ultralytics / yolov5

YOLOv5 🚀 in PyTorch > ONNX > CoreML > TFLite
https://docs.ultralytics.com
GNU Affero General Public License v3.0
51.23k stars 16.44k forks source link

Force_reload Error #5362

Closed ozlem-atiz closed 3 years ago

ozlem-atiz commented 3 years ago

Hello my teacher. I'm getting a problem here. Try force_reload= true feedback. I couldn't understand even if I tried. The same error continues. Can you please help?

Thanks

this is my code

``import numpy as np import cv2 import time import torch model = torch.hub.load('ultralytics/yolov5', 'custom', path='best.pt',force_reload=True) model1 = torch.hub.load('ultralytics/yolov5', 'custom', path='best1.pt',force_reload=True) cap = cv2.VideoCapture(0) prev_frame_time = 0 new_frame_time = 0

while(cap.isOpened()): ret, frame = cap.read() if not ret: break gray = frame gray = cv2.resize(gray, (500, 300))

results = model(gray)
for _, det in enumerate(results.xyxy[0]):
    # convert from tensor to numpy
    box = det.detach().cpu().numpy()[:5]
    # convert from float to integer
    box = [int(x) for x in box]
    x1, y1, x2, y2,name = box  # crop the license plate image part
    cropped = gray[y1:y2, x1:x2].copy()
    label = "plate"
    color = (0, 255, 255)
    # draw a box on original image
    cv2.rectangle(gray, (x1, y1), (x2, y2), (0, 255, 255), 2)
    t_size = cv2.getTextSize(label, cv2.FONT_HERSHEY_PLAIN, 2, 2)[0]

    img2 = cropped.copy()

results1=model1(img2)
results1.pandas().xyxy[0].sort_values('xmin')
yeni = str(results1.pandas().xyxy[0].sort_values('xmin').name.values)
clean_text2 = ""
for char in yeni:
    if char in "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ":
        clean_text2 += char
yeni = clean_text2
yeni = yeni.replace(" ", "")
font = cv2.FONT_HERSHEY_SIMPLEX
new_frame_time = time.time()
fps = 1/(new_frame_time-prev_frame_time)
prev_frame_time = new_frame_time
fps = int(fps)
fps = str(fps)
cv2.putText(gray, fps, (7, 70), font, 3, (100, 255, 0), 3, cv2.LINE_AA)
cv2.imshow('frame', gray)
if (len(yeni)<9) and (len(yeni)>6):
    print(yeni)
    print(len(yeni))
else:
    continue
if cv2.waitKey(1) & 0xFF == ord('q'):
    break

cap.release() cv2.destroyAllWindows() `` Screenshot from 2021-10-27 12-38-41

glenn-jocher commented 3 years ago

@ozlem-atiz

ozlem-atiz commented 3 years ago

@glenn-jocher I can't run it on a computer with a gpu. I did what you said and I get the same error. Frames came very low on the computer with CPU. I get 1 frame in 5 seconds. It's pretty low. For this reason, I wanted to run it on a computer with a GPU. But it doesn't work here :((

glenn-jocher commented 3 years ago

@ozlem-atiz see YOLOv5 PyTorch Hub to get started.

ozlem-atiz commented 3 years ago

I'm deleting the model loading part. But this error is falling in front of me. There is no problem with the codes. i am looking your send site . But same error @glenn-jocher

github-actions[bot] commented 3 years ago

👋 Hello, this issue has been automatically marked as stale because it has not had recent activity. Please note it will be closed if no further activity occurs.

Access additional YOLOv5 🚀 resources:

Access additional Ultralytics ⚡ resources:

Feel free to inform us of any other issues you discover or feature requests that come to mind in the future. Pull Requests (PRs) are also always welcomed!

Thank you for your contributions to YOLOv5 🚀 and Vision AI ⭐!