Python 3.x 如何保存和恢复tf.estimator模型
我想保存并恢复我的tf.estimator模型。虽然我试图关注stackoverflow的其他相关问题,但我没有成功。以下输入可以提供要预测的数据。但我不知道如何用它来保存和恢复预测模型。 顺便说一句,我的返回数据集的形状为[batch\u size,dim],其中dtype为float32Python 3.x 如何保存和恢复tf.estimator模型,python-3.x,tensorflow,Python 3.x,Tensorflow,我想保存并恢复我的tf.estimator模型。虽然我试图关注stackoverflow的其他相关问题,但我没有成功。以下输入可以提供要预测的数据。但我不知道如何用它来保存和恢复预测模型。 顺便说一句,我的返回数据集的形状为[batch\u size,dim],其中dtype为float32 def predict_input_fn(path, dim, batch_size): dataset = ds.get_dataset(path,
def predict_input_fn(path, dim, batch_size):
dataset = ds.get_dataset(path,
dim)
dataset = dataset.batch(batch_size)
dataset = dataset.prefetch(1)
return dataset
到目前为止,我已经尝试了以下内容,但没有达到预期效果,您能帮我保存和恢复这样一个模型吗
试用版
def serving_input_receiver_fn():
features = tf.placeholder(
dtype=tf.float32, shape=[None, batch_size])
fn = lambda x : precict_input_fn(path, dim, batch_size)
mapped_fn = tf.map_fn(fn, features)
return tf.estimator.export.ServingInputReceiver(mapped_fn, features)
estimator.export_savedmodel(model_save_path, serving_input_receiver_fn)
错误:
Failed to convert object of type <class 'tensorflow.python.data.ops.dataset_ops.PrefetchDataset'> to Tensor. Contents: <PrefetchDataset shapes: (?, 1024), types: tf.float32>. Consider casting elements to a supported type
无法将类型的对象转换为张量。目录:。将铸造元素考虑为支持类型
为什么会附加keras
标签?我看不到使用了任何Keras模块。这个问题与Keras
无关-请不要垃圾邮件标签(removed0Keras模块未使用,但使用Keras的人可能对此也有一些想法。