DAVIDNYARKO123 / yolov8-silva

41 stars 36 forks source link

TypeError: int() argument must be a string, a bytes-like object or a number, not 'Results' #2

Closed monkeycc closed 1 year ago

monkeycc commented 1 year ago
    # Convert tensor array to numpy
    print(detect_params[0].numpy())
    detect_params = detect_params[0].numpy()

    print("detect_params",detect_params)

    if len(detect_params) !=0:

        # Loop through all detections in current frame
        for param in detect_params:
            print("param",param)

            # Draw BBox around detection
            cv2.rectangle(frame, (int(param[0]),int(param[1])), (int(param[2]), int(param[3])), (0,0,255), 3)
YOLOv8n summary (fused): 168 layers, 3151904 parameters, 0 gradients, 8.7 GFLOPs
0: 480x640 92.2ms
Speed: 1.0ms pre-process, 92.2ms inference, 1.0ms postprocess per image at shape (1, 3, 640, 640)
[]
detect_params []
0: 480x640 77.8ms
Speed: 1.0ms pre-process, 77.8ms inference, 0.0ms postprocess per image at shape (1, 3, 640, 640)
[]
detect_params []
0: 480x640 1 person, 81.5ms
Speed: 1.0ms pre-process, 81.5ms inference, 1.0ms postprocess per image at shape (1, 3, 640, 640)
[[          4           1         637         478     0.50595           0]]
detect_params [[          4           1         637         478     0.50595           0]]
param [[          4           1         637         478     0.50595           0]]
Traceback (most recent call last):
  File "f:/2022/PY/yolov8_n_opencv.py", line 73, in <module>
    cv2.rectangle(frame, (int(param[0]),int(param[1])), (int(param[2]), int(param[3])), (0,0,255), 3)
TypeError: int() argument must be a string, a bytes-like object or a number, not 'Results'
Sentry is attempting to send 2 pending error messages
Waiting up to 2 seconds
Press Ctrl-Break to quit
DAVIDNYARKO123 commented 1 year ago

Hello @monkeycc , the issue above has been fixed after your submission. It was associated with the new release of ultralytics and how they want to simplify the use of YOLO in a python environment.

you can re-clone repo or update yolov8_n_opencv.py with code bellow.


DP = detect_params[0].numpy()
print(DP)

    if len(DP) != 0:
        for i in range(len(detect_params[0])):
            print(i)

            boxes = detect_params[0].boxes
            box = boxes[i]  # returns one box
            clsID = box.cls.numpy()[0]
            conf = box.conf.numpy()[0]
            bb = box.xyxy.numpy()[0]

            cv2.rectangle(
                frame,
                (int(bb[0]), int(bb[1])),
                (int(bb[2]), int(bb[3])),
                detection_colors[int(clsID)],
                3,
            )

            # Display class name and confidence
            font = cv2.FONT_HERSHEY_COMPLEX
            cv2.putText(
                frame,
                class_list[int(clsID)]
                + " "
                + str(round(conf, 3))
                + "%",
                (int(bb[0]), int(bb[1]) - 10),
                font,
                1,
                (255, 255, 255),
                2,
            )
oriaj3 commented 1 year ago

I am using an nvidia jetson device, so I need to modify line 55 to:

DP = detect_params[0].cpu().numpy()

And I get the following error when executing: Line 58, in if len(DP) !=0: The error is: 'NoneType' object cannot be interpreted as an integer.

Can you help me?