美文网首页
训练和推理对象检测模型

训练和推理对象检测模型

作者: 逍遥_yjz | 来源:发表于2022-01-20 19:48 被阅读0次

    目录

    1. 数据集

    2. 环境配置

    3. 模型训练

    4. 评估模型

    5. 检测图像中的自定义对象

    5.1 图像的文件路径

    5.2 图像的文件-array

    5.3 图像的文件路径-单独的图像

    5.4 图像的文件-array-单独的图像

    6. 对视频进行对象检测特殊函数

    在最新版本的ImageAI v2.1.0中

    ImageAI提供了一种简单而强大的方法来使用YOLOv3 架构训练自定义对象检测**模型。这使您可以在与任何类型的感兴趣对象相对应的任何图像集上训练自己的模型。

    您可以使用经过训练的检测模型来检测图像、视频中的对象并执行视频分析。

    1. 数据集

    ======= imageai.Detection.Custom.DetectionModelTrainer =======

    这是检测模型训练类,它允许您使用 YOLOv3 在 Pascal VOC 注释格式的图像数据集上训练对象检测模型。训练过程会生成一个 JSON 文件,该文件映射图像数据集中的对象名称和检测锚点,并创建大量模型。

    首先,您需要准备Pascal VOC 格式的数据集并按如下详述进行组织:

    – 确定您要检测的对象类型并收集每个对象的大约 200 张(最低推荐)或更多图片

    – 收集图像后,您需要对图像中的对象进行注释。您可以使用 LabelIMG等工具为图像生成注释。

    – 为所有图像添加注释后,为您的数据集(例如耳机)创建一个文件夹,并在此父文件夹中创建子文件夹训练验证

    – 在train文件夹中,创建图像注释子文件夹。将每个对象图像的大约 70-80% 的数据集放在images文件夹中,并将这些图像的相应注释放在annotations文件夹中。

    – 在验证文件夹中,创建图像注释子文件夹。将其余数据集图像放在images文件夹中,并将这些图像的相应注释放在annotations文件夹中。

    – 完成此操作后,图像数据集文件夹的结构应如下所示:

    >> train    >> images       >> img_1.jpg  (shows Object_1)
                >> images       >> img_2.jpg  (shows Object_2)
                >> images       >> img_3.jpg  (shows Object_1, Object_3 and Object_n)
                >> annotations  >> img_1.xml  (describes Object_1)
                >> annotations  >> img_2.xml  (describes Object_2)
                >> annotations  >> img_3.xml  (describes Object_1, Object_3 and Object_n)
    
    >> validation   >> images       >> img_151.jpg (shows Object_1, Object_3 and Object_n)
                    >> images       >> img_152.jpg (shows Object_2)
                    >> images       >> img_153.jpg (shows Object_1)
                    >> annotations  >> img_151.xml (describes Object_1, Object_3 and Object_n)
                    >> annotations  >> img_152.xml (describes Object_2)
                    >> annotations  >> img_153.xml (describes Object_1)
    
    • 您可以完全从头开始训练您的自定义检测模型,也可以从预训练的 YOLOv3 模型中使用迁移学习(建议使用以提高准确性)。此外,我们还提供了一个示例带注释的 Hololens 和 Headsets(Hololens 和 Oculus)数据集供您训练。在下面的链接中下载预训练的 YOLOv3 模型和示例数据集

    样本数据集和预训练的 YOLOv3

    2. 环境配置

    • 为了训练您的检测模型,我们建议您安装Tensorflow-GPU v1.13.1以避免错误:
    pip install tensorflow==1.13.1
    pip install imageai==2.1.0
    pip install Keras==2.2.4
    python3.7
    

    3. 模型训练

    以下是在数据集上训练新检测模型的代码:

    from imageai.Detection.Custom import DetectionModelTrainer
    
    trainer = DetectionModelTrainer()
    trainer.setModelTypeAsYOLOv3()
    trainer.setDataDirectory(data_directory="hololens")
    trainer.setTrainConfig(object_names_array=["hololens"], batch_size=4, num_experiments=200, train_from_pretrained_model="pretrained-yolov3.h5")
    trainer.trainModel()
    

    在前 2 行中,我们导入了DetectionModelTrainer类并创建了它的一个实例

    trainer = DetectionModelTrainer()
    

    然后我们调用了以下函数

    • .setModelTypeAsYOLOv3(),该函数将物体检测训练实例的模型类型设置为YOLOv3模型:

      trainer.setModelTypeAsYOLOv3()
      
    • .trainer.setDataDirectory(),此函数用于设置数据集文件夹的路径:

      trainer.setDataDirectory()
      

    参数 data_directory(必需):这是您的数据集文件夹的路径。

    • .trainer.setTrainConfig(),该函数设置训练实例的属性:

      trainer.setTrainConfig()
      

    参数 object_names_array(必需):这是数据集中所有不同对象的名称列表。

    参数 batch_size(可选):这是训练实例的批量大小。

    参数 num_experiments(必需):也称为 epochs,它是网络将在所有训练中训练的次数。

    参数 train_from_pretrained_model(可选):这用于通过指定预训练 YOLOv3 模型的路径来执行迁移学习

    当您运行训练代码时,ImageAI将执行以下操作:

    • dataset_folder/json文件夹中生成detection_config.json 。请注意,训练中生成的JSON文件只能与训练中保存的检测模型一起使用。
    • 将训练的Tensorboard报告保存在hololens/logs文件夹中。
    • 随着训练损失的减少,将新模型保存在hololens/models文件夹中。
    Using TensorFlow backend.
    Generating anchor boxes for training images and annotation...
    Average IOU for 9 anchors: 0.78
    Anchor Boxes generated.
    Detection configuration saved in  hololens/json/detection_config.json
    Training on:        ['hololens']
    Training with Batch Size:  4
    Number of Experiments:  200
    
    Epoch 1/200
    480/480 [==============================] - 395s 823ms/step - loss: 36.9000 - yolo_layer_1_loss: 3.2970 - yolo_layer_2_loss: 9.4923 - yolo_layer_3_loss: 24.1107 - val_loss: 15.6321 - val_yolo_layer_1_loss: 2.0275 - val_yolo_layer_2_loss: 6.4191 - val_yolo_layer_3_loss: 7.1856
    Epoch 2/200
    480/480 [==============================] - 293s 610ms/step - loss: 11.9330 - yolo_layer_1_loss: 1.3968 - yolo_layer_2_loss: 4.2894 - yolo_layer_3_loss: 6.2468 - val_loss: 7.9868 - val_yolo_layer_1_loss: 1.7054 - val_yolo_layer_2_loss: 2.9156 - val_yolo_layer_3_loss: 3.3657
    Epoch 3/200
    480/480 [==============================] - 293s 610ms/step - loss: 7.1228 - yolo_layer_1_loss: 1.0583 - yolo_layer_2_loss: 2.2863 - yolo_layer_3_loss: 3.7782 - val_loss: 6.4964 - val_yolo_layer_1_loss: 1.1391 - val_yolo_layer_2_loss: 2.2058 - val_yolo_layer_3_loss: 3.1514
    Epoch 4/200
    480/480 [==============================] - 297s 618ms/step - loss: 5.5802 - yolo_layer_1_loss: 0.9742 - yolo_layer_2_loss: 1.8916 - yolo_layer_3_loss: 2.7144 - val_loss: 6.4275 - val_yolo_layer_1_loss: 1.6153 - val_yolo_layer_2_loss: 2.1203 - val_yolo_layer_3_loss: 2.6919
    Epoch 5/200
    480/480 [==============================] - 295s 615ms/step - loss: 4.8717 - yolo_layer_1_loss: 0.7568 - yolo_layer_2_loss: 1.6641 - yolo_layer_3_loss: 2.4508 - val_loss: 6.3723 - val_yolo_layer_1_loss: 1.6434 - val_yolo_layer_2_loss: 2.1188 - val_yolo_layer_3_loss: 2.6101
    Epoch 6/200
    480/480 [==============================] - 300s 624ms/step - loss: 4.7989 - yolo_layer_1_loss: 0.8708 - yolo_layer_2_loss: 1.6683 - yolo_layer_3_loss: 2.2598 - val_loss: 5.8672 - val_yolo_layer_1_loss: 1.2349 - val_yolo_layer_2_loss: 2.0504 - val_yolo_layer_3_loss: 2.5820
    Epoch 7/200
    

    4. 评估模型

    训练完成后,您可以评估已保存模型的mAP分数,以选择结果最准确的模型。

    为此,只需运行以下代码:

    from imageai.Detection.Custom import DetectionModelTrainer
    
    trainer = DetectionModelTrainer()
    trainer.setModelTypeAsYOLOv3()
    trainer.setDataDirectory(data_directory="hololens")
    metrics = trainer.evaluateModel(model_path="hololens/models", json_path="hololens/json/detection_config.json", iou_threshold=0.5, object_threshold=0.3, nms_threshold=0.5)
    print(metrics)
    

    上面的代码与我们的训练代码类似,除了我们调用evaluateModel()函数的那一行。请参阅以下功能的详细信息。

    • .trainer.evaluateModel(),此函数允许您根据 IoU 和置信度分数等标准计算并获取保存模型mAP

      trainer.evaluateModel()
      

    参数 model_path(必需):这可以是单个模型的路径,也可以是包含已保存模型的文件夹

    参数 json_path(必需):这是在保存模型的训练期间生成的detection_config.json 。

    参数 iou_threshold (可选):用于为mAP评估设置所需的Intersection over Union 。

    参数 object_threshold(可选):用于设置mAP评估的最小置信度分数。

    参数 nms_threshold(可选):用于设置mAP评估的最小非最大抑制值。

    当你运行上面的代码时,你会得到类似于下面的结果:

    [{
        'average_precision': {'hololens': 0.9231334437735249},
        'map': 0.9231334437735249,
        'model_file': 'hololens/models/detection_model-ex-07--loss-4.42.h5',
        'using_iou': 0.5,
        'using_non_maximum_suppression': 0.5,
        'using_object_threshold': 0.3
    },
    {
        'average_precision': {'hololens': 0.9725334437735249},
        'map': 0.97251334437735249,
        'model_file': 'hololens/models/detection_model-ex-10--loss-3.95.h5',
        'using_iou': 0.5,
        'using_non_maximum_suppression': 0.5,
        'using_object_threshold': 0.3
    },
    {
        'average_precision': {'hololens': 0.92041334437735249},
        'map': 0.92041334437735249,
        'model_file': 'hololens/models/detection_model-ex-05--loss-5.26.h5',
        'using_iou': 0.5,
        'using_non_maximum_suppression': 0.5,
        'using_object_threshold': 0.3
    },
    {
        'average_precision': {'hololens': 0.81201334437735249},
        'map': 0.81201334437735249,
        'model_file': 'hololens/models/detection_model-ex-03--loss-6.44.h5',
        'using_iou': 0.5,
        'using_non_maximum_suppression': 0.5,
        'using_object_threshold': 0.3
    },
    {
        'average_precision': {'hololens': 0.94311334437735249},
        'map': 0.94311334437735249,
        'model_file': 'hololens/models/detection_model-ex-18--loss-2.96.h5',
        'using_iou': 0.5,
        'using_non_maximum_suppression': 0.5,
        'using_object_threshold': 0.3
    },
    {
        'average_precision': {'hololens': 0.94041334437735249},
        'map': 0.94041334437735249,
        'model_file': 'hololens/models/detection_model-ex-17--loss-3.10.h5',
        'using_iou': 0.5,
        'using_non_maximum_suppression': 0.5,
        'using_object_threshold': 0.3
    },
    {
        'average_precision': {'hololens': 0.97251334437735249},
        'map': 0.97251334437735249,
        'model_file': 'hololens/models/detection_model-ex-08--loss-4.16.h5',
        'using_iou': 0.5,
        'using_non_maximum_suppression': 0.5,
        'using_object_threshold': 0.3
    }
    ]
    

    5. 检测图像中的自定义对象

    ======= imageai.Detection.Custom.CustomObjectDetection =======

    CustomObjectDetection类提供了非常方便和强大的方法来对图像进行对象检测,并使用您自己的自定义****YOLOv3 模型和训练期间生成的相应detection_config.json从图像中提取每个对象。

    现在我们已经训练了自定义模型来检测Hololens头具,我们将使用已保存的最优模型以及生成的用于检测图像中对象的detection_config.json文件。

    • 让我们以上面的示例图像来测试我们训练的定制hololens检测模型。

    • 我们提供了已经训练的Hololens检测模型供您测试。通过下面的链接下载模型和相应的detection_config.json文件。

    https://github.com/OlafenwaMoses/ImageAI/releases/download/essential-v4/hololens-ex-60--loss-2.76.h5

    https://github.com/OlafenwaMoses/ImageAI/releases/download/essential-v4/detection_config.json

    img

    下载自定义对象检测模型文件后,应将模型文件复制到.py文件所在的项目文件夹中。然后创建一个python文件并给它一个名字;一个例子是FirstCustomDetection.py。然后将以下代码写入python文件:

    from imageai.Detection.Custom import CustomObjectDetection
    
    detector = CustomObjectDetection()
    detector.setModelTypeAsYOLOv3()
    detector.setModelPath("hololens-ex-60--loss-2.76.h5")
    detector.setJsonPath("detection_config.json")
    detector.loadModel()
    detections = detector.detectObjectsFromImage(input_image="holo1.jpg", output_image_path="holo1-detected.jpg")
    for detection in detections:
        print(detection["name"], " : ", detection["percentage_probability"], " : ", detection["box_points"])
    

    当您运行代码时,它将产生类似于以下的结果:

    hololens  :  39.69653248786926  :  [611, 74, 751, 154]
    hololens  :  87.6643180847168  :  [23, 46, 90, 79]
    hololens  :  89.25175070762634  :  [191, 66, 243, 95]
    hololens  :  64.49641585350037  :  [437, 81, 514, 133]
    hololens  :  91.78624749183655  :  [380, 113, 423, 138]
    
    img

    请参阅下面的更多详细信息:

    • .setModelTypeAsYOLOv3(),这表明您正在使用经过训练的 YOLOv3 模型

      detector.setModelTypeAsYOLOv3()
      
    • .setModelPath(),用于设置训练模型的文件路径

      detector.setModelPath()
      

    参数 detection_model_path(必需):这是模型文件的路径

    • .setJsonPath(),用于设置配置 json 文件的文件路径

      detector.setJsonPath()
      

    参数 configuration_json(必需):这是detection_json文件的路径

    • .loadModel(),这是加载检测模型:

      detector.loadModel()
      
    • .detectObjectsFromImage(),这是在加载模型后执行对象检测任务的函数。可以多次调用它来检测任意数量图像中的对象。在下面找到示例代码:

      detections = detector.detectObjectsFromImage(input_image="image.jpg", output_image_path="imagenew.jpg", minimum_percentage_probability=30)
      

    参数 input_image(必需):这是指您要检测的图像文件的路径。如果将参数input_type设置为“array”或“stream” ,则可以将此参数设置为任何图像的 File 流的 Numpy 数组

    参数 output_image_path(仅当input_type = “file” 时才需要):这是指将保存检测到的图像的文件路径。仅当input_type = “file”时才需要

    参数 minimum_percentage_probability(可选):该参数用于确定检测结果的完整性。降低该值可显示更多对象,而增加该值可确保检测到具有最高准确度的对象。默认值为 50。

    参数 output_type(可选):此参数用于设置检测图像的生成格式。可用的值为“文件”和“数组”。默认值为“文件”。如果此参数设置为“array”,该函数将返回检测到的图像的 Numpy 数组。请参阅下面的示例::

    returned_image, detections = detector.detectObjectsFromImage(input_image=”image.jpg”, output_type=”array”, minimum_percentage_probability=30)
    

    参数 display_percentage_probability(可选):如果设置为 False,此参数可用于隐藏检测到的图像中检测到的每个对象的百分比概率。默认值为 True。

    参数 display_object_name(可选):如果设置为 False,此参数可用于隐藏检测到的图像中检测到的每个对象的名称。默认值为 True。

    参数 extract_detected_objects(可选):此参数可用于提取和保存/返回图像中检测到的每个对象作为单独的图像。默认值为假。

    参数 thread_safe(可选):如果设置为 true,则可确保加载的检测模型在所有线程中工作。

    返回:返回值将取决于解析到detectObjectsFromImage()函数中的参数。请参阅下面的注释和代码

    5.1 图像的文件路径

    如果设置了所有必需的参数并且 'output_image_path' 设置为您希望保存检测到的图像的文件路径,该函数将返回:

    如果设置了所有必需的参数并且 'output_image_path' 设置为您希望保存检测到的图像的文件路径,该函数将返回:

      • 字典数组,每个字典对应于对象

        在图像中检测到。每个字典都包含以下属性:

        • 名称(字符串)
        • 百分比概率(浮点数)
        • box_points(x1、y1、x2 和 y2 坐标列表)
    detections = detector.detectObjectsFromImage(input_image=”image.jpg”, output_image_path=”imagenew.jpg”, minimum_percentage_probability=30)
    

    5.2 图像的文件-array

    如果设置了所有必需的参数并且 output_type = 'array' ,该函数将返回

    1. 检测到的图像的 numpy 数组

      • 字典数组,每个字典对应于对象

        在图像中检测到。每个字典都包含以下属性:

        • 名称(字符串)

        • 百分比概率(浮点数)

        • box_points(x1、y1、x2 和 y2 坐标列表)

    returned_image, detections = detector.detectObjectsFromImage(input_image=”image.jpg”, output_type=”array”, minimum_percentage_probability=30)
    

    5.3 图像的文件路径-单独的图像

    如果 extract_detected_objects = True 并且 'output_image_path' 设置为您想要的文件路径

    检测到要保存的图像,该函数将返回:

    1. 字典数组,每个字典对应于对象

    在图像中检测到。每个字典都包含以下属性:

    • 名称(字符串)

    • 百分比概率(浮点数)

    • box_points(x1、y1、x2 和 y2 坐标列表)

    1. 从图像中提取的每个对象的图像的字符串路径数组
    detections, extracted_objects = detector.detectObjectsFromImage(input_image=”image.jpg”, output_image_path=”imagenew.jpg”, extract_detected_objects=True, minimum_percentage_probability=30)
    

    5.4 图像的文件-array-单独的图像

    如果 extract_detected_objects = True 且 output_type = 'array',该函数将返回:

    1. 检测到的图像的 numpy 数组

      • 字典数组,每个字典对应于对象

        在图像中检测到。每个字典包含以下属性:

        • name (string)
        • percent_probability (float)
        • box_points (x1,y1,x2 和 y2 坐标列表)
    2. 图像中检测到的每个对象的 numpy 数组

    returned_image, detections, extracted_objects = detector.detectObjectsFromImage(input_image=”image.jpg”, output_type=”array”, extract_detected_objects=True, minimum_percentage_probability=30)
    

    6. 对视频进行对象检测

    ======= imageai.Detection.Custom.CustomVideoObjectDetection =======

    CustomVideoObjectDetection类提供了非常方便和强大的方法来对视频进行对象检测并从视频中获取分析,使用您自己的自定义YOLOv3 模型和训练期间生成的相应detection_config.json

    要测试自定义对象检测,您可以通过以下链接下载我们已训练用于检测 Hololens 耳机及其detection_config.json文件的示例自定义模型:

    Hololens检测模型

    detection_config.json

    在下面的链接中下载 Hololens 的示例视频。

    Hololens 视频示例

    然后在视频中运行下面的代码:

    from imageai.Detection.Custom import CustomVideoObjectDetection
    import os
    
    execution_path = os.getcwd()
    
    video_detector = CustomVideoObjectDetection()
    video_detector.setModelTypeAsYOLOv3()
    video_detector.setModelPath("hololens-ex-60--loss-2.76.h5")
    video_detector.setJsonPath("detection_config.json")
    video_detector.loadModel()
    
    video_detector.detectObjectsFromVideo(input_file_path="holo1.mp4",
                                            output_file_path=os.path.join(execution_path, "holo1-detected"),
                                            frames_per_second=30,
                                            minimum_percentage_probability=40,
                                            log_progress=True)
    

    请参阅以下可用功能的详细信息

    • .setModelTypeAsYOLOv3(),这表明您正在使用经过训练的 YOLOv3 模型

      video_detector.setModelTypeAsYOLOv3()
      
    • .setModelPath(),用于设置训练模型的文件路径

      video_detector.setModelPath()
      

    参数 detection_model_path(必需):这是模型文件的路径

    • .setJsonPath(),用于设置配置 json 文件的文件路径

      video_detector.setJsonPath()
      

    参数 configuration_json(必需):这是detection_json文件的路径

    • .loadModel(),这是加载检测模型:

      video_detector.loadModel()
      
    • .detectObjectsFromVideo(),这是在模型加载到您创建的实例后对视频文件或视频直播进行对象检测的函数。在下面找到完整的示例代码:

    参数 input_file_path(如果您没有设置camera_input则需要):这是指您要检测的视频文件的路径。

    参数 output_file_path(如果您没有设置save_detected_video = False,则需要):这是指将保存检测到的视频的路径。默认情况下,此功能保存视频 .avi格式。

    参数 frames_per_second(可选,但推荐):此参数允许您为将保存的检测到的视频设置所需的每秒帧数。默认值为 20,但我们建议您设置适合您的视频或摄像机实时源的值。

    参数 log_progress(可选):将此参数设置为 True 会显示在 CLI 中检测到的视频或实时源的进度。它将报告检测到的每一帧。默认值为假。

    参数 return_detected_frame(可选):此参数允许您在检测到的视频的每一帧、秒和分钟将检测到的帧作为 Numpy 数组返回。返回的 Numpy 数组将被解析为各自的per_frame_functionper_second_functionper_minute_function(详见下文)

    参数 camera_input (可选):如果您想检测摄像机实时馈送中的对象,可以设置此参数来替换input_file_path 。您只需要使用 OpenCV 的VideoCapture()函数加载相机并将对象解析为该参数即可。

    参数 minimum_percentage_probability(可选):该参数用于确定检测结果的完整性。降低该值可显示更多对象,而增加该值可确保检测到具有最高准确度的对象。默认值为 50。

    参数 display_percentage_probability(可选):如果设置为 False,此参数可用于隐藏检测到的视频中检测到的每个对象的百分比概率。默认值为 True。

    参数 display_object_name(可选):如果设置为 False,此参数可用于隐藏检测到的视频中检测到的每个对象的名称。默认值为 True。

    参数 save_detected_video(可选):此参数可用于保存或不保存检测到的视频或不保存。默认设置为 True。

    参数 per_frame_function(可选):此参数允许您解析您定义的函数的名称。然后,对于检测到的每一帧视频,该函数将被解析为将执行的参数,并将视频的分析数据解析为该函数。返回的数据可以可视化或保存在 NoSQL 数据库中,以供将来处理和可视化。

    特殊函数

    请参阅下面此参数的示例函数:

    “”” 此参数允许您解析在检测到视频的每一帧后要执行的函数。如果将此参数设置为函数,则在检测到每个视频帧后,将执行该函数并解析以下值: – 帧的位置编号 – 字典数组,每个字典对应于检测到的每个对象。

    每个字典包含'name'、'percentage_probability'和'box_points'

    • – 一个字典,其中键是每个唯一对象和值的名称

      是存在的每个对象的实例数

    • – 如果 return_detected_frame 设置为 True,则将解析检测到的帧的 numpy 数组

      作为函数的第四个值

    def forFrame(frame_number, output_array, output_count):
        print(“FOR FRAME ” , frame_number) 
        print(“Output for each object : “, output_array) 
        print(“Output count for unique objects : “, output_count) print(”————END OF A FRAME ————–“)
    

    参数 per_second_function(可选):此参数允许您以您定义的函数的名称进行解析。然后,对于检测到的每一秒的视频,该函数将被解析为将执行的参数,并将视频的分析数据解析为该函数。返回的数据可以可视化或保存在 NoSQL 数据库中,以供将来处理和可视化。

    请参阅下面此参数的示例函数:

    “”” 此参数允许您在检测到视频的每一秒后解析一个您想要执行的函数。如果将此参数设置为函数,则在检测到视频的每一秒后,将执行该函数并解析以下值: – 秒的位置编号 – 字典数组,其键为每帧的位置编号存在于最后一秒,每个键的值是每个帧的数组,其中包含帧中检测到的每个对象的字典

    • 一个字典数组,每个字典对应过去一秒的每一帧,每个字典的key是每一帧中检测到的唯一对象的数量的名称,key值是对象的实例数在框架中找到

    • 一个字典,其键是在过去一秒内检测到的每个唯一对象的名称,键值是在过去一秒内包含的所有帧中找到的对象实例的平均数

    • 如果 return_detected_frame 设置为 True,则检测到的帧的 numpy 数组将作为第五个值解析到函数“””中

    def forSeconds(second_number, output_arrays, count_arrays, average_output_count):
        print(“SECOND : “, second_number) 
        print(“Array for the outputs of each frame “, output_arrays) 
        print(“Array for output count for unique objects in each frame : “, count_arrays)       print(“Output average count for unique objects in the last second: “, average_output_count) print(”————END OF A SECOND ————–“)
    

    参数 per_minute_function(可选):此参数允许您解析您定义的函数的名称。然后,对于检测到的每一帧视频,都会执行解析成参数的函数,并将视频的解析数据解析成函数。返回的数据与per_second_function具有相同的性质;不同之处在于它涵盖了视频过去 1 分钟内的所有帧。

    请参阅下面此参数的示例函数:
    
    def forMinute(minute_number, output_arrays, count_arrays, average_output_count):
        print("MINUTE : ", minute_number)
        print("Array for the outputs of each frame ", output_arrays)
        print("Array for output count for unique objects in each frame : ", count_arrays)
        print("Output average count for unique objects in the last minute: ", average_output_count)
        print("------------END OF A MINUTE --------------")
    

    参数 video_complete_function(可选):此参数允许您解析您定义的函数的名称。一旦完全检测到视频中的所有帧,该函数将被解析为将执行的参数,并将视频的分析数据解析为该函数。返回的数据与per_second_functionper_minute_function具有相同的性质;不同之处在于不会返回任何索引,它涵盖了整个视频中的所有帧。

    请参阅下面此参数的示例函数:

    def forFull(output_arrays, count_arrays, average_output_count):
        print("Array for the outputs of each frame ", output_arrays)
        print("Array for output count for unique objects in each frame : ", count_arrays)
        print("Output average count for unique objects in the entire video: ", average_output_count)
        print("------------END OF THE VIDEO --------------")
    

    参数 detection_timeout(可选):此函数允许您说明应该检测到的视频的秒数,在该秒数之后检测函数停止处理视频。

    相关文章

      网友评论

          本文标题:训练和推理对象检测模型

          本文链接:https://www.haomeiwen.com/subject/tnxshrtx.html