【问题标题】:How to replace placeholder in tensorflow2?如何替换tensorflow2中的占位符?
【发布时间】:2019-06-11 21:42:18
【问题描述】:

我需要将估算器导出器代码从 tensorflow 1.x 转换为 2 并去掉占位符。有人知道如何正确操作吗?

我已经尝试过 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)

【问题讨论】:

    标签: tensorflow tensorflow2.0


    【解决方案1】:

    如果你已经迁移到使用 keras 模型,你可以使用这个

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-04-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-09-29
      • 2017-09-11
      • 2013-01-24
      相关资源
      最近更新 更多