INNER CODE UNIT · Python
detect
chonyy/ML-auto-baseball-pitching-overlay · src/get_pitch_frames.py:134
def detect(infer, frame, input_size, iou, score_threshold, detected_balls):
image_data = cv2.resize(frame, (input_size, input_size))
image_data = image_data / 255.0
image_data = image_data[np.newaxis, ...].astype(np.float32)
batch_data = tf.constant(image_data)
pred_bbox = infer(batch_data)
for key, value in pred_bbox.items():
boxes = value[:, :, 0:4]
pred_conf = value[:, :, 4:]
boxes, scores, classes, valid_detections = tf.image.combined_non_max_suppression(
boxes=tf.reshape(boxes, (tf.shape(boxes)[0], -1, 1, 4)),
scores=tf.reshape(
pred_conf, (tf.shape(pred_conf)[0], -1, tf.shape(pred_conf)[-1])
),
max_output_size_per_class=50,
max_total_size=50,