【问题标题】:aws sagemaker python sdk : Predict function giving weird errorsaws sagemaker python sdk:预测函数给出奇怪的错误
【发布时间】:2020-03-27 00:49:57
【问题描述】:

我已经训练了一个 tf 模型(不使用任何 sagemaker 服务)。我使用了 tf 2.1.0 版本。 我用下面的签名def保存了它 MetaGraphDef with tag-set: 'serve' 包含以下 SignatureDef:

  The given SavedModel SignatureDef contains the following input(s):
    inputs['inputs'] tensor_info:
        dtype: DT_FLOAT
        shape: (-1, 80)
        name: text_input_1:0
  The given SavedModel SignatureDef contains the following output(s):
    outputs['predictions'] tensor_info:
        dtype: DT_FLOAT
        shape: (-1, 738)
        name: output_1/Identity:0
  Method name is: tensorflow/serving/predict

我压缩了模型并使用AWS sagemaker's Python SDK 创建了一个模型对象

model = Model(model_data=s3_location,
              role=role,
              framework_version='2.1.0')
predictor = model.deploy(initial_instance_count=1, instance_type='ml.m5.xlarge') {code}

模型创建后,我很难预测。我得到了一些奇怪的错误,例如 "error": "Session was not created with a graph before Run()!""error": "Failed to process element: 0 of 'instances' list. Error: Invalid argument: JSON Value:

我尝试了使用各种格式的 predictor.predict() 方法和 client.invoke_endpoint() 方法,例如 predictor.predict(list)、使用 "instances" 格式的各种 tf 服务 REST API 格式的变体。我也在所有变体上尝试了 json.dumps() 。但没有任何效果。 有人可以建议一种预测方法。如 signature_def 所示,我的输入形状为 (1,80)。 谢谢你

我正在寻找predictor.predict($what here?) 形式的答案。或者建议我在这里做错了什么。

谢谢

【问题讨论】:

    标签: tensorflow tensorflow-serving amazon-sagemaker


    【解决方案1】:

    如果您可以将您传递的内容分享给predictor.predict(),将会很有帮助。

    输入应该是“实例”值的列表,例如如果您想使用 TFS REST API 发送:

    {
      "instances": [1.0, 2.0, 3.0]
    }
    

    那么你的代码应该是这样的:

    predictor.predict([1.0, 2.0, 3.0])
    

    这是一个演示此功能的示例笔记本:https://github.com/awslabs/amazon-sagemaker-examples/blob/master/sagemaker-python-sdk/tensorflow_serving_container/tensorflow_serving_container.ipynb

    【讨论】:

      猜你喜欢
      • 2017-11-11
      • 1970-01-01
      • 2016-08-24
      • 2023-03-06
      • 2016-05-05
      • 1970-01-01
      • 2014-06-03
      • 2016-04-24
      • 2023-04-01
      相关资源
      最近更新 更多