Skip to content
Advertisement

How do I use the exported ‘best.pt” file from yolov5 colab file to run the trained weights locally?

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?

Advertisement

Answer

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
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement