Alex Blog

[Hailo Model Zoo]如何利用Hailo Model Zoo 创建独立运行的其他模型脚本

如何使用 Hailo Model Zoo 创建独立运行的其他模型

1. 介绍

本文将介绍如何使用 Hailo Model Zoo 示例创建独立版本的模型。

2. 步骤

首先:

本过程基于我们的 Hailo Model Zoo, 所以你的模型必须是我们Hailo Model Zoo 支持的模型, 和实例分割的sample code。并且此方法仅适用于 Python 版本。

其次:

您可以使用 `hailomz eval` 来检查你希望支持的模型输出效果是否符合预期。例如(以yolov8s_pose为例):

hailomz eval yolov8s_pose --target hailo8 --hef yolov8s_pose.hef --data-path test_pose --visualize

您可以通过输入 `hailomz eval –help` 查看更多使用说明。

第三:

由于不同的模型评估具有不同的后处理功能和关键字参数,您需要了解目标模型的详细信息。您可以在文件 `hailo_model_zoo/core/postprocessing/postprocessing_factory.py` 中打印所有关键字参数:

def print_kwargs(**kwargs):
    for key, value in kwargs.items():
        print(f"{key}: {value}")

def postprocessing_fn(endnodes, device_pre_post_layers=None, **kwargs):
    print_kwargs(**kwargs)
    return postprocessing_fn_map[name](endnodes, device_pre_post_layers, **kwargs)

此将打印所有关键字参数,您需要用到这些参数来设置您自己的目标关键字参数。

您还可以通过 `postprocessing_fn_map` 和 `visualization_fn_map` 找到您的后处理和可视化函数,以帮助定位您的后处理文件。
例如:

from hailo_model_zoo.core.postprocessing.pose_estimation_postprocessing 
     import (pose_estimation_postprocessing, visualize_pose_estimation_result)

第四:

您可以使用与实例分割类似的方法创建自己版本的后处理。如果它依赖于一些hailo model zoo的函数,只需将其复制出来即可。记得预先设置上一步获取的关键字参数值。
例如(yolov8_pose):

arch_dict = {'v8': {'anchors':
                 {'scale_factors': [0.5, 0.5],
                  'sizes': [[10, 13, 16, 30, 33, 23], [30, 61, 62, 45, 59, 119], [116, 90, 156, 198, 373, 326]],
                  'type': 'default',
                  'strides': [8, 16, 32],
                  'regression_length': 15}
                 }
            }
arch_list = arch_dict.keys()
num_of_classes = args.class_num
kwargs['meta_arch'] = 'nanodet_v8'
anchors = arch_dict['v8']
kwargs['anchors'] = arch_dict['v8']['anchors']
kwargs['score_threshold'] = 0.001
kwargs['nms_iou_thresh'] = 0.7
kwargs['dataset_name'] = 'cocopose'
kwargs['nms_max_output_per_class'] = 300

def postproc_yolov8pose(raw_detections):
    raw_detections_keys = list(raw_detections.keys())
    layer_from_shape: dict = {raw_detections[key].shape:key for key in raw_detections_keys}
    pose_channels = 51
    detection_output_channels = (kwargs['anchors']['regression_length'] + 1) * 4 # (regression length + 1) * num_coordinates
    endnodes = [raw_detections[layer_from_shape[1, 20, 20, detection_output_channels]],
                raw_detections[layer_from_shape[1, 20, 20, kwargs['classes']]],
                raw_detections[layer_from_shape[1, 20, 20, pose_channels]],
                raw_detections[layer_from_shape[1, 40, 40, detection_output_channels]],
                raw_detections[layer_from_shape[1, 40, 40, kwargs['classes']]],
                raw_detections[layer_from_shape[1, 40, 40, pose_channels]],
                raw_detections[layer_from_shape[1, 80, 80, detection_output_channels]],
                raw_detections[layer_from_shape[1, 80, 80, kwargs['classes']]],
                raw_detections[layer_from_shape[1, 80, 80, pose_channels]]]
    predictions_dict = pose_estimation_postprocessing(endnodes, **kwargs)
    return predictions_dict

 


已发布

分类

,

来自

标签:

评论

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注