Google cloud platform Google AI平台预测错误-对象检测API模型-HttpError 400-Tensor名称批量大小不一致

Google cloud platform Google AI平台预测错误-对象检测API模型-HttpError 400-Tensor名称批量大小不一致,google-cloud-platform,tensorflow2.0,object-detection-api,google-cloud-ml,Google Cloud Platform,Tensorflow2.0,Object Detection Api,Google Cloud Ml,我需要用TensorFlow做远程在线预测。我正在尝试使用谷歌人工智能平台。当我在AI平台上对目标检测模型进行在线预测时,我得到一个类似于以下的错误: HttpError 400 Tensor name: num_proposals has inconsistent batch size: 1 expecting: 49152 HttpError: <HttpError 400 when requesting https://ml.googleapis.com/v1/projects/

我需要用TensorFlow做远程在线预测。我正在尝试使用谷歌人工智能平台。当我在AI平台上对目标检测模型进行在线预测时,我得到一个类似于以下的错误:

HttpError 400 Tensor name: num_proposals has inconsistent batch size: 1 expecting: 49152
HttpError: <HttpError 400 when requesting 
https://ml.googleapis.com/v1/projects/gcp_project/models/error_demo/versions/mobilenet:predict?alt=json
returned "{ "error": "Tensor name: refined_box_encodings has inconsistent batch size: 300 
expecting: 1"}}>
当我在本地执行预测时(例如,
result=model(image)
),我会得到所需的结果

此错误适用于多种型号——掩码RCNN和MobileNet。错误发生在我训练过的对象检测模型上,以及直接从中加载的对象检测模型上。我使用相同的代码获得了成功的结果,但是部署在AI平台上的模型不是目标检测

签名信息 模型输入
签名def
似乎是正确的:

!saved_model_cli show --dir {MODEL_DIR_GS}
!saved_model_cli show --dir {MODEL_DIR_GS} --tag_set serve 
!saved_model_cli show --dir {MODEL_DIR_GS} --tag_set serve --signature_def serving_default
给出:

The given SavedModel contains the following tag-sets:
serve
The given SavedModel MetaGraphDef contains SignatureDefs with the following keys:
SignatureDef key: "__saved_model_init_op"
SignatureDef key: "serving_default"
The given SavedModel SignatureDef contains the following input(s):
  inputs['input_tensor'] tensor_info:
      dtype: DT_UINT8
      shape: (1, -1, -1, 3)
      name: serving_default_input_tensor:0
The given SavedModel SignatureDef contains the following output(s):
  outputs['anchors'] tensor_info:
      dtype: DT_FLOAT
      shape: (-1, 4)
      name: StatefulPartitionedCall:0
  outputs['box_classifier_features'] tensor_info:
      dtype: DT_FLOAT
      shape: (300, 9, 9, 1536)
      name: StatefulPartitionedCall:1
  outputs['class_predictions_with_background'] tensor_info:
      dtype: DT_FLOAT
      shape: (300, 2)
      name: StatefulPartitionedCall:2
  outputs['detection_anchor_indices'] tensor_info:
      dtype: DT_FLOAT
      shape: (1, 100)
      name: StatefulPartitionedCall:3
  outputs['detection_boxes'] tensor_info:
      dtype: DT_FLOAT
      shape: (1, 100, 4)
      name: StatefulPartitionedCall:4
  outputs['detection_classes'] tensor_info:
      dtype: DT_FLOAT
      shape: (1, 100)
      name: StatefulPartitionedCall:5
  outputs['detection_masks'] tensor_info:
      dtype: DT_FLOAT
      shape: (1, 100, 33, 33)
      name: StatefulPartitionedCall:6
  outputs['detection_multiclass_scores'] tensor_info:
      dtype: DT_FLOAT
      shape: (1, 100, 2)
      name: StatefulPartitionedCall:7
  outputs['detection_scores'] tensor_info:
      dtype: DT_FLOAT
      shape: (1, 100)
      name: StatefulPartitionedCall:8
  outputs['final_anchors'] tensor_info:
      dtype: DT_FLOAT
      shape: (1, 300, 4)
      name: StatefulPartitionedCall:9
  outputs['image_shape'] tensor_info:
      dtype: DT_FLOAT
      shape: (4)
      name: StatefulPartitionedCall:10
  outputs['mask_predictions'] tensor_info:
      dtype: DT_FLOAT
      shape: (100, 1, 33, 33)
      name: StatefulPartitionedCall:11
  outputs['num_detections'] tensor_info:
      dtype: DT_FLOAT
      shape: (1)
      name: StatefulPartitionedCall:12
  outputs['num_proposals'] tensor_info:
      dtype: DT_FLOAT
      shape: (1)
      name: StatefulPartitionedCall:13
  outputs['proposal_boxes'] tensor_info:
      dtype: DT_FLOAT
      shape: (1, 300, 4)
      name: StatefulPartitionedCall:14
  outputs['proposal_boxes_normalized'] tensor_info:
      dtype: DT_FLOAT
      shape: (1, 300, 4)
      name: StatefulPartitionedCall:15
  outputs['raw_detection_boxes'] tensor_info:
      dtype: DT_FLOAT
      shape: (1, 300, 4)
      name: StatefulPartitionedCall:16
  outputs['raw_detection_scores'] tensor_info:
      dtype: DT_FLOAT
      shape: (1, 300, 2)
      name: StatefulPartitionedCall:17
  outputs['refined_box_encodings'] tensor_info:
      dtype: DT_FLOAT
      shape: (300, 1, 4)
      name: StatefulPartitionedCall:18
  outputs['rpn_box_encodings'] tensor_info:
      dtype: DT_FLOAT
      shape: (1, 12288, 4)
      name: StatefulPartitionedCall:19
  outputs['rpn_objectness_predictions_with_background'] tensor_info:
      dtype: DT_FLOAT
      shape: (1, 12288, 2)
      name: StatefulPartitionedCall:20
Method name is: tensorflow/serving/predict
复制步骤
  • 从下载模型

  • 部署到AI平台

  • 远程评估
  • 我得到一个类似以下的错误:

    HttpError 400 Tensor name: num_proposals has inconsistent batch size: 1 expecting: 49152
    
    HttpError: <HttpError 400 when requesting 
    https://ml.googleapis.com/v1/projects/gcp_project/models/error_demo/versions/mobilenet:predict?alt=json
    returned "{ "error": "Tensor name: refined_box_encodings has inconsistent batch size: 300 
    expecting: 1"}}>
    
    • 如果我重复这个预测步骤,我会得到相同的错误消息,除了张量的名称不同

    • 如果我使用
      gcloud

    我得到一个
    无效的\u参数
    错误

    ERROR: (gcloud.ai-platform.predict) HTTP request failed. Response: {
      "error": {
        "code": 400,
        "message": "{ \"error\": \"Tensor name: anchors has inconsistent batch size: 49152 expecting: 1\" }",
        "status": "INVALID_ARGUMENT"
      }
    }
    
    • 如果我使用谷歌云控制台提交上述相同的JSON数据——AI平台
      版本详细信息
      屏幕上的
      测试和使用
      选项卡,或者在
      方法:Projects.predict
    我启用了日志记录(包括常规日志记录和控制台日志记录),但它没有提供任何附加信息

    我已将复制所需的详细信息放在一个文件夹中

    提前谢谢。我花了一天多的时间在这上面,我真的被卡住了

    Per,当请求使用
    实例
    键时,TensorFlow服务确保输出的所有组件具有相同的批处理大小。解决方法是使用
    输入
    关键字

    例如

    invalidArgument -- The value for one of fields in the request body was invalid.
    
    import json
    
    x = {"instances":[
    [
      [
        [0, 0, 0], 
        [0, 0, 0]
      ], 
      [
        [0, 0, 0], 
        [0, 0, 0]
      ]
    ]
    ]
    }
    with open('test.json', 'w') as f:
      json.dump(x, f)
    
    !gcloud ai-platform predict --model $MODEL --json-request=./test.json 
    
    ERROR: (gcloud.ai-platform.predict) HTTP request failed. Response: {
      "error": {
        "code": 400,
        "message": "{ \"error\": \"Tensor name: anchors has inconsistent batch size: 49152 expecting: 1\" }",
        "status": "INVALID_ARGUMENT"
      }
    }
    
    inputs = [img_list]
    ...
    response = service.projects().predict(
        name=model_version_string,
        body={'inputs': inputs}