一,环境安装
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
版权声明:本文为CSDN博主「AI小白龙」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/qq_34106574/article/details/118906909
暂无评论