Get outputs in model.predict by name in TensorFlow-JS

Viewed 528

My model has several outputs as

class MyModel(tf.keras.Model):
    def call(self, input):
        ...
        return {"a": a, "b": b, "c": c}

a, b, and c all are named tensors. But after converting to TF-JS and running the model in browser my outputs seems to be a list with nameless elements in an arbitrary order. So I don't know how to match training to serving. Any ideas?

I was hoping to be able to do something like this in JS:

pred = model.predict(input);
a_pred = pred["a"]

Here is the output in JS console. Model outputs in JS console

UPDATE1: Looking at model graph with saved_model_cli revealed that SignatureDef makes sense and has tree different outputs as expected:

The given SavedModel SignatureDef contains the following output(s):
    outputs['a'] tensor_info:
        ...
    outputs['b'] tensor_info:
        ...
    outputs['c'] tensor_info:
        ...

I guess the problem is converting to TF-JS.

UPDATE 2: Seems like in one of the examples prediction is also a list but it seems to be ordered (see example).

UPDATE 3: By printing model.outputNodes in JS I found out that my output operations in model.json are called IDENTITY, IDENTITY_1, IDENTITY_2. So I need to figure out how to name them properly.

0 Answers
Related