[英]Can Keras' model.predict return a dictionary?
The documentation https://keras.io/models/model/#predict says that model.predict
returns Numpy array(s) of predictions.文档https://keras.io/models/model/#predict说
model.predict
返回 Numpy 预测数组。 In the Keras API, is there is a way to distinguishing which of these arrays are which?在 Keras API 中,有没有办法区分这些数组中的哪些是哪些? How about in the TF implementation?
在TF实现中怎么样?
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."调用
model.fit
,相同的文档说“如果模型中的输入层被命名,您还可以将字典映射输入名称传递给 Numpy 数组。”
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(...)
如果
my_output_dict
的键或my_output_dict
中的字典值(层)的my_output_dict
附加到my_model.predict(...)
的输出, 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...如果我使用
tf.keras.model.save
将模型保存到 TensorFlow 的 saved_model 格式 protobuf tf.serving API 以这种方式工作 - 具有命名的输入和输出......
my_model.output_names
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从
my_model.output_names
自己创建dict
,它是按预测顺序排列的输出层的name
属性列表
prediction_list = my_model.predict(my_test_input_dict)
prediction_dict = {name: pred for name, pred in zip(my_model.output_names, prediction_list)}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.