Azure / Azure/MachineLearningNotebooks
Trouble Deploying Yolov5 (pt file) Pytorch model
- Linguagem predominante
- Jupyter Notebook
- Estrelas
- 4.4k
- Forks
- 2.6k
- Métricas de merge de PRs
- Nenhum PR com merge em 30d
Descrição
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
Guia de contribuição
Nenhum guia de contribuição indexado para este repositório
Direção de pesquisa
Comece com source_dir/entry_script.py e o código de deployment que usa LocalWebservice e, em seguida, execute o deployment mostrado para inspecionar AZUREML_MODEL_DIR e a chamada torch.hub.load. Compare o ambiente observado e o comportamento de carregamento do modelo com o Azure ML deployment tutorial; considera-se concluído quando o modelo YOLOv5 registrado consegue ser inicializado e o deployment não falha mais em init.
Escrita pelo modelo de indexação a partir do texto da issue.
Avaliação
- Stack de tecnologia
- azure, python, pytorch
- Domínio
- cloud, machine-learning
- Tipo de issue
- Bug
- Dificuldade
- 4/5
- Tempo estimado
- 3-5 dias
- Status de atividade
- Estagnada
- Clareza
- Precisa de esclarecimento
- Facilidade para iniciantes
- 20/100