【发布时间】: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