Tensorflow v1.12.0 中 export_savedmodel 的问题
Problem with export_savedmodel in Tensorflow v1.12.0
我正在尝试使用 export_savedmodel 函数编写从 Keras 模型创建的 Estimator。我的代码看起来像这样:
from tensorflow.python import keras
...
model = keras.Model(...)
model.compile(...)
model.fit(...)
estimator_model = keras.estimator.model_to_estimator(keras_model=model, model_dir='./estimator_model')
estimator_model.export_savedmodel('./export', serving_input_receiver_fn=serving_input_fn)
def serving_input_fn():
...
我是根据Google tutorial写的,但是有问题。不幸的是,export_savedmodel 无法在 ./estimator_model 中找到经过训练的模型。这让我很惊讶,因为首先我没有在附件 link 中查看与此相关的任何问题,其次在 export_savedmodel 中我们还有一个额外的 checkpoint_path参数,没用过,不过貌似有影响。
因为model_to_estimator将数据保存到文件夹./estimator_model/keras我试过如下方式使用:
estimator_model.export_savedmodel('./export', serving_input_receiver_fn=serving_input_fn, checkpoint_path='./estimator_model/keras/keras_model.ckpt.data-00000-of-00001')
但现在我有:
"Data loss: not an sstable (bad magic number): maybe your file is in a different file format?"
这是怎么回事?
你能试试吗
from tensorflow.python import keras
...
model = keras.Model(...)
model.compile(...)
estimator_model = keras.estimator.model_to_estimator(keras_model=model,
model_dir='./estimator_model')
estimator_model.train(...)
estimator_model.export_savedmodel('./export',
serving_input_receiver_fn=serving_input_fn)
看看是否有效?
这可能是一个错误,我会在 github 上报告它。
我正在尝试使用 export_savedmodel 函数编写从 Keras 模型创建的 Estimator。我的代码看起来像这样:
from tensorflow.python import keras
...
model = keras.Model(...)
model.compile(...)
model.fit(...)
estimator_model = keras.estimator.model_to_estimator(keras_model=model, model_dir='./estimator_model')
estimator_model.export_savedmodel('./export', serving_input_receiver_fn=serving_input_fn)
def serving_input_fn():
...
我是根据Google tutorial写的,但是有问题。不幸的是,export_savedmodel 无法在 ./estimator_model 中找到经过训练的模型。这让我很惊讶,因为首先我没有在附件 link 中查看与此相关的任何问题,其次在 export_savedmodel 中我们还有一个额外的 checkpoint_path参数,没用过,不过貌似有影响。 因为model_to_estimator将数据保存到文件夹./estimator_model/keras我试过如下方式使用:
estimator_model.export_savedmodel('./export', serving_input_receiver_fn=serving_input_fn, checkpoint_path='./estimator_model/keras/keras_model.ckpt.data-00000-of-00001')
但现在我有: "Data loss: not an sstable (bad magic number): maybe your file is in a different file format?"
这是怎么回事?
你能试试吗
from tensorflow.python import keras
...
model = keras.Model(...)
model.compile(...)
estimator_model = keras.estimator.model_to_estimator(keras_model=model,
model_dir='./estimator_model')
estimator_model.train(...)
estimator_model.export_savedmodel('./export',
serving_input_receiver_fn=serving_input_fn)
看看是否有效?
这可能是一个错误,我会在 github 上报告它。