记录自己的YOLOv3实现和一些遇到的问题
参考教程及程序来源
根据此博主的教程实现了一下:https://blog.csdn.net/sinat_27634939/article/details/89884011?spm=1001.2014.3001.5506
主要是复现使用了yolov3.weights的80类检测、博主提到的细胞数据集进行自己训练。
使用的是Pytorch版本,github来源:
https://github.com/ultralytics/yolov3
这个版本已经是采用.yaml作为配置文件的(也就是.cfg,.names,.data不采用了),那个博主的教程还是用的cfg文件,现在github作者已经更新了代码,.yaml和YOLOv5的程序好像是一样的,好像只要改一下配置网络和权重其他都差不多?等一会把Yolov5也跑一下
.cfg版本的可以在历史版本里下吧,我好像下过一个,忘了是不是这个作者的
环境
- GPU独显4G,CUDA11.2,cdnn查对应匹配的版本
- Anaconda Win10 python==3.6
- Pytorch torch-1.8.0+cu111-cp36-cp36m-win_amd64,torchvision-0.9.0+cu111-cp36-cp36m-win_amd64 (建议下好whl文件本地pip install,并且在之前先下requirement.txt里的包,不然还是下载很慢会断)
- 剩下的下完程序 把程序里requirement.txt里面的都下好
简单记录一下过程
对数据集和标签各创文件夹,用makeTX.py和voc_label.py(如教程)
和一开始贴的教程里面一样就行,我程序稍微改动了一点(好像是因为我这边报错),码一下我自己的:(我直接放在项目目录下面)
# voc_label.py
import xml.etree.ElementTree as ET
import pickle
import os
from os import listdir, getcwd
from os.path import join
sets = ['train', 'test', 'val'] #
classes = ["RBC"] #
def convert(size, box):
dw = 1. / size[0]
dh = 1. / size[1]
x = (box[0] + box[1]) / 2.0
y = (box[2] + box[3]) / 2.0
w = box[1] - box[0]
h = box[3] - box[2]
x = x * dw
w = w * dw
y = y * dh
h = h * dh
return (x, y, w, h)
def convert_annotation(image_id):
in_file = open('data/Annotations/%s.xml' % (image_id))
out_file = open