当前位置:网站首页>Configure MMdetection environment and train
Configure MMdetection environment and train
2022-07-30 07:08:00 【Amber Bright】
配置MMdetection环境(以VFNet为例)
It is recommended to use the official website method first,链接放在下面了!
https://github.com/open-mmlab/mmdetection/blob/master/docs/get_started.md

1、先创建一个conda环境并激活它
conda create -n open-mmlab python=3.7 -y
conda activate open-mmlab
2、安装PyTorch 和 torchvision,
根据cuda和pytorch版本安装(我的版本是cuda11.0和torch1.7.0)
conda install pytorch torchvision -c pytorch
conda install pytorch cudatoolkit=11.0 torchvision -c pytorch
3、安装mmcv-full
根据cuda和pytorch版本安装(我的版本是cuda11.0和torch1.7.0).mmcvIf the version configuration is incorrect, the model cannot be trained normally,Be sure to use the correct version.
pip install mmcv-full -f https://download.openmmlab.com/mmcv/dist/cu110/torch1.7.0/index.html
4、安装pycocotools
Although the official website does not require installation,But I am getting error missingpycocotools.
pip install git+https://github.com/philferriere/cocoapi.git#subdirectory=PythonAPI
或者https://github.com/philferriere/cocoapi下载源码,并进行解压.切换到 cocoapi\PythonAPI目录.运行:
python setup.py build_ext install
然后cdto your own path,安装mmdetection
5、mmdetection安装和编译
git clone https://github.com/open-mmlab/mmdetection.git
cd mmdetection
pip install -r requirements/build.txt
pip install -v -e. # or "python setup.py develop".
到这里为止,环境的配置就完成了.Start preparing the dataset
6、使用自己的coco格式数据集
All officially provided code is used by defaultcoco格式的数据集,I also use it herecoco格式的数据集.Various types of data transfercocoSee format script:
https://github.com/spytensor/prepare_detection_dataset
mmdetection
├── mmdet
├── tools
├── configs
├── data
│ ├── coco
│ │ ├── annotations
│ │ ├── train2017
│ │ ├── val2017
│ │ ├── test2017
7、Some parameters need to be changed before training
1)定义数据种类,The place that needs to be modified is heremmdetection/mmdet/datasets/coco.py.把CLASSES的那个tuple改为自己数据集对应的种类tuple即可.
CLASSES = ('liner', 'bulk carrier', 'container ship', 'other ship')
2)接着在mmdetection/mmdet/core/evaluation/class_names.py修改coco_classes数据集类别,This is related to the backtestThe category name displayed in the resulting graph when
3)修改configs/vfnet/vfnet_x101_64x4d_fpn_mstrain_2x_coco.py中的model字典中的num_classes、data字典中的img_scale和optimizer中的lr(学习率).例如:
num_classes=4,#类别数
optimizer = dict(type='SGD', lr=0.0025, momentum=0.9, weight_decay=0.0001)
当gpu数量为8时,lr=0.02;当gpu数量为4时,lr=0.01;我只要一个gpu,所以设置lr=0.0025
训练完之后work_dirs文件夹中会保存下训练过程中的log日志文件、每个epoch的pth文件(这个文件将会用于后面的test测试)
8、开始训练
单个GPU(Not distributed):
#Train the model from the start
python tools/train.py configs/vfnet/vfnet_x101_64x4d_fpn_mstrain_2x_coco.py
#Continue training from the breakpoint weights file
python tools/train.py configs/vfnet/vfnet_x101_64x4d_fpn_mstrain_2x_coco.py --resume-from="work_dirs/yy.pth"
resume_from和load_from之间的区别: resume_from加载模型权重和优化器状态,并且epoch也从指定的检查点继承.它通常用于恢复意外中断的训练过程. load_from仅加载模型权重,训练时期从0开始.通常用于微调.
9、测试
(1)If you just want to see the effect and don't do quantitative indicator analysis,Can run the previous onedemo.py文件,But change itcheckpoint_file的地址路径,Use what we ran out of the previous stepwork_dirs下的pth文件.例如checkpoint_file = 'work_dirs/epoch_100.pth
(2)使用testcommand to perform a test to evaluate some parameters
python tools/test.py configs/vfnet/vfnet_x101_64x4d_fpn_mstrain_2x_coco.py work_dirs/latest.pth --out ./result/result_100.pkl --eval bbox
Put a picture of the result of my training(The dataset used is its own,single class 2万多张)
VFNet X-101-64x4d (mAP 91.7%)
10、报错和解决
1)修改config里面的num_calss之后报错:
重新编译
python setup.py install
要是还不行,先卸载mmdet,再重新编译
pip uninstall mmdet
pip install -r requirements/build.txt
pip install -v -e . # or "python setup.py develop".
Modifications will be added later!
边栏推荐
猜你喜欢

MySQL data types and footprint

Knowledge distillation method of target detection

Thread state of five

nodejs PM2监控及报警邮件发送(二)

The first WebAssembly program

Servlet基本原理与常见API方法的应用

Based on R language geographic weighted regression, principal component analysis, discriminant analysis and other spatial heterogeneity data analysis

Flink CDC implements Postgres to MySQL streaming processing transmission case

边境的悍匪—机器学习实战:第十三章 使用TensorFlow加载和预处理数据

七、Kotlin基础学习:1、创建类;2、构造函数;3、继承;4、封装;5、抽象类;6、接口;7、嵌套类;8、内部类;9、枚举类
随机推荐
CLUE模型构建方法、模型验证及土地利用变化情景预测
MySQL - Multi-table query and case detailed explanation
边境的悍匪—机器学习实战:第九章 无监督学习任务
SQL Server安装教程
什么是过拟合、欠拟合现象以及如何缓解?
MySQL 特殊语句及优化器
Simulation of Future Air Pollution Changes Based on Global Model Comparison Program CMIP6 and Regional Climate-Chemistry Coupling Model WRF-Chem
MYSQL一站式学习,看完即学完
MySQL开窗函数
TDengine集群搭建
The number of warehouse 】 data quality
Flink-流/批/OLAP一体得到Flink引擎
TDengineGUI cannot connect to TDengine
Nodejs PM2 monitoring and alarm email (2)
十九、Kotlin进阶学习:1、管道数据的收和发;2、管道的关闭;3、生产者和消费者;4、管道的缓存区;
Meta分析在生态环境领域里的应用
边境的悍匪—机器学习实战:第十五章 使用CNN和RNN处理序列
MySQL achievement method 】 【 5 words, single table SQL queries
十、Kotlin基础学习:1、延迟加载;2、异常处理;3、使用 throw 主动抛出异常;4、自定义异常;
C语言实战小项目(传统卡牌游戏)