hhk7734/tensorflow-yolov4

How to get the coordinates of the bounding box in YOLOv4?

Closed this issue · 3 comments

Sorry i want to know How to get the coordinates of the bounding box in YOLOv4? thanks

def predict(self, frame: np.ndarray, prob_thresh: float):
"""
Predict one frame
@param `frame`: Dim(height, width, channels)
@param `prob_thresh`
@return pred_bboxes
Dim(-1, (x, y, w, h, cls_id, prob))
"""
# image_data == Dim(1, input_size[1], input_size[0], channels)
height, width, _ = frame.shape
image_data = self.resize_image(frame)
image_data = image_data / 255.0
image_data = image_data[np.newaxis, ...].astype(np.float32)
candidates = self._predict(image_data)
candidates = [
c.numpy().astype(np.float32, copy=False) for c in candidates
]
pred_bboxes = self.get_yolo_detections(
yolos=candidates, prob_thresh=prob_thresh
)
self.fit_to_original(pred_bboxes, height, width)
return pred_bboxes

frame = cv2.imread(media_path)
frame_rgb = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
start_time = time.time()
bboxes = self.predict(frame_rgb, prob_thresh=prob_thresh)

Put an image in predict(). Then, you can get the bbox.

Sorry i want to run in v2.1.0 what can i do ?

https://wiki.loliot.net/docs/lang/python/libraries/yolov4/python-yolov4-about#tensorflow

from yolov4.tf import YOLOv4

yolo = YOLOv4()
# yolo = YOLOv4(tiny=True)

yolo.classes = "coco.names"
yolo.input_size = (640, 480)

yolo.make_model()
yolo.load_weights("yolov4.weights", weights_type="yolo")
# yolo.load_weights("yolov4-tiny.weights", weights_type="yolo")

frame = cv2.imread(media_path) 
frame_rgb = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB) 

bboxes = self.predict(frame_rgb)