【目标检测】Nanodet使用笔记

一,环境安装


1. Create a conda virtual environment and then activate it.

```shell script
 conda create -n nanodet python=3.8 -y
 conda activate nanodet
```

2. Install pytorch

```shell script
conda install pytorch torchvision cudatoolkit=11.0 -c pytorch
```

3. Install requirements

```shell script
pip install Cython termcolor numpy tensorboard pycocotools matplotlib pyaml opencv-python tqdm
```

4. Setup NanoDet

```shell script
git clone https://github.com/RangiLyu/nanodet.git
cd nanodet
python setup.py develop

二,网络训练


1. **Prepare dataset** 准备数据

    If your dataset annotations are pascal voc xml format, refer to [config/nanodet_custom_xml_dataset.yml](config/nanodet_custom_xml_dataset.yml)

  使用 xml2json.py  脚本,将xml 转换成json
  Or convert your dataset annotations to MS COCO format[(COCO annotation format details)](https://cocodataset.org/#format-data).

2. **Prepare config file** 修改配置文件

    Copy and modify an example yml config file in config/ folder.

    Change ***save_path*** to where you want to save model.

    Change ***num_classes*** in ***model->arch->head***.

    Change image path and annotation path in both ***data->train   data->val***.

    Set gpu, workers and batch size in ***device*** to fit your device.

    Set ***total_epochs***, ***lr*** and ***lr_schedule*** according to your dataset and batchsize.

3. **Start training** 训练

    For single GPU, run

    ```shell script
    python tools/train.py CONFIG_PATH
    ```

    For multi-GPU, NanoDet using distributed training. (Notice: Windows not support distributed training before pytorch1.7) Please run

    ```shell script
    python -m torch.distributed.launch --nproc_per_node=GPU_NUM --master_port 29501 tools/train.py CONFIG_PATH
    ```

4. **Visualize Logs** 可视化训练

    TensorBoard logs are saved in `save_dir` which you set in config file.

    To visualize tensorboard logs, run:

    ```shell script
    cd <YOUR_SAVE_DIR>
    tensorboard --logdir ./logs
5,数据批量测试
python demo.py  --config ./config/EfficientNet-Lite/nanodet-EfficientNet-Lite2_512.yml --model ./workspace_hand_efficientlite2_512/efficientlite2_512/model_best/model_best.pth --path ./S_test --savepath ./S_det

三,生成部署文件


1. pth 转化为ONNX
python tools/export.py --cfg_path /config/EfficientNet-Lite/nanodet-EfficientNet-Lite1_416.yml --model_path  /model_best/model_best.pth --out_path model_test.onnx --input_shape 416,416

2,ONNX转化NCNN
(1)编译ncnn参考   https://blog.csdn.net/weixin_40970506/article/details/105148061
(2)安装onnx==1.8.1
(3)cd onnx-simplifier-master
python -m onnxsim  /nanodet/nanodet-main/tools/model_test.onnx nanodet_sim.onnx
(4)转换成bin
cd  /ncnn-master/build/tools/onnx
./onnx2ncnn /onnx-simplifier-master/nanodet_sim.onnx nanodet_m.param nanodet_m.bin

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Arthur.AI

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值