首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >POST请求失败,因为在Azure容器上部署了大量数据发送到模型

POST请求失败,因为在Azure容器上部署了大量数据发送到模型
EN

Stack Overflow用户
提问于 2019-10-02 11:52:14
回答 2查看 589关注 0票数 1

摘要

我通过Azure机器学习服务SDK在Azure容器实例上部署了一个PyTorch模型。该模型以标准的numpy格式获取(大型)图像进行分类。

看来,我在服务器端遇到了HTTP请求大小限制。对模型的请求在8-9mb范围内成功地处理大小为PNG的图像,而对于15mb+大小的图像则失败。具体来说,如果413个请求实体太大,它就会失败。

我假设,作为部署过程的一部分,在正在构建的Docker映像中,在Nginx中设置了限制。我的问题是:考虑到这个问题是由于HTTP请求大小限制造成的,那么在azureml中有什么方法来增加这个限制吗?

部署过程

部署过程如预期的那样成功。

代码语言:javascript
运行
复制
from azureml.core import Workspace
from azureml.core.model import InferenceConfig, Model
from azureml.core.webservice import AciWebservice, Webservice
from azureml.exceptions import WebserviceException
from pathlib import Path

PATH = Path('/data/home/azureuser/my_project')

ws = Workspace.from_config()
model = ws.models['my_pytorch_model']

inference_config = InferenceConfig(source_directory=PATH/'src',
                                   runtime='python',
                                   entry_script='deployment/scoring/scoring.py',
                                   conda_file='deployment/environment/env.yml')

deployment_config = AciWebservice.deploy_configuration(cpu_cores=2, memory_gb=4)
aci_service_name = 'azure-model'

try:
    service = Webservice(ws, name=aci_service_name)
    if service:
        service.delete()
except WebserviceException as e:
    print()

service = Model.deploy(ws, aci_service_name, [model], inference_config, deployment_config)

service.wait_for_deployment(True)
print(service.state)

基于requests测试

使用请求进行的简单测试:

代码语言:javascript
运行
复制
import os
import json
import numpy as np
import requests
from PIL import Image as PilImage

test_data = np.array(PilImage.open(PATH/'src/deployment/test/test_image.png')).tolist()
test_sample = json.dumps({'raw_data': 
    test_data
})
test_sample_encoded = bytes(test_sample, encoding='utf8')

headers = {
    'Content-Type': 'application/json'
}

response = requests.post(
    service.scoring_uri,
    data=test_sample_encoded,
    headers=headers,
    verify=True,
    timeout=10
)

requests中为更大的文件生成以下错误:

代码语言:javascript
运行
复制
ConnectionError: ('Connection aborted.', BrokenPipeError(32, 'Broken pipe'))

当数据上传完成之前从服务器关闭连接时,我猜这是请求中已知的错误。

基于pycurl的测试

使用curl包装器,我得到了更可解释的响应。

代码语言:javascript
运行
复制
import pycurl
from io import BytesIO

c = pycurl.Curl()
b = BytesIO()

c.setopt(c.URL, service.scoring_uri)
c.setopt(c.POST, True)
c.setopt(c.HTTPHEADER,['Content-Type: application/json'])
c.setopt(pycurl.WRITEFUNCTION, b.write)
c.setopt(c.POSTFIELDS, test_sample)
c.setopt(c.VERBOSE, True)
c.perform()

out = b.getvalue()

b.close()
c.close()

print(out)

对于大型文件,这将产生以下错误:

代码语言:javascript
运行
复制
<html>
    <head>
        <title>
            413 Request Entity Too Large
        </title>
    </head>
    <body bgcolor="white">
        <center>
            <h1>
                413 Request Entity Too Large
            </h1>
        </center>
        <hr>
        <center>
                nginx/1.10.3 (Ubuntu)
        </center>
    </body>
</html>

让我相信这是Nginx配置中的一个问题。具体来说,我猜client_max_body_size被设置为10 to。

问题概述

考虑到我确实碰到了Nginx配置的问题,我能以某种方式改变它吗?如果不使用Azure机器学习服务SDK,那么可能是通过覆盖/etc/nginx/nginx.conf文件吗?

EN

回答 2

Stack Overflow用户

发布于 2019-10-02 17:41:45

在构建的映像中,nginx配置中的client_max_body_size设置为100 m。不支持更改nginx配置。

票数 0
EN

Stack Overflow用户

发布于 2019-10-02 14:59:59

为了获取大量数据,您可能需要研究不同的体系结构。在HTTP请求体中传递大量原始数据不是最有效的方法。

例如,您可以构建一个评分管道。例如,请参阅此笔记本:Pipeline Style Transfer

或者,如果您想使用ACI服务,您可以将图像放置到blob存储区,然后通过引用blob位置传递图像。

票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/58200953

复制
相关文章

相似问题

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