获取错误“ TypeError:现有的“ global_step”必须为变量或张量:无。”运行estimator.export_saved_model()时

时间:2019-07-19 06:11:54

标签: python tensorflow

我正在尝试使用estimator.export_saved_model()导出给定的estimator的SavedModel:

def serving_receiver_fn():
    serialized_tf_example = tf.compat.v1.placeholder(
        dtype=tf.string, shape=[None], name='input_example_tensor')

    image = tf.feature_column.numeric_column("resnet50_input", shape=[255, 255, 3])
    label = tf.feature_column.numeric_column('dense_1_target')

    receiver_tensors = {'examples': serialized_tf_example}
    feature_spec = tf.feature_column.make_parse_example_spec([image, label])
    features = tf.io.parse_example(serialized_tf_example, feature_spec)

    return tf.estimator.export.ServingInputReceiver(features, receiver_tensors)
estimator.export_saved_model(export_dir_base=serving_model_dir,
                             serving_input_receiver_fn=serving_receiver_fn,
                             checkpoint_path=tf.train.latest_checkpoint(
                                 f'/Users/user/Documents/.../saved_model/variables/'),
                             )

但是我得到了错误:

TypeError: Existing "global_step" must be a Variable or Tensor: None.

请帮助!

0 个答案:

没有答案