pskcci / intel-01

0 stars 0 forks source link

YOLO detect 파이선 코드 #226

Open J-WBaek opened 8 months ago

J-WBaek commented 8 months ago
from ultralytics import YOLO
import cv2

model = YOLO("yolov5s.pt")

# from ndarray
im2 = cv2.imread("cat1.jpg")
results = model.predict(source=im2, save=True, save_txt=False)  # save predictions as labels
conf = results[0].boxes.conf.item()
if conf > 0.5:
    print("A confidence is ......")
    print(conf)
agroidmk2 commented 8 months ago

PRO TIP 💡 Replace 'model=yolov5s.pt' with new 'model=yolov5su.pt'. YOLOv5 'u' models are trained with https://github.com/ultralytics/ultralytics and feature improved performance vs standard YOLOv5 models trained with https://github.com/ultralytics/yolov5.

0: 384x640 3 persons, 1 cat, 43.0ms Speed: 2.0ms preprocess, 43.0ms inference, 301.1ms postprocess per image at shape (1, 3, 384, 640) Results saved to /home/busan/intel01-ssh/runs/detect/predict3 Traceback (most recent call last): File "/home/busan/yolov5/project.py", line 11, in if results[0].boxes.conf > 0.5: RuntimeError: Boolean value of Tensor with more than one value is ambiguous

synsan123 commented 8 months ago

코드 실행 시 if results[0].boxes.conf > 0.5: 에서

Exception has occurred: RuntimeError Boolean value of Tensor with more than one value is ambiguous File "/home/kyj/yolov5/dataTest.py", line 9, in if results[0].boxes.conf > 0.5: RuntimeError: Boolean value of Tensor with more than one value is ambiguous 라는 RuntimeError가 발생합니다

J-WBaek commented 8 months ago

해당 런타임 에러는 tensor와 value를 비교해서 생긴 오류입니다. 아래와 같이 results[0].boxes.conf 를 results[0].boxes.conf.item() 로 변경하고 실행해보세요.