1、选择使用的算法
D:\pythonProject\mmaction2-main\mmdetection-main\configs\deformable_detr\deformable-detr_r50_16xb2-50e_coco.py
2、选择数据data,放在那里都可以只要能找到就行
D:\pythonProject\mmdetection-master\mmdet\data
可以使用labelme来进行图片的标注,表完后为json格式,要用脚本将其转换为coco数据集的格式
经典格式:1、COCO格式,比较通用
2、VOC格式
找脚本进行转换,标注工具中一般会自带脚本
D:\pythonProject\mmdetection-master\mmdet\data\json2coco.py
需要改的地方:
1、类别编号
#1、
classname_to_id = {
"mask": 0, #改成自己的类别
"person": 1
}
2、路径的更改
if __name__ == '__main__':
#2、路径的更改
labelme_path = "./labelme-data/maskdataset"#源路径
saved_coco_path = "./labelme-data/coco-format"#保存的路径
print('reading...')
3、算法的修改
1、D:\pythonProject\mmdetection-master\mmdet\core\evaluation\class_names.py
将coco_classes中的内容改成自己的
2、D:\pythonProject\mmdetection-master\mmdet\datasets\coco.py
在这里将此次datasets中的类别改成自己的
3、D:\pythonProject\mmdetection-master\configs\deformable_detr\my_deformable_detr_r50_16x2_50e_coco.py
需要将类别数量进行更改
bbox_head=dict(
type='DeformableDETRHead',
num_query=300,
num_classes=2,#这里改成类别的数量
in_channels=2048,
4、将程序全部显示,报错也会有文件生成
将原算法的绝对路径复制,作为参数到tools\train.py中运行
D:\pythonProject\mmaction2-main\mmdetection-main\configs\deformable_detr\deformable-detr_r50_16xb2-50e_coco.py
D:\pythonProject\mmdetection-master\tools\train.py
在D:\pythonProject\mmdetection-master\tools\work_dirs\deformable_detr_r50_16x2_50e_coco
中可以找到执行完的代码
就化成了全部显示的样子
可以将运行好的代码重命名后,保存到算法运行的地方,注意不要直接替换
5、注意这里的mmcv需要1.4.2,先去下载吧
如果项目要求很落后,那么两个思路:
1\新建一个环境去安装版本较低的配置文件 ==>但是若电脑较新,配置较高就会出现不兼容的问题
2\去github上找版本较高的项目,进行重新配置,那样的话,与老师将的版本不一致,有些代码更改的地方,就找不到了
两种各有弊端,但是用2起码可以跑出来
6、预训练模型的配置
将下载好的预训练模型放到哪里到可以,但是要注意这里需制定好路径信息
1\github打开mmdetection
2\找model zoo
3\找到自己所使用的算法
4\去里面找model的预训练模型
里面还有此算法的论文
7、配置文件
算法中不明白的参数,可以查看官网的详解
https://mmdetection.readthedocs.io/zh-cn/latest/user_guides/config.html
8、训练train
重复4,直接将程序进行训练即可
会在这里生成训练好的权重参数
D:\pythonProject\mmdetection-high\tools\work_dirs\deformable-detr_r50_16xb2-50e_coco
可以在算法中配置更改进行的轮数,活何时进行保存等
9、测试,用单个照片进行
传参之前先执行一下,看是否存在错误,虽然有错我也不会改
代码:
D:\pythonProject\mmdetection-high\demo\image_demo.py
至少需要传进去3 个参数
1\图片
2\算法
3\训练好的权重值
parser.add_argument(
'inputs', type=str, help='Input image file or folder path.')
parser.add_argument(
'model',
type=str,
help='Config or checkpoint .pth file or the model name '
'and alias defined in metafile. The model configuration '
'file will try to read from .pth if the parameter is '
'a .pth weights file.')
parser.add_argument('--weights', default=None, help='Checkpoint file')
D:\\pythonProject\\mmdetection-high\\configs\\deformable_detr\\my_all_deformable-detr_r50_16xb2-50e_coco.py
D:\\pythonProject\\mmdetection-high\\tools\\work_dirs\\deformable-detr_r50_16xb2-50e_coco\\epoch_50.pth
--out
D:\\pythonProject\\mmdetection-high\\tools\\work_dirs\\deformable-detr_r50_16xb2-50e_coco\\test1.pkl
--show
10、进行数据分析
位置:D:\pythonProject\mmdetection-high\tools\analysis_tools\confusion_matrix.py
设置参数,运行
‘’’
D:\pythonProject\mmdetection-high\configs\deformable_detr\my_all_deformable-detr_r50_16xb2-50e_coco.py
D:\pythonProject\mmdetection-high\tools\work_dirs\deformable-detr_r50_16xb2-50e_coco\test1.pkl
D:\pythonProject\mmdetection-high\tools\work_dirs\deformable-detr_r50_16xb2-50e_coco\
–show
‘’'参数设置