如何在浏览器上执行TensorFlow实时对象检测模型
我是一个机器学习初学者,正在从事我的第一个ML项目,我制作了一个程序,可以检测人们是否实时戴头盔(使用TensorFlow和OpenCV),现在我执行它,Python使用相机,我的相机显示一个新窗口,但是现在我想在本地执行它,只是在本地,我不想部署它,
这是执行执行和显示程序的代码的一部分:
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'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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试
googlecolab
或kaggle
,都有所需的东西。Try
GoogleColab
orKaggle
, both have what you need.尝试使用烧瓶,您可以在浏览器上执行它。
Try using Flask, you can execute it on a browser.