简体   繁体   English

如何在tensorflow2中替换占位符?

[英]How to replace placeholder in tensorflow2?

I need to convert estimator exporter code from tensorflow 1.x to 2 and get rid of placeholders. 我需要将估计器导出器代码从tensorflow 1.x转换为2并删除占位符。 Does somebody know how to do it correctly? 有人知道如何正确地做到这一点吗?

I already tried features = {'input': tf.compat.v1.placeholder(tf.float32, shape=(1, 224, 224, 3), name="input")} , but this did not work as I would expect 我已经尝试过features = {'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)

In case you have migrated to using keras models you can use this 如果您已迁移到使用keras模型,则可以使用此模型

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

It will export the keras model to the SavedModel format. 它会将keras模型导出为SavedModel格式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM