Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/tensorflow/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在TensorFlow 2.X中,是否可以创建一个具有任意多个输入张量的估计器来预测SignatureDef,而不使用占位符?_Tensorflow_Gcloud_Google Cloud Ml - Fatal编程技术网

在TensorFlow 2.X中,是否可以创建一个具有任意多个输入张量的估计器来预测SignatureDef,而不使用占位符?

在TensorFlow 2.X中,是否可以创建一个具有任意多个输入张量的估计器来预测SignatureDef,而不使用占位符?,tensorflow,gcloud,google-cloud-ml,Tensorflow,Gcloud,Google Cloud Ml,问题 我正在将我的Tensorflow 1.14估计器转换为Tensorflow 2.1。我目前的工作流程包括在gcloud的ai平台上培训我的tensorflow模型,并使用他们的模型服务部署我的模型进行在线预测 升级到TensorFlow 2时的问题是,他们已经删除了占位符,这影响了我的服务输入以及导出估计器模型的方式。使用tensorflow 2,如果我导出一个模型而不使用占位符,那么我的模型的“predict”SignatureDef只有一个“examples”张量,而以前它有许多输入通

问题

我正在将我的Tensorflow 1.14估计器转换为Tensorflow 2.1。我目前的工作流程包括在gcloud的ai平台上培训我的tensorflow模型,并使用他们的模型服务部署我的模型进行在线预测

升级到TensorFlow 2时的问题是,他们已经删除了占位符,这影响了我的
服务输入以及导出估计器模型的方式。使用tensorflow 2,如果我导出一个模型而不使用占位符,那么我的模型的“predict”
SignatureDef
只有一个“examples”张量,而以前它有许多输入通过我的
服务输入fn进行适当命名

我的估计器之前的设置如下:

def serving_input_fn():

    inputs = {
        'feature1': tf.compat.v1.placeholder(shape=None, dtype=tf.string),
        'feature2': tf.compat.v1.placeholder(shape=None, dtype=tf.string),
        'feature3': tf.compat.v1.placeholder(shape=None, dtype=tf.string),
        ...
    }

    return tf.estimator.export.ServingInputReceiver(features=split_features, receiver_tensors=inputs)

exporter = tf.estimator.LatestExporter('exporter', serving_input_fn)

eval_spec = tf.estimator.EvalSpec(
    input_fn=lambda: input_eval_fn(args.test_dir),
    exporters=[exporter],
    start_delay_secs=10,
    throttle_secs=0)

...

tf.estimator.train_and_evaluate(estimator, train_spec, eval_spec)
这在过去工作得很好,它允许我有一个多输入“predict”SignatureDef,在这里我可以将输入的json发送到ai平台模型服务并获取预测。但是由于我试图不依赖
tf.compat.v1
库,所以我希望避免使用占位符

我尝试过的

根据链接的文档,我已经用
tf.estimator.export.build\u parsing\u service\u input\u receiver\u fn方法替换了我的服务输入\u fn:

feature_columns = ... # list of feature columns 
serving_input_fn = tf.estimator.export.build_parsing_serving_input_receiver_fn(
  tf.feature_column.make_parse_example_spec(feature_columns))
但是,这给了我以下“预测”签名:

signature_def['predict']:
  The given SavedModel SignatureDef contains the following input(s):
    inputs['examples'] tensor_info:
        dtype: DT_STRING
        shape: (-1)
        name: input_example_tensor:0
而在我的“预测”签名之前,EF如下:

signature_def['predict']:
  The given SavedModel SignatureDef contains the following input(s):
    inputs['feature1'] tensor_info:
        dtype: DT_STRING
        shape: unknown_rank
        name: Placeholder:0
    inputs['feature2'] tensor_info:
        dtype: DT_STRING
        shape: unknown_rank
        name: Placeholder_1:0
    inputs['feature3'] tensor_info:
        dtype: DT_STRING
        shape: unknown_rank
        name: Placeholder_2:0
我也尝试过使用
tf.estimator.export.build\u raw\u serving\u input\u receiver\u fn
,但我的理解是,这种方法需要实际的张量才能使用,而不是特性规范。除非我使用占位符,否则我真的不知道从哪里获取这些服务张量

所以我的主要问题是:

  • 不使用Tensorflow 2中的占位符,是否可以从估计器模型创建多输入“预测”特征定义
  • 如果不可能,我应该如何向gcloud predictions服务提供“predict”签名def中的“examples”张量的实例
谢谢