我想根据 Google ML 引擎中现有的模型进行在线对象检测预测(或推理)。但我无法构建 json 请求。
模型是来自TF模型动物园的faster_rcnn_inception_resnet_v2_atrous_coco_2017_11_08。输入是图像输出类,bb,分数等...
所需的输入是(来自 saved_model_cli show )
inputs['inputs'] tensor_info:
dtype: DT_UINT8
shape: (-1, -1, -1, 3)
name: image_tensor:0
因为它需要一个 uint8 数组,所以我将图像加载到一个 numpy 数组中
encoded_contents = np.array(image.getdata()).reshape(
(im_height, im_width, 3)).astype(np.uint8)
调整图像大小 image_np_expanded = np.expand_dims(encoded_contents, axis=0)
尝试构建 json 请求
instance = {"input":encoded_contents}
row = json.dumps(instance,sort_keys=True)
但我无法构建它,因为
TypeError(repr(o) + " is not JSON serializable")
TypeError: array([[[164, 191, 220],
[190, 157, 114],
[190, 157, 114]]], dtype=uint8) is not JSON serializable
如果我使用 tolist() 方法将 numpy 数组转换为列表,则 json 文件需要 3 兆字节并且 ML 引擎拒绝它“消息”:“请求有效负载大小超过限制:1572864 字节。”,
我会将此 json 作为 json 文件发送到 ml-engine predict。
gcloud ml-engine predict --model=pellaires --version=pellaires14 --json-
instances=request.json > response.yaml
牧羊人nacy
繁华开满天机
相关分类