如何在tensorflow2中替换占位符?

时间:2019-06-11 21:42:18

标签: tensorflow tensorflow2.0

我需要将估算器导出器代码从tensorflow 1.x转换为2,并摆脱占位符。有人知道该怎么做吗?

我已经尝试过功能= {'input':tf.compat.v1.placeholder(tf.float32,shape =(1,224,224,3),name =“ input”)},但这不起作用正如我所期望的

features = {'input': tf.placeholder(tf.float32, shape=(1, 224, 224, 3), name="input")}
input_fn = tf.estimator.export.build_raw_serving_input_receiver_fn(features, 1)
exported_model_path = estimator.export_savedmodel(args.model_dir, input_fn)

1 个答案:

答案 0 :(得分:0)

如果您已迁移到使用keras模型,则可以使用此

# model is a compiled and trained keras model
tf.saved_model.save(model, export_dir)

它将将keras模型导出为SavedModel格式。