Azure / Azure/MachineLearningNotebooks
Trouble Deploying Yolov5 (pt file) Pytorch model
- Langage dominant
- Jupyter Notebook
- Étoiles
- 4.4k
- Forks
- 2.6k
- Métriques de merge des PR
- Aucune PR mergée en 30 j
Description
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
Guide de contribution
Aucun guide de contribution indexé pour ce dépôt
Piste de recherche
Commencez par source_dir/entry_script.py et le code de déploiement utilisant LocalWebservice, puis exécutez le déploiement présenté pour inspecter AZUREML_MODEL_DIR et l’appel à torch.hub.load. Comparez l’environnement observé et le comportement de chargement du modèle avec le Azure ML deployment tutorial ; le travail est terminé lorsque le modèle YOLOv5 enregistré peut s’initialiser et que le déploiement n’échoue plus lors de init.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Évaluation
- Stack technique
- azure, python, pytorch
- Domaine
- cloud, machine-learning
- Type d'issue
- Bug
- Difficulté
- 4/5
- Temps estimé
- 3-5 jours
- Activité
- À l'abandon
- Clarté
- À clarifier
- Accessibilité débutants
- 20/100