Question: I ' m currently learning how to do custom dataset object detection by using Yolov 5 . This is my current code and I am

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. But 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 I 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.
This is my code in main.py. Please show me how to fix it and explain the changes in the code.
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()

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!