项目地址
https://github.com/OSU-Haolin/FasterRCNN-based-Face-Mask-Detection
源工程很多坑 例如标签没有添加到判断数组,标签判断是反着的
安装环境aconada环境

创建py37环境
conda create -n py37 python=3.7
激活环境
activate py37
CPU版本安装
https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/win-64/
0安装库 无需安装cuda(省事但是训练速度慢)
pip install -i https://pypi.doubanio.com/simple/ --trusted-host pypi.doubanio.com opencv-python
pip install -i https://pypi.doubanio.com/simple/ --trusted-host pypi.doubanio.com pycocotools
pip install -i https://pypi.doubanio.com/simple/ --trusted-host pypi.doubanio.com torch torchvision torchaudio
https://pytorch.org/

GPU版本安装
0 确保装好cuda11.3和cudnn8 aconda 部署了py37
(没有FQ 装的也很快 但是防止万一不建议直接装gpu版本 如果已经训练好模型前提下)
1安装cuda和cudnn (折腾但是训练速度快)
注意版本号对应尤其是pythrch
这里对应是cuda11.3 之后安装cudnn 并确定自动加入环境变量
2 安装库
pip install -i https://pypi.doubanio.com/simple/ --trusted-host pypi.doubanio.com opencv-python
pip install -i https://pypi.doubanio.com/simple/ --trusted-host pypi.doubanio.com pycocotools
conda install --use-local pytorch-1.11.0-py3.7_cuda11.3_cudnn8_0.tar.bz2 (有用GPU 开了烦请)


卸载
(如果已经pip装了cpu版本)
pip uninstall torch torchvision torchaudio
https://pytorch.org/
(pip安装的gpu版本不能用,难不成是先装了cpu版本 没卸载干净)

测试import torch
print(torch.__version__) #注意是双下划线
print(torch.cuda.is_available())
测试
1下载数据

解压后修改名字和路径

2数据转换
变成训练可以用的格式
python dataset_copy.py
训练输入数据

训练输出数据
迭代次数 默认30次 使用10次 每一轮保存一个结果

3训练
根据装的cpu还是gpu 选择

gpu一旦跑起来就会被占用 显示flase
python train_faster_rcnn.py
每一次迭代结果保存在 checkpoints_faster_rcnn
默认训练30次

4评估
python evaluation_faster_rcnn.py
检查
python checkpoints_faster_rcnn.py
5检测
1根据装的cpu还是gpu 选择
2 选择测试图像
3选择训练的模型

python demo_faster_rcnn.py demo.jpg


训练

验证截图
假设训练了10次 对第10次的权重验证下

浙公网安备 33010602011771号