더북(TheBook)
def nms(bbox_list, threshold=0.6): # ⑤
    return [bbox for bbox in bbox_list if bbox[4] > threshold]

def get_YOLO_output(YOLO, image_path, class_names): # ⑥
    image_cv = cv2.imread(image_path)
    original_h, original_w, _ = image_cv.shape
    image_resized = cv2.resize(image_cv, IMAGE_SIZE) / 255.0
    image_input = np.expand_dims(image_resized, axis=0).astype('float32')
    
    yolo_output = YOLO(image_input)[0].numpy()
    
    bbox_list = []
    for y in range(7):
        for x in range(7):
            bbox1 = yolo_output[y][x][:4]
            bbox2 = yolo_output[y][x][5:9]
            bbox1_score = yolo_output[y][x][10:] * yolo_output[y][x][4]
            bbox2_score = yolo_output[y][x][10:] * yolo_output[y][x][9]
            
            bbox1_processed = process_single_bbox(x, y, bbox1, (original_w, original_h), bbox1_score, class_names)
            bbox2_processed = process_single_bbox(x, y, bbox2, (original_w, original_h), bbox2_score, class_names)
            
            bbox_list.extend([bbox1_processed, bbox2_processed])

    nms_boxes = nms(bbox_list)
신간 소식 구독하기
뉴스레터에 가입하시고 이메일로 신간 소식을 받아 보세요.