如何使用 FasterRCNN Openimages v4?

How to use FasterRCNN Openimages v4?

我似乎找不到任何关于如何使用此模型的文档。 我正在尝试用它打印出视频中出现的对象 任何帮助将不胜感激 我才刚开始所以对我放轻松

I am trying to use it to print out the objects that appear in a video

我理解你的问题是打印出找到的对象的名称。

我不知道你是如何实现在 OpenImages v4 上训练 Fast RCNN 的地方的。因此,我会给你the model from Tensorflow Hub. Google Colab. AI Hub

的方法

经过一番挖掘和大量试验和错误后,我想到了这个

#!/home/ahmed/anaconda3/envs/TensorFlow/bin/python3.8
import tensorflow as tf
import tensorflow_hub as hub
import time,imageio,sys,pickle

# sys.argv[1] is used for taking the video path from the terminal
video = sys.argv[1]
#passing the video file to ImageIO to be read later in form of frames
video = imageio.get_reader(video)
dictionary = {}
#download and extract the model( faster_rcnn/openimages_v4/inception_resnet_v2 or
# openimages_v4/ssd/mobilenet_v2) in the same folder
module_handle = "*Path to the model folder*"
detector = hub.load(module_handle).signatures['default']
#looping over every frame in the video
for index, frames in enumerate(video):
    # converting the images ( video frames ) to tf.float32 which is the only acceptable input format
    image = tf.image.convert_image_dtype(frames, tf.float32)[tf.newaxis]
    # passing the converted image to the model
    detector_output = detector(image)
    class_names = detector_output["detection_class_entities"]
    scores = detector_output["detection_scores"]
    # in case there are multiple objects in the frame
    for i in range(len(scores)):
        if scores[i] > 0.3:
            #converting form bytes to string
            object = class_names[i].numpy().decode("ascii")
            #adding the objects that appear in the frames in a dictionary and their frame numbers
            if object not in dictionary:
                dictionary[object] = [index]
            else:
                dictionary[object].append(index)
print(dictionary)