hhk7734 / tensorflow-yolov4

YOLOv4 Implemented in Tensorflow 2.
MIT License
136 stars 75 forks source link

Issue with No detection? #53

Closed Jeremy26 closed 3 years ago

Jeremy26 commented 3 years ago

Hello,

If there are no objects on the image, what happens?

I'm having an error where the box result is negative: prediction --> [[0. 0. 0. 0. 0. 0.]] after the call to fit_pred_bboxes_to_original: [[ 0. -1.156 0. 0. 0. 0. ]] time: 3171.96 ms

If I need to then use the box; the negative result will bring an error.

I'm using the following script

def run_obstacle_detection(img):
    start_time=time.time()
    img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
    resized_image = yolo.resize_image(img)
    # 0 ~ 255 to 0.0 ~ 1.0
    resized_image = resized_image / 255.
    #input_data == Dim(1, input_size, input_size, channels)
    input_data = resized_image[np.newaxis, ...].astype(np.float32)

    candidates = yolo.model.predict(input_data)

    _candidates = []
    result = img.copy()
    for candidate in candidates:
        batch_size = candidate.shape[0]
        grid_size = candidate.shape[1]
        _candidates.append(tf.reshape(candidate, shape=(1, grid_size * grid_size * 3, -1)))
        #candidates == Dim(batch, candidates, (bbox))
        candidates = np.concatenate(_candidates, axis=1)
        #pred_bboxes == Dim(candidates, (x, y, w, h, class_id, prob))
        pred_bboxes = yolo.candidates_to_pred_bboxes(candidates[0], iou_threshold=0.35, score_threshold=0.40)
        print(pred_bboxes)
        pred_bboxes = yolo.fit_pred_bboxes_to_original(pred_bboxes, img.shape)
        print(pred_bboxes)
        exec_time = time.time() - start_time
        print("time: {:.2f} ms".format(exec_time * 1000))
        result = yolo.draw_bboxes(img, pred_bboxes)
    return result, pred_bboxes

result, pred_bboxes = run_obstacle_detection(img_left)
plt.imshow(result)
plt.show() 

Thanks for helping!

hhk7734 commented 3 years ago

is the script above your full script?