无脑002——yolov5从头训练一个目标检测模型

参考这篇文章:
https://blog.csdn.net/ECHOSON/article/details/121939535

conda config --remove-key channels
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/pkgs/main/
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/pkgs/free/
conda config --add channels https://mirrors.bfsu.edu.cn/anaconda/cloud/pytorch/
conda config --set show_channel_urls yes
pip config set global.index-url https://mirrors.ustc.edu.cn/pypi/web/simple
conda create -n yolo5 python==3.8.5
conda activate yolo5
我在G:\dipExp\yolo5这里统一存放文件
g:
cd dipExp\yolo5
pip install torch==1.8.1+cu101 torchvision==0.9.1+cu101 torchaudio==0.8.1 -f https://download.pytorch.org/whl/torch_stable.html 
然后测试是否安装GPU版本的torch
>>> import torch
>>> torch.__version__
'1.8.1+cu101'
>>> torch.cuda.get_device_name(0)
'NVIDIA GeForce GTX 1060'
能输出GPU型号就表明成功了
pip install -r requirements.txt
pip install pyqt5
pip install labelme

然后就可以进行测试了
python detect.py --source data/images/bus.jpg --weights pretrained/yolov5s.pt
python detect.py --source 0  # webcam
                            file.jpg  # image 
                            file.mp4  # video
                            path/  # directory
                            path/*.jpg  # glob
                            'https://youtu.be/NUsoVlDFqZg'  # YouTube video
                            'rtsp://example.com/media.mp4'  # RTSP, RTMP, HTTP stream


pip install labelimg -i https://mirror.baidu.com/pypi/simple
输入labelmg启动标注程序
yolov5-mask-42-master\dataset  ├─ images
						       │    ├─ test # 下面放测试集图片 19张
						       │    ├─ train # 下面放训练集图片 51张
						       │    └─ val # 下面放验证集图片 和test用的一样的 19张
						       └─ labels
						              ├─ test # 下面放测试集标签
						              ├─ train # 下面放训练集标签
						              ├─ val # 下面放验证集标签

然后开始训练,
python train.py --data mask_data.yaml --cfg mask_yolov5s.yaml --weights pretrained/yolov5s.pt --epoch 100 --batch-size 8
完成之后进行测试:
python detect.py  --weights runs/train/exp5/weights/best.pt --source 0
反正能检测到,但是效果一般,把我爸妈都认成我了哈哈。
 # 检测摄像头
 python detect.py  --weights runs/train/exp_yolov5s/weights/best.pt --source 0  # webcam
 # 检测图片文件
  python detect.py  --weights runs/train/exp_yolov5s/weights/best.pt --source file.jpg  # image 
 # 检测视频文件
   python detect.py --weights runs/train/exp_yolov5s/weights/best.pt --source file.mp4  # video
 # 检测一个目录下的文件
  python detect.py --weights runs/train/exp_yolov5s/weights/best.pt path/  # directory
 # 检测网络视频
  python detect.py --weights runs/train/exp_yolov5s/weights/best.pt 'https://youtu.be/NUsoVlDFqZg'  # YouTube video
 # 检测流媒体
  python detect.py --weights runs/train/exp_yolov5s/weights/best.pt 'rtsp://example.com/media.mp4'  # RTSP, RTMP, HTTP stream                            

你可能感兴趣的:(无脑100,目标检测,python,深度学习)