'How do I execute my TensorFlow Realtime Object Detection model on a browser
I'm a Machine learning beginner, working on my first ML project, I made a program that detects if people are wearing helmets in realtime (Using TensorFlow and OpenCV), now when I execute it, Python displays a new window using my camera, but now I want to execute it on a browser, just locally, I don't want to deploy it
This is the part of the code that does the execution and the display of the program :
while True:
ret, frame = cap.read()
image_np = np.array(frame)
input_tensor = tf.convert_to_tensor(np.expand_dims(image_np, 0), dtype=tf.float32)
detections = detect_fn(input_tensor)
num_detections = int(detections.pop('num_detections'))
detections = {key: value[0, :num_detections].numpy()
for key, value in detections.items()}
detections['num_detections'] = num_detections
# detection_classes should be ints.
detections['detection_classes'] = detections['detection_classes'].astype(np.int64)
label_id_offset = 1
image_np_with_detections = image_np.copy()
viz_utils.visualize_boxes_and_labels_on_image_array(
image_np_with_detections,
detections['detection_boxes'],
detections['detection_classes']+label_id_offset,
detections['detection_scores'],
category_index,
use_normalized_coordinates=True,
max_boxes_to_draw=5,
min_score_thresh=.5,
agnostic_mode=False)
cv2.imshow('object detection', cv2.resize(image_np_with_detections, (800, 600)))
if cv2.waitKey(1) & 0xFF == ord('q'):
cap.release()
break
I don't know how to proceed from here, it works perfectly on my computer, but I don't know how I could switch to a browser, I don't know where to start from and would appreciate some help if possible
Solution 1:[1]
Try GoogleColab
or Kaggle
, both have what you need.
Solution 2:[2]
Try using Flask, you can execute it on a browser.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | DontDownvote |
Solution 2 | mehmetgenc |