【问题标题】:Google ML Batch prediction error: Exception during running the graph: assertion failed: [Unable to decode bytes as JPEG, PNG, GIF, or BMP]Google ML 批量预测错误:运行图表时出现异常:断言失败:[无法将字节解码为 JPEG、PNG、GIF 或 BMP]
【发布时间】:2018-06-03 12:14:56
【问题描述】:

我在 Google ML 中部署了一个对象检测模型,我能够进行在线预测,但它失败无法进行批量预测,在堆栈驱动程序日志中出现以下错误:

运行图表时出现异常:断言失败:[无法将字节解码为 JPEG、PNG、GIF 或 BMP] [[节点:map/while/decode_image/cond_jpeg/cond_png/cond_gif/Assert_1/Assert = Assert[T =[DT_STRING], summarize=3, _device="/job:localhost/replica:0/task:0/device:CPU:0"](map/while/decode_image/cond_jpeg/cond_png/cond_gif/is_bmp, map/while /decode_image/cond_jpeg/cond_png/cond_gif/Assert_1/Assert/data_0)]]

我尝试了 gcloud 命令和 python api 但没有运气。在线预测的 request.json 文件。

{"inputs": {"b64": "/9j/4SurRXhpZgAATU0AKgAAAAgACgEPAAIAAAAHAAAAhgEQAAIAAAAFAAAAjgEaAAUAAAABAAAAlAEbAAUAAAABAAAAnAEoAAMAAAABAAIAAAExAAA2gITAAMAAAABAAEAAIdpAAQAAAABAAAA7oglAAQAAAABAAAC0gAAAyhYaWFvbWkAAE1.....}}

它已经 b64 编码。它适用于在线预测:

gcloud ml-engine predict --model object_detector  --version v2 --json-instances request.json

但是对于批量预测它失败了,下面是 batch_request.json 文件的两行

{'instances': [{"inputs": {"b64": "/9j/4SurRXhpZgAATU0AKgAAAAgACgEPAAIAHAAAAhgEQAAIAAAAFAAAAjgEaAAUAAAABAAAAlAEbAAUAAAABAAAAnAEoAAMAAAABAAIAAAExAAIAAAA1AAAApAEyAAIAAAAUA...}}]}
{'instances': [{"inputs": {"b64": "/9j/4SurRXhpZgAATU0AKgAAAAgACgEPAAIAAAAAAhgEQAAIAAAAFAAAAjgEaAAUAAAABAAAAlAEbAAUAAAABAAAAnAEoAAMAAAABAAIAAAExAAIAAAA1AAAApAEyAAIAAAAUA...}}]}

为批量预测发出的 python api 请求正文:

{'jobId': 'mycloud_machine_object_detector_115252',
'predictionInput': {'dataFormat': 'TEXT',
'inputPaths': 'gs://my-bucket/object-detection/batch_request.json',
'outputPath': 'gs://my-bucket/object-detection/',
'region': 'us-central1',
'versionName': 'projects/mycloud_machine/models/object_detector/versions/v2'}}

我使用 Google Docs 中的 python 代码来发出批处理请求。

project_id = 'projects/{}'.format(project_name)

ml = discovery.build('ml', 'v1', credentials=credentials)
request = ml.projects().jobs().create(parent=project_id,
                                  body=body_fn())

try:
    response = request.execute()

    print('Job requested.')

    # The state returned will almost always be QUEUED.
    print('state : {}'.format(response['state']))

except errors.HttpError as err:
    # Something went wrong, print out some information.
    print('There was an error getting the prediction results.' +
      'Check the details:')
    print(err._get_reason())

【问题讨论】:

    标签: google-cloud-platform google-cloud-ml


    【解决方案1】:

    尝试使用这种格式进行批量预测:

    {"inputs": {"b64": "/9j/4SurRXhpZgAATU0AKgAAAAgACgEPAAIAHAAAAhgEQAAIAAAAFAAAAjgEaAAUAAAABAAAAlAEbAAUAAAABAAAAnAEoAAMAAAABAAIAAAExAAIAAAA1AAAApAEyAAIAAAAUA...}}
    {"inputs": {"b64": "/9j/4SurRXhpZgAATU0AKgAAAAgACgEPAAIAAAAAAhgEQAAIAAAAFAAAAjgEaAAUAAAABAAAAlAEbAAUAAAABAAAAnAEoAAMAAAABAAIAAAExAAIAAAA1AAAApAEyAAIAAAAUA...}}
    

    换句话说,与您使用gcloud 发送在线预测请求的格式相同。

    批量预测、gcloud、在线预测请求的关系如下:

    • local predictpredict 的 gcloud 文件格式与批量预测相同
    • 使用 gcloud 时发送到在线预测的请求的实际正文将文件的每一行转换为“instances”数组的元素。因此请求的实际正文(例如,如果您不使用 gcloud,即使用 curl、Python 的 request 库等,您将发送到在线预测服务的请求)是 {"instances": [line1, line2, ...]}

    【讨论】:

    • 我尝试从 gcloud 命令运行批处理作业,但它再次失败并出现同样的错误。我使用了与您询问的相同格式 {"inputs": {"b64" : "b64 coded data"}}
    • 您尝试gcloud ml-engine local predict 开始了吗?如果您仍有问题,请与 cloudml-feedback@google.com 联系,并提供此线程和作业 ID 的参考。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-09-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-04-06
    • 1970-01-01
    • 2022-12-03
    相关资源
    最近更新 更多