1.GitHub 下载yolov5
2.环境:win10,visual studio 2015 ,anaconda2.7,python=3.7,cuda=10.2 ,pytorch=1.5(GPU)
3.更改镜像-清华
4.安装pytorch
5.安装requirements.txt:报错。解决方案:
git+https://github.com/philferriere/cocoapi.git#subdirectory=PythonAPI
用这个替换掉原有语句
6.下载预训练模型,YOLOv5l.pt。
7.直接运行detect文件,报错。解决方案:
1.python detect.py --source ./inference/images/bus.jpg --weights ./weights/yolov5s.pt --conf 0.4 --device cuda:0
2.这里报错:找不到cuda
3.进入到torch_utils.py,
def select_device(device='', apex=False, batch_size=None):
# device = 'cpu' or '0' or '0,1,2,3'
cpu_request = device.lower() == 'cpu'
if device and not cpu_request: # if device requested other than 'cpu'
os.environ['CUDA_VISIBLE_DEVICES'] = device # set environment variable
assert torch.cuda.is_available(), 'CUDA unavailable, invalid device %s requested' % device # check availablity
.
.
.
加入一个语句
def select_device(device='', apex=False, batch_size=None):
# device = 'cpu' or '0' or '0,1,2,3'
print(torch.cuda.is_available())
cpu_request = device.lower() == 'cpu'
if device and not cpu_request: # if device requested other than 'cpu'
os.environ['CUDA_VISIBLE_DEVICES'] = device # set environment variable
assert torch.cuda.is_available(), 'CUDA unavailable, invalid device %s requested' % device # check availablity
这样就可以找到cuda
于是得到结果:
接下来,是制作自己的小型数据集,训练和测试
0.下载coco2017,手动选40张图片和对应标签。
1.目录结构:
##数据集和代码平行目录
yolo的格式是 xxx.jpg和对应的 xxx.txt,共2个文件
txt中存放的是标注好的人、狗、摩托车的坐标;还有所属类别的序号
2.自制yaml文件
train: ../lee/train/images
val: ../lee/valid/images
test: ../lee/test/images
# number of classes
nc: 80
# class names
names: ['person', 'bicycle', 'car', 'motorcycle', 'airplane', 'bus', 'train', 'truck', 'boat', 'traffic light',
'fire hydrant', 'stop sign', 'parking meter', 'bench', 'bird', 'cat', 'dog',