I have trained my model using yoloV5 on google colab, following the provided tutorial and walkthrough provided for training any custom model: Colab file for training your own custom model. I now have an exported best.pt
file after running the last cell in the link provided. Now, I want to make use of this trained weight to run a detection locally on any python script. Is this possible? If so, how do I go about doing this?
Asked
Active
Viewed 1.2k times
4
2 Answers
1
You should follow this step:
- Create an empty folder in desktop called ObjectDetection
- Open command prompt and change directory to that new folder using
cd ObjectDetection
. - Clone yolov5 repo using command -
git clone https://github.com/ultralytics/yolov5.git
. It will create a new folder called yolov5 inside ObjectDetection folder.
yolov5 folder contains important python file called detect.py which is responsible to detect the objects. - After cloning the repo, enter into yolov5 folder using
cd yolov5
- Install all the necessary requirements using -
pip install -r requirements.txt
- Download best.pt from colab and manually paste it inside yolov5 folder.
- Also copy the image that you want to test inside yolov5 folder.
- Before running inference, make sure that image.png, best.pt and detect.py should be in inside yolov5 folder.
- You can then run inference inside yolov5 folder by using this command:
python detect.py --weights best.pt --source image.png
- After the process is completed, you can check the result inside path
ObjectDetection/yolov5/runs/detect/exp

Prakash Dahal
- 4,388
- 2
- 11
- 25
-
Okay when I run the install step, I get an error for building wheel for pycocotools. How do I fix that? Or do I ignore the error – Jun 09 '21 at 05:24
-
Are you using windows or linux? – Prakash Dahal Jun 09 '21 at 05:40
-
Use this command separately `pip3 install pycocotools` – Prakash Dahal Jun 09 '21 at 05:42
0
Use colab files lib
from google.colab import files
files.download('/content/yolov5/runs/train/yolov5s_results/weights/best.pt')
If the path is different you can change the path.

Prabhat Kumar Sahu
- 918
- 8
- 13