The documentation https://keras.io/models/model/#predict says that model.predict
returns Numpy array(s) of predictions. In the Keras API, is there is a way to distinguishing which of these arrays are which? How about in the TF implementation?
At the top of the same page of documentation, they say that "models can specify multiple inputs and outputs using lists". It seems that nothing breaks if instead, one passes dictionaries:
my_model = tf.keras.models.Model(inputs=my_inputs_dict, outputs=my_outputs_dict)
When calling model.fit
the same documentation says "If input layers in the model are named, you can also pass a dictionary mapping input names to Numpy arrays."
It would be nice if either the keys from my_output_dict
or the names of the dictionary values (layers) in my_output_dict
were attached to the outputs of my_model.predict(...)
If I save the model to TensorFlow's saved_model format protobuf using
tf.keras.model.save
the tf.serving API works this way-- with named inputs and outputs...
my_model.output_names
Given
my_model = tf.keras.models.Model(inputs=my_inputs_dict, outputs=my_outputs_dict)
create the dict
yourself from my_model.output_names
, which is a list of name
attributes of your output layers in the order of prediction
prediction_list = my_model.predict(my_test_input_dict)
prediction_dict = {name: pred for name, pred in zip(my_model.output_names, prediction_list)}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With