我在Google ML中部署了一个对象检测模型,我可以进行在线预测,但 FAILS 进行批量预测,堆栈驱动程序日志中出现以下错误:
运行图形时出现异常:断言失败:[无法将字节解码为JPEG,PNG,GIF或BMP] [[节点:map / while / decode_image / cond_jpeg / cond_png / cond_gif / Assert_1 / Assert = Assert [T = [DT_STRING],汇总= 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文档中的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())
答案 0 :(得分:1)
尝试使用此格式进行批量预测:
{"inputs": {"b64": "/9j/4SurRXhpZgAATU0AKgAAAAgACgEPAAIAHAAAAhgEQAAIAAAAFAAAAjgEaAAUAAAABAAAAlAEbAAUAAAABAAAAnAEoAAMAAAABAAIAAAExAAIAAAA1AAAApAEyAAIAAAAUA...}}
{"inputs": {"b64": "/9j/4SurRXhpZgAATU0AKgAAAAgACgEPAAIAAAAAAhgEQAAIAAAAFAAAAjgEaAAUAAAABAAAAlAEbAAUAAAABAAAAnAEoAAMAAAABAAIAAAExAAIAAAA1AAAApAEyAAIAAAAUA...}}
换句话说,与gcloud
用于发送在线预测请求的格式相同。
批量预测,gcloud和在线预测请求之间的关系如下:
local predict
和predict
文件格式与批量预测相同request
库等)是{"instances": [line1, line2, ...]}