当前位置:网站首页>配置MMdetection环境并训练
配置MMdetection环境并训练
2022-07-30 05:44:00 【Amber亮】
配置MMdetection环境(以VFNet为例)
建议优先使用官网的方法哦,链接放在下面了!
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)。mmcv版本配置不对就无法正常训练模型,一定要使用正确的版本。
pip install mmcv-full -f https://download.openmmlab.com/mmcv/dist/cu110/torch1.7.0/index.html
4、安装pycocotools
虽然官网上没有要求安装,但是我报错缺失pycocotools。
pip install git+https://github.com/philferriere/cocoapi.git#subdirectory=PythonAPI
或者https://github.com/philferriere/cocoapi下载源码,并进行解压。切换到 cocoapi\PythonAPI目录。运行:
python setup.py build_ext install
然后cd到自己的路径下,安装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".
到这里为止,环境的配置就完成了。开始准备数据集
6、使用自己的coco格式数据集
官方提供的所有代码都默认使用的是coco格式的数据集,我这里也使用的coco格式的数据集。各种类型数据转coco格式脚本见:
https://github.com/spytensor/prepare_detection_dataset
mmdetection
├── mmdet
├── tools
├── configs
├── data
│ ├── coco
│ │ ├── annotations
│ │ ├── train2017
│ │ ├── val2017
│ │ ├── test2017
7、训练之前还要改一些参数
1)定义数据种类,需要修改的地方在mmdetection/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数据集类别,这个关系到后面test的时候结果图中显示的类别名称
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(不用分布式):
#从开始训练模型
python tools/train.py configs/vfnet/vfnet_x101_64x4d_fpn_mstrain_2x_coco.py
#从断点权重文件继续训练
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)如果只是想看一下效果而不要进行定量指标分析的话,可以运行之前那个demo.py文件,但是要改一下checkpoint_file的地址路径,使用我们上一步跑出来的work_dirs下的pth文件。例如checkpoint_file = 'work_dirs/epoch_100.pth
(2)使用test命令来进行测试评估一些参数
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
放一张我训练完的结果图(数据集用的是自己的,单类的 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".
后续还会再添加修改!
边栏推荐
- Mysql 客户端常见异常分析
- 【OS】操作系统高频面试题英文版(1)
- MySQL - Function and Constraint Commands
- Conda 安装 tensorflow gpu 1.13.1(验证可行)
- 卷积神经网络(CNN)之卷积操作、池化操作、激活函数
- 史上超强最常用SQL语句大全
- Monstache执行monstache -f config.toml出错No processor type exists with name [attachment] [type=parse_exc
- The types of data structures and MySQL index
- 线程的5种状态
- MySQL data types and footprint
猜你喜欢

Pytorch(三):可视化工具(Tensorboard、Visdom)

在线sql编辑查询工具sql-editor
![Monstache执行monstache -f config.toml出错No processor type exists with name [attachment] [type=parse_exc](/img/2d/50c9001125cd613087044d2b6c78b1.png)
Monstache执行monstache -f config.toml出错No processor type exists with name [attachment] [type=parse_exc

九、Kotlin基础学习:1、Companion的扩展方法和扩展属性;2、一般类的扩展方法和扩展属性;3、委托;

二十一、Kotlin进阶学习:实现简单的网络访问封装
Awd summary

TDengine集群搭建

MySQL 5.7 安装教程(全步骤、保姆级教程)

六、Kotlin基础学习:函数

MySQL - 多表查询与案例详解
随机推荐
protobuf编码及网络通信应用(一)
函数的信息传递(C语言实践)
MySQL开窗函数
【十年网络安全工程师整理】—100渗透测试工具使用方法介绍
MySQL 索引的数据结构及类型
[Getting C language from zero basis - navigation summary]
sqli-labs shooting range SQL injection learning Less-1
Bypassing the file upload vulnerability
MySQL - 函数及约束命令
Flink CDC 实现Postgres到MySQL流式加工传输案例
Detailed explanation of ClickHouse query statement
The most powerful and most commonly used SQL statements in history
使用kotlin扩展插件/依赖项简化代码(在最新版本4.0以后,此插件已被弃用,故请选择性学习,以了解为主。)
mysql不是内部或外部命令,也不是可运行的程序或批处理文件解决
TDengineGUI无法连接TDengine
FastAPI 快速入门
十七、Kotlin进阶学习:1、守护线程;2、线程和协程之间的效率对比;3、取消协程;
Kotlin协程的简单用法:1、GlobalScope(不建议使用);2、lifecycleScope、viewModelScope(建议使用);
Remember a traffic analysis practice - Anheng Technology (August ctf)
ClickHouse查询语句详解