如何在浏览器上执行TensorFlow实时对象检测模型

发布于 2025-01-29 05:19:57 字数 1514 浏览 4 评论 0原文

我是一个机器学习初学者,正在从事我的第一个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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

拒绝两难 2025-02-05 05:19:57

尝试googlecolabkaggle,都有所需的东西。

Try GoogleColab or Kaggle, both have what you need.

往日 2025-02-05 05:19:57

尝试使用烧瓶,您可以在浏览器上执行它。

Try using Flask, you can execute it on a browser.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文