![](/img/trans.png)
[英]tf.saved_model.simple_save fail when converting from Keras model
[英]Error when using tf.saved_model.simple_save()
我正在嘗試在計算機上托管一個圖像分類模型,我正在嘗試實施本文提供的步驟。
我使用的代碼段是:
import tensorflow as tf
# The export path contains the name and the version of the model
tf.keras.backend.set_learning_phase(0) # Ignore dropout at inference
model = tf.keras.models.load_model('./model_new.hdf5')
export_path = './model/1'
# Fetch the Keras session and save the model
# The signature definition is defined by the input and output tensors
# And stored with the default serving key
with tf.keras.backend.get_session() as sess:
tf.saved_model.simple_save(
sess,
export_path,
inputs={'input_image': model.input},
outputs={t.name:t for t in model.outputs})
如以上文章所述。 我的模型存儲在model_new.hdf5文件中,但是出現以下錯誤消息。
NameError:名稱“ tf”未定義
在行中
型號= tf.keras.models.load_model('./ model_new.hdf5')
這是使用tf.saved_model.simple_save()的正確方法嗎?
這是加載模型而不是tf.saved_model.simple_save()
。 加載Keras模型時,需要處理自定義對象或自定義圖層。 為此,您可以傳遞一個custom_objects
字典,該字典包含tf
:
import tensorflow as tf
model = keras.models.load_model('model_new.hdf5', custom_objects={'tf': tf})
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.