首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在使用边缘部署的AutoML视觉模型时,是否可以传递参数?

在使用边缘部署的AutoML视觉模型时,是否可以传递参数?
EN

Stack Overflow用户
提问于 2020-10-09 07:19:19
回答 2查看 119关注 0票数 1

我已经使用谷歌云平台训练了一个AutoML愿景模型。我训练了一个特定于边缘的版本,这样我就可以在我自己的硬件上将其部署到docker镜像中。

我遵循了这里的教程说明:https://cloud.google.com/vision/automl/docs/containers-gcs-tutorial

并且已经使用示例python代码成功地执行了一些预测:

代码语言:javascript
复制
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_thresholdmax_bounding_box_count添加到请求json包中。

我尝试了这样的东西:

代码语言:javascript
复制
    instances = {
        'instances': [
            {'image_bytes': {'b64': str(encoded_image)},
            'key': key}
        ],
        'params': [
            {'max_bounding_box_count': 10}
        ]
    }

无济于事。

有人知道如何将参数添加到json请求负载中吗?或者边缘部署的docker是否会接受它们?

EN

回答 2

Stack Overflow用户

发布于 2020-10-14 05:52:09

你应该尝试一下类似这样的东西:

代码语言:javascript
复制
{
   "instances":[
      {
         "image_bytes":{
            "b64":"/9j/4AAQSkZJRgABAQ....ABAAD2P//Z"
         },
         "params":{
            "maxBoundingBoxCount":"100"
         }
      }
   ]
}

documentation显示了一个示例。

票数 0
EN

Stack Overflow用户

发布于 2021-05-03 20:03:27

只是想知道它是否工作,我正在尝试与docker score_threshold类似的东西,虽然这不会给出格式错误,但响应仍然超过阈值

代码语言:javascript
复制
{
    "instances": [
        {
            "image_bytes": {
                "b64": "<base64 encoded image>"
            },
            "key": "your-chosen-image-key123"
        }
    ],
                "params": {
                "score_threshold": 0.7
            }
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/64271887

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档