Azure / Azure/MachineLearningNotebooks
Trouble Deploying Yolov5 (pt file) Pytorch model
- Lenguaje dominante
- Jupyter Notebook
- Estrellas
- 4.4k
- Forks
- 2.6k
- Métricas de merge de PR
- Sin PR fusionados en 30 d
Descripción
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
Guía de contribución
No hay ninguna guía de contribución indexada para este repositorio
Línea de trabajo
Comienza con source_dir/entry_script.py y el código de deployment que utiliza LocalWebservice, y luego ejecuta el deployment mostrado para inspeccionar AZUREML_MODEL_DIR y la llamada a torch.hub.load. Compara el entorno observado y el comportamiento de carga del modelo con el Azure ML deployment tutorial; se considera terminado cuando el modelo YOLOv5 registrado puede inicializarse y el deployment ya no falla en init.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- azure, python, pytorch
- Área
- cloud, machine-learning
- Tipo de issue
- Error
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Estado de actividad
- Estancado
- Claridad
- Necesita aclaración
- Aptitud para principiantes
- 20/100