Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Load my own Yolov5 model on cvat by nuclio (function.yaml) #4909

Closed
matiassalriv1998 opened this issue Sep 6, 2022 · 10 comments
Closed

Load my own Yolov5 model on cvat by nuclio (function.yaml) #4909

matiassalriv1998 opened this issue Sep 6, 2022 · 10 comments

Comments

@matiassalriv1998
Copy link

My actions before raising this issue

The problem starts when deploying the model to nuclio in order to use it at cvat.

I have a trained model by yolo v5 (its weights best.pt file) and from that model I want to auto annotate (which is in fact the purpose of cvat). The thing is the official tutorial pasted above shows how to do it with a detectron2 model. For yolo there's an example on the cvat folder at serverless/ultralytics/yolo that I already loaded and worked. Seems easy right?

I copied the yolov5 folder to use from start to load mine. I start so from function.yaml and main.py at the copied folder inside nuclio folder and the thing is how to modify that files to get my own model instead of the standard yolo model which is actually using that.

Expected Behaviour

The model should be loaded to nuclio after running on my wsl ubuntu the command ./serverless/deploy_cpu.sh ./serverless/pytorch/ultralytics/yolov5-copy

Current Behaviour

Executor failed running [/bin/sh -c pip install nuclio-sdk msgpack --no-index --find-links /opt/nuclio/whl]: exit code 127

Also exit code 1 sometimes the error shown deppends on changes made to function.yaml or main.py.

Possible Solution

Surely function.yaml and main.py must be changed to fit with my own trained model (my weights best.pt file) but seems not so easy after a lot of tries and there's no information on internet about how to modify that file. Probably base:Image should be changed on function... I don't know, I've been trying and there's no way

Steps to Reproduce (for bugs)

1-Simply install cvat repo from cvat and install auto annotation tools by nuclio. (All this on Ubuntu 18.04 WSL on Windows)
2-Deploy a custom YOLOv5 model (not the default one).

Context

Impossible to deploy my own YOLOv5 dataset to nuclio serverless as function. Impossible to auto-annotate.

Your Environment

  • Ubuntu on WSL 18.04 on Windows.

  • Docker version : latest.

  • Other diagnostic information / logs:
    Console exit code 127 or exit code 1 provocated by incorrect changes on function.yaml and main.py, the problem is in that files.

@matiassalriv1998
Copy link
Author

Self-solved. There is no information on internet for the particular case on nuclio yolo model for auto trainning further than the example with the yolo default model so I hope this is helping someone.

On main the loading model configuration must be changed this way:

torch.model.load(, 'custom', path=/best.pt, force_reload=True) is the correct sentence for a custom model. All other configurations could generate error on function deploy.

I close the issue.

@boldjoel
Copy link

hey, I am currently trying to load my local model file during the model deployment through editing YAML file with kind: COPY. But it seems that the system cannot find the local file. Just wonder how you make it.

@matiassalriv1998
Copy link
Author

matiassalriv1998 commented Sep 16, 2022

I would need more information about your case. What I did where to load my model for auto-annotation on CVAT getting the repository on an Ubuntu virtualization by WSL on Windows using a Docker container to deploy on nuclio and finally auto-annotate on CVAT.

My model where YoloV5 model on pytorch. I put some instructions bellow in order to help you or someone with my problem with the same purpose.

If this is your specific case or you are deploying some other nuclio function it's all about routes. At main.py there is a sentence torch..hub.load() with wrong arguments (wrong for your model) so use ultralytics/yolov5 repo at first argument (this one lets you use some repo scripts which are necessary), 'custom' as a seccond argument and third argument the path you can find at localhost:8070 on nuclio interface where you have to save your weights (best.pt). To get this last one deploy the yolo default as said on cvat auto-annotation and navigate to find the route, but is usually the common folder inside serverless at repo (you will find something like opt/common). The last argument force_reload is optional.

In main.py:

model = torch.hub.load('ultralyics/yolov5', 'custom', path='common/best.pt', force_reload=True)

@nfrvnikita
Copy link

nfrvnikita commented Dec 12, 2022

I would need more information about your case. What I did where to load my model for auto-annotation on CVAT getting the repository on an Ubuntu virtualization by WSL on Windows using a Docker container to deploy on nuclio and finally auto-annotate on CVAT.

My model where YoloV5 model on pytorch. I put some instructions bellow in order to help you or someone with my problem with the same purpose.

If this is your specific case or you are deploying some other nuclio function it's all about routes. At main.py there is a sentence torch..hub.load() with wrong arguments (wrong for your model) so use ultralytics/yolov5 repo at first argument (this one lets you use some repo scripts which are necessary), 'custom' as a seccond argument and third argument the path you can find at localhost:8070 on nuclio interface where you have to save your weights (best.pt). To get this last one deploy the yolo default as said on cvat auto-annotation and navigate to find the route, but is usually the common folder inside serverless at repo (you will find something like opt/common). The last argument force_reload is optional.

In main.py:

model = torch.hub.load('ultralyics/yolov5', 'custom', path='common/best.pt', force_reload=True)

Hi, I also needed to create a model with my parameters, but unfortunately it did not work.
In main.py "path" I specified the path to my model parameters (cvat/serverless/common/params.pt), made deploy with the following commands:

nuctl deploy --project-name cvat \
  --path serverless/pytorch/ultralytics/yolov5/nuclio
  --volume `pwd`/serverless/common:/opt/nuclio/common \
  --platform local

After loading the model my tag is missing in the labels and the following error occurs:

requests.exceptions.ConnectionError: HTTPConnectionPool(host='host.docker.internal', port=port): Max retries exceeded with url: / (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at >: Failed to establish a new connection: [Errno 111] Connection refused'))

How do I fix this? I followed the documentation, but I must have made a mistake somewhere...

@nfrvnikita
Copy link

Please tell me what steps you took to create a custom model?

@halskov
Copy link

halskov commented Dec 22, 2022

I would need more information about your case. What I did where to load my model for auto-annotation on CVAT getting the repository on an Ubuntu virtualization by WSL on Windows using a Docker container to deploy on nuclio and finally auto-annotate on CVAT.
My model where YoloV5 model on pytorch. I put some instructions bellow in order to help you or someone with my problem with the same purpose.
If this is your specific case or you are deploying some other nuclio function it's all about routes. At main.py there is a sentence torch..hub.load() with wrong arguments (wrong for your model) so use ultralytics/yolov5 repo at first argument (this one lets you use some repo scripts which are necessary), 'custom' as a seccond argument and third argument the path you can find at localhost:8070 on nuclio interface where you have to save your weights (best.pt). To get this last one deploy the yolo default as said on cvat auto-annotation and navigate to find the route, but is usually the common folder inside serverless at repo (you will find something like opt/common). The last argument force_reload is optional.
In main.py:
model = torch.hub.load('ultralyics/yolov5', 'custom', path='common/best.pt', force_reload=True)

Hi, I also needed to create a model with my parameters, but unfortunately it did not work. In main.py "path" I specified the path to my model parameters (cvat/serverless/common/params.pt), made deploy with the following commands:

nuctl deploy --project-name cvat \
  --path serverless/pytorch/ultralytics/yolov5/nuclio
  --volume `pwd`/serverless/common:/opt/nuclio/common \
  --platform local

After loading the model my tag is missing in the labels and the following error occurs:

requests.exceptions.ConnectionError: HTTPConnectionPool(host='host.docker.internal', port=port): Max retries exceeded with url: / (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at >: Failed to establish a new connection: [Errno 111] Connection refused'))

How do I fix this? I followed the documentation, but I must have made a mistake somewhere...

I experience the same issue getting this error when running the build in yolov5 detector:

Detection error occurred
Error: Request failed with status code 503. "HTTPConnectionPool(host='host.docker.internal', port=49582): Max retries exceeded with url: / (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7fd4fb0e02b0>: Failed to establish a new connection: [Errno 111] Connection refused'))".

@Sneh09
Copy link

Sneh09 commented Jan 20, 2023

@halskov @nfrvnikita Even I am facing the same problem. Did you find any solution for it ?
@matiassalriv1998 Could you please help with this problem.

@halskov
Copy link

halskov commented Jan 20, 2023

@halskov @nfrvnikita Even I am facing the same problem. Did you find any solution for it ?
@matiassalriv1998 Could you please help with this problem.

I gave up and ended up running detect.py locally on the images, then uploading the annotations manually to completely avoid the Nuclio integration.

@JustVietNH
Copy link

@halskov @nfrvnikita Even I am facing the same problem. Did you find any solution for it ? @matiassalriv1998 Could you please help with this problem.

Hey, maybe it is still an issue for you. I haven't tried this yet, but I am able to use custom models which are not yolo models.

In this linked issue, it is described how to load custom weights to your custom yolo model
ultralytics/yolov5#1441 (comment)

You need to modify the main.py file in your custom nuclio dir to load the weights, If I understood correctly.

@halskov
Copy link

halskov commented Feb 3, 2023

@halskov @nfrvnikita Even I am facing the same problem. Did you find any solution for it ? @matiassalriv1998 Could you please help with this problem.

Hey, maybe it is still an issue for you. I haven't tried this yet, but I am able to use custom models which are not yolo models.

In this linked issue, it is described how to load custom weights to your custom yolo model ultralytics/yolov5#1441 (comment)

You need to modify the main.py file in your custom nuclio dir to load the weights, If I understood correctly.

I haven't looked into this since then as my current workflow of doing the detection locally and then uploading runs smoothly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants