用opencv部署nanodet目标检测,包含C++和python两种版本程序的实现

Overview

nanodet-opncv-dnn-cpp-python

用opencv部署nanodet目标检测,包含C++和python两种版本程序的实现, 使用opencv里的dnn模块加载网络模型,图像预处理和后处理模块是使用C++和python编程实现。 整个程序运行,不依赖任何深度学习框架, 在windows系统和ubuntu系统,在cpu和gpu机器上都能运行。

python版本的主程序是main_nanodet.py, c++版本的主程序是main.cpp

程序里提供输入图片尺寸320和416这两种选择,类别置信度阈值confThreshold,nms重叠率阈值nmsThreshold可自行调整

You might also like...
Comments
  • About NanoDet model config file

    About NanoDet model config file

    Hi, Can you release your training model config file for reference? Because I use netron check my model is only one output. But your excellent model have six output. Have you done any other processing on the model? Following text is my training config file.

    # nanodet-EfficientNet-Lite1_416
    save_dir: workspace/RepVGG-A0-416
    model:
      arch:
        name: OneStageDetector
        backbone:
          name: RepVGG
          arch: A0
          out_stages: [2,3,4]
          activation: ReLU
          last_channel: 512
          deploy: False
        fpn:
          name: PAN
          in_channels: [96, 192, 512]
          out_channels: 128
          start_level: 0
          num_outs: 3
        head:
          name: NanoDetHead
          num_classes: 1
          conv_type: Conv
          input_channel: 128
          feat_channels: 128
          stacked_convs: 2
          activation: ReLU
          share_cls_reg: True
          octave_base_scale: 8
          scales_per_octave: 1
          strides: [8, 16, 32]
          reg_max: 10
          norm_cfg:
            type: BN
          loss:
            loss_qfl:
              name: QualityFocalLoss
              use_sigmoid: True
              beta: 2.0
              loss_weight: 1.0
            loss_dfl:
              name: DistributionFocalLoss
              loss_weight: 0.25
            loss_bbox:
              name: GIoULoss
              loss_weight: 2.0
    data:
      train:
        name: CocoDataset
        img_path: /nfs/Workspace/dataset/mscoco/images/train2017
        ann_path: /nfs/Workspace/dataset/mscoco/annotations/annotations/instances_train2017_person.json
        input_size: [416,416] #[w,h]
        keep_ratio: True
        pipeline:
          perspective: 0.0
          scale: [0.5, 1.5]
          stretch: [[1, 1], [1, 1]]
          rotation: 0
          shear: 0
          translate: 0.2
          flip: 0.5
          brightness: 0.2
          contrast: [0.6, 1.4]
          saturation: [0.5, 1.2]
          normalize: [[103.53, 116.28, 123.675], [57.375, 57.12, 58.395]]
      val:
        name: CocoDataset
        img_path: /nfs/Workspace/dataset/mscoco/images/val2017
        ann_path: /nfs/Workspace/dataset/mscoco/annotations/annotations/instances_val2017_person.json
        input_size: [416,416] #[w,h]
        keep_ratio: True
        pipeline:
          normalize: [[103.53, 116.28, 123.675], [57.375, 57.12, 58.395]]
    device:
      gpu_ids: [0]
      workers_per_gpu: 1
      batchsize_per_gpu: 100
    schedule:
    #  resume:
    #  load_model: YOUR_MODEL_PATH
      optimizer:
        name: SGD
        lr: 0.07
        momentum: 0.9
        weight_decay: 0.0001
      warmup:
        name: linear
        steps: 500
        ratio: 0.01
      total_epochs: 170
      lr_schedule:
        name: MultiStepLR
        milestones: [130,150,160,165]
        gamma: 0.1
      val_intervals: 5
    evaluator:
      name: CocoDetectionEvaluator
      save_key: mAP
    
    log:
      interval: 10
    
    class_names: ['person']
    

    And this is my model architecture output mine

    Here is the model architecture output you provided nanodet_ros

    Please help! Thanks a lot!

    opened by Wei0703 0
  • when i use cv2.dnn.readNet() to read the onnx model, i have a question

    when i use cv2.dnn.readNet() to read the onnx model, i have a question

    when i use cv2.dnn.readNet() to read the onnx model, i have a question (expected: 'shapes.depth() == CV_32S') where 'shapes.depth()' is 5(CV_32FC1) must be equal to 'CV_32S' is 4(CV_32SC1) in void_cdecl cv::dnn::dnn4_v20200609::ONNXImporter::populateNet(class cv::dnn::dnn4_v20200609::Net), file D:\opencv_test\newbuild\opencv-master\modules\dnn\src\onnx\innx_importer.cpp, line 1442

    opened by zhanght021 4
  • error about cpp code

    error about cpp code

    [ INFO:0] global C:\jenkins\workspace\OpenCV\OpenVINO\2021.2\build\windows\opencv\modules\dnn\src\onnx\onnx_importer.cpp (395) cv::dnn::dnn4_v20201117::ONNXImporter::populateNet DNN/ONNX: loading ONNX v6 model produced by 'pytorch':1.7. Number of nodes = 335, inputs = 1, outputs = 6

    opened by czyczyczy 1
Owner
深度学习算法工程师
null
使用ONNXRuntime部署anchor-free系列的YOLOR,包含C++和Python两种版本的程序

yolor-onnxruntime 使用ONNXRuntime部署anchor-free系列的YOLOR,包含C++和Python两种版本的程序 YOLOR是一个anchor-free系列的YOLO目标检测,不需要anchor作为先验。本套程序参考了YOLOR的 官方程序(https://githu

null 38 Dec 6, 2022
使用OpenCV部署YOLOX,支持YOLOX-S、YOLOX-M、YOLOX-L、YOLOX-X、YOLOX-Darknet53五种结构,包含C++和Python两种版本的程序

yolox-opencv-dnn 使用OpenCV部署YOLOX,支持YOLOX-S、YOLOX-M、YOLOX-L、YOLOX-X、YOLOX-Darknet53五种结构,包含C++和Python两种版本的程序 onnx文件在百度云盘,下载链接:https://pan.baidu.com/s/11

null 140 Jan 4, 2023
使用ONNXRuntime部署anchor-free系列的YOLOR,包含C++和Python两种版本的程序

yolor-onnxruntime 使用ONNXRuntime部署anchor-free系列的YOLOR,包含C++和Python两种版本的程序 YOLOR是一个anchor-free系列的YOLO目标检测,不需要anchor作为先验。本套程序参考了YOLOR的 官方程序(https://githu

null 38 Dec 6, 2022