YOLOv5 custom dataset object detection - Bounding box and Identification is not showing when I run my code

40 views Asked by At

I'm currently learning how to do custom dataset object detection by using Yolov5. This is my current code and I am using PyCharm.
It does not show any bounding box or identification when I run an mp4 video.

import torch
from matplotlib import pyplot as plt
import numpy as np
import cv2

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


#real time detections
cap = cv2.VideoCapture('tridaxnew.mp4') #This video should have bounding box and identification but it is not
while cap.isOpened():
    ret, frame = cap.read()

    #make detections
    results = model(frame)

    cv2.imshow('ObjectDetection', np.squeeze(results.render()))

    if cv2.waitKey(10) & 0xFF == ord('q'):
        break
cap.release()
cv2.destroyAllWindows()

When I use the terminal by using
python detect.py --weights best.pt --conf 0.45 --img-size 420 --source CustomData/tridaxnew.mp4, it brings me the results I want. However if do it in the Python script, it just shows the video of it but it does not show any bounding box and identification. I did this so I can check if the yoloV5 detection works in real-time when I use my webcam. I would appreciate any tips.

0

There are 0 answers