python - Docker 上的 Google Cloud AutoML 预测
问题描述
我已经在 Google Cloud AutoML 上训练了一个多类对象检测模型。我已经从Container export 下载了我自己的模型。比我使用 Google Cloud AutoML docker 映像将它部署在 Docker 上。我已经使用以下代码发送请求:
import base64
import io
import json
import requests
def process(image_file_path, image_key="1", port_number=8501):
with io.open(image_file_path, 'rb') as image_file:
encoded_image = base64.b64encode(image_file.read()).decode('utf-8')
instances = {
"instances": [
{
"image_bytes": {
"b64": str(encoded_image)
},
"key": image_key
}
]
}
url = 'http://localhost:{}/v1/models/default:predict'.format(port_number)
response = requests.post(url, data=json.dumps(instances))
return response.json()
我已经成功地从 docker 获得了 json 格式的响应:
{
"predictions": [{
"detection_multiclass_scores": [
[0.00540795922, 0.99754715],
...
],
"detection_classes": [1.0, ...],
"num_detections": 40.0,
"image_info": [320, 320, 1, 0, 320, 320],
"detection_boxes": [
[0.0382162929, 0.0984618068, 0.746192276, 0.991413414],
...
],
"detection_scores": [0.99754715, ...],
"detection_classes_as_text": ["image_class", ...],
"key": "1"
}]
}
此时,我想知道在图像中检测到的边界框在哪里。我知道我应该使用 获取此信息detection_boxes
,但我需要将其转换为 px 值。因为我会再次处理边界框。
的图案是detection_boxes
什么?
解决方案
detection_boxes 的格式是
[min_y, min_x, max_y, max_x]
,这些值通过图像的高度和宽度进行归一化,从而得到像素坐标y*height
和x*width
。
这与 Tensorflow 对象检测 API 使用的格式相同,您可以在此处阅读有关格式的信息
推荐阅读
- c - 求平均数的C程序
- amazon-web-services - 如何使用 AWS Lambda 读取 S3 中的 csv 并将记录数输出到 HTML?
- protocol-buffers - 如何正确地将嵌套的 protobuf 模式传递给融合模式注册表?
- go - 带时间的 Golang 协程
- rust - 带有 str 键的 HashMap 的 Rust lang 生命周期不匹配
- windows-10 - 我在Windows 10中安装了Odoo 13,突然出现“无法显示所选图像”。我如何解决它?
- context-free-grammar - 递归文法可以有 LR(0) 状态吗?
- javascript - 多链接的 JS 函数
- oracle - 甲骨文。如何按值阈值对数据进行分组
- javascript - If 语句在控制台中有效,但在其他情况下无效(带有选择值的 If 语句)