google-cloud-platform - 使用边缘部署的 AutoML 视觉模型时是否可以传递参数?
问题描述
我已经使用 Google Cloud Platform 训练了一个 AutoML Vision 模型。我训练了一个特定于边缘的版本,因此我可以将它部署在我自己硬件上的 docker 映像中。
我按照这里的教程说明操作: https ://cloud.google.com/vision/automl/docs/containers-gcs-tutorial
并使用示例 python 代码成功执行了一些预测:
import base64
import io
import json
import requests
def container_predict(image_file_path, image_key, port_number=8501):
"""Sends a prediction request to TFServing docker container REST API.
Args:
image_file_path: Path to a local image for the prediction request.
image_key: Your chosen string key to identify the given image.
port_number: The port number on your device to accept REST API calls.
Returns:
The response of the prediction request.
"""
with io.open(image_file_path, 'rb') as image_file:
encoded_image = base64.b64encode(image_file.read()).decode('utf-8')
# The example here only shows prediction with one image. You can extend it
# to predict with a batch of images indicated by different keys, which can
# make sure that the responses corresponding to the given image.
instances = {
'instances': [
{'image_bytes': {'b64': str(encoded_image)},
'key': image_key}
]
}
# This example shows sending requests in the same server that you start
# docker containers. If you would like to send requests to other servers,
# please change localhost to IP of other servers.
url = 'http://localhost:{}/v1/models/default:predict'.format(port_number)
response = requests.post(url, data=json.dumps(instances))
print(response.json())
但是,响应包含比我想要的更多的预测(40,即使我只想要 5-10)。我想我可以在 POST 请求中添加一些参数来限制预测的数量,或者根据对象检测分数进行过滤。此处概述了此类功能: https ://cloud.google.com/automl/docs/reference/rest/v1/projects.locations.models/predict#request-body
该文档建议score_threshold
或max_bounding_box_count
应该能够添加到请求 json 包中。
我试过这样的事情:
instances = {
'instances': [
{'image_bytes': {'b64': str(encoded_image)},
'key': key}
],
'params': [
{'max_bounding_box_count': 10}
]
}
无济于事。
有人知道如何将参数添加到 json 请求有效负载吗?或者边缘部署的 docker 是否会接受它们?
解决方案
只是想知道它是否有效我正在尝试与 docker score_threshold 类似的东西,而这不会给出格式错误响应仍然超过阈值
{
"instances": [
{
"image_bytes": {
"b64": "<base64 encoded image>"
},
"key": "your-chosen-image-key123"
}
],
"params": {
"score_threshold": 0.7
}
}
推荐阅读
- linux - Docker 容器无法连接互联网,ping 正常,wget 失败
- python - 如何在 python 中从 BigQuery 获取表名
- c# - Blazor 在 C# 类上使用 RenderTreeBuilder 创建的 html 上的 .razor 传递变量和调用事件
- reactjs - 在 vis.js 中连接具有多个边的两个节点
- android - FCM 推送通知未在 Android 中接收打盹和深度睡眠模式
- java - 我想将列表中的颜色显示为两个不同的组,例如团队 1 和团队 2。如何分隔数组列表?
- ruby-on-rails - 可以将 rspec 配置为仅运行在单个规范文件中修改的测试吗?
- swift - 将文件从应用程序包复制并保存到桌面/其他地方
- reactjs - 我在 React 中有一个结果页面,我想将每个结果链接到一个详细页面,但使用动态 URL
- c++ - eof 函数不起作用并导致无限循环