Azure / Azure/MachineLearningNotebooks
Trouble Deploying Yolov5 (pt file) Pytorch model
- 主要語言
- Jupyter Notebook
- 星號
- 4.4k
- 分支
- 2.6k
- PR 合併指標
- 30 天內沒有已合併 PR
描述
Hi there,
I am trying to deploy a model by following the tutorial.
Before reading the full details I would like to address something I think is causing the problem.
When I run print(os.getenv('AZUREML_MODEL_DIR')) it returns None. Should I be able to see the variable?, I don't think the environment variable is being created when I registered my model.
Anyway here is my entry script, deployment code and error message.
Here is my entry script:
```
from azureml.core.model import Model
from PIL import Image
import json
import numpy as np
import os
import torch
def init():
"""
Load registered YOLO v5 model from the Azure ML model Registry
"""
global model
print(os.getenv('AZUREML_MODEL_DIR'))
model = torch.hub.load(os.getenv('AZUREML_MODEL_DIR'), 'best.pt')
def run(request):
"""
Code to execute upon receiving a request
"""
print(request)
file_bytes = request.files["image"]
image = Image.open(file_bytes).convert('RGB')
img = Image.open(io.BytesIO(img_bytes))
# inference
results = model(img, size=640)
# inference
return results
def preprocess():
return None
```
Here is all the code relating to the deployment, bare in mind I have already registered a model in AzureML workspace.
```
from azureml.core import Environment
from azureml.core.model import InferenceConfig
from azureml.core.webservice import LocalWebservice
env = Environment(name="Covid Detector Project")
dummy_inference_config = InferenceConfig(
environment=myenv,
source_directory="./source_dir",
entry_script="entry_script.py",
)
deployment_config = LocalWebservice.deploy_configuration(port=6789)
service = Model.deploy(
ws,
"myservice",
[model],
dummy_inference_config,
deployment_config,
overwrite=True,
)
service.wait_for_deployment(show_output=True)
```
This is the error I am receiving:
```
File "/var/azureml-app/source_dir/entry_script.py", line 16, in init
model = torch.hub.load(os.getenv('AZUREML_MODEL_DIR'), 'best.pt')
File "/azureml-envs/azureml_20ec05239403d2f40e2df6a2b8665783/lib/python3.6/site-packages/torch/hub.py", line 397, in load
repo_or_dir = _get_cache_or_reload(repo_or_dir, force_reload, verbose, skip_validation)
File "/azureml-envs/azureml_20ec05239403d2f40e2df6a2b8665783/lib/python3.6/site-packages/torch/hub.py", line 165, in _get_cache_or_reload
repo_owner, repo_name, branch = _parse_repo_info(github)
File "/azureml-envs/azureml_20ec05239403d2f40e2df6a2b8665783/lib/python3.6/site-packages/torch/hub.py", line 112, in _parse_repo_info
repo_owner, repo_name = repo_info.split('/')
ValueError: too many values to unpack (expected 2)
```
The first thing I think I need to understand is how to retrieve the os.getenv('AZUREML_MODEL_DIR') environment variable.
Thanks,
Viraj
貢獻指南
這個儲存庫沒有索引到貢獻指南
研究方向
從 source_dir/entry_script.py 和使用 LocalWebservice 的部署程式碼開始,然後執行所示的部署,以檢查 AZUREML_MODEL_DIR 和 torch.hub.load 呼叫。將觀察到的環境和模型載入行為與 Azure ML deployment tutorial 進行比較;當已註冊的 YOLOv5 模型能夠初始化,且部署不再在 init 時失敗時,即表示完成。
由索引模型根據 Issue 內容生成。
評估
- 技術堆疊
- azure, python, pytorch
- 領域
- cloud, machine-learning
- Issue 類型
- 缺陷
- 難度
- 4/5
- 預估耗時
- 3-5 天
- 活躍度
- 停滯
- 描述清晰度
- 需要釐清
- 新手友好度
- 20/100