Ubuntu修改清华源、conda修改清华源、更改pip源
https://blog.csdn.net/ly59782/article/details/89604663
https://www.cnblogs.com/lvchengda/p/12533040.html
git clone https://github.com/Tianxiaomo/pytorch-YOLOv4
conda create -n env_36 python=3.6.10
pip install -r requirements.txt
#去掉requirements.txt里的 skimage
pip install torchvision==0.5.0 # 与pytorch1.4.0配套
#python models.py <num_classes> <weightfile> <imgfile> <IN_IMAGE_H> <IN_IMAGE_W> <namefile(optional)>
python models.py 80 weight/yolov4.pth data/giraffe.jpg 416 416
pip install tensorboard #安装tensorboard
pip install tensorboardx #安装tensorboardx
硬币数据:https://pan.baidu.com/s/1y701NRKSdpj6UKDIH-GpqA 提取码:j09s
数据data 内部为图片、coins.name、train.txt、val.txt
由于类别比较少,修改cfg.py
Cfg.use_darknet_cfg = False
Cfg.cfgfile = os.path.join(_BASE_DIR, 'cfg', 'yolov4.cfg')
#Cfg.batch = 64
#Cfg.subdivisions = 16
Cfg.batch = 4
Cfg.subdivisions = 1
修改cfg.py使得train.py中的darknet不被使用
if cfg.use_darknet_cfg:
model = Darknet(cfg.cfgfile)
else:
model = Yolov4(cfg.pretrained, n_classes=cfg.classes)
为了不报错,修改了这里
def get_image_id(filename:str) -> int:
#aise NotImplementedError("Create your own 'get_image_id' function")
#lv, no = os.path.splitext(os.path.basename(filename))[0].split("_")
#lv = lv.replace("level", "")
#no = f"{int(no):04d}"
#return int(lv+no)
parts = filename.split('-')
id = int(parts[-1][0:-4])
return id
#训练
python train.py -l 0.001 -g 0 -pretrained weight/yolov4.conv.137.pth -classes 3 -dir /home/shilinzhe/dataset/coins/data -train_label_path /home/shilinzhe/dataset/coins/data/train.txt
-l 学习率
-g gpu id
-pretrained 预训练的主干网络,从AlexeyAB给的darknet的yolov4.conv.137转换过来的
-classes 类别种类
-dir 图片所在文件夹
-train_label_path标签所在目录
#预测
python models.py 3 checkpoints/Yolov4_epoch299.pth data/P00524-151911.jpg 418 418
#tensor board
tensorboard --logdir log --host 192.168.212.75 --port 6008
#浏览器打开上面的域名
Epoch 300/300: 96%|\u2589| 24/25 [00:12<00:00, 2.63imin function convert_to_coco_api...
creating index...
index created!
Accumulating evaluation results...
DONE (t=0.06s).
IoU metric: bbox
Average Precision (AP) @[ IoU=0.50:0.95 | area= all | maxDets=100 ] = 0.489
Average Precision (AP) @[ IoU=0.50 | area= all | maxDets=100 ] = 0.727
Average Precision (AP) @[ IoU=0.75 | area= all | maxDets=100 ] = 0.609
Average Precision (AP) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = -1.000
Average Precision (AP) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = -1.000
Average Precision (AP) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.489
Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets= 1 ] = 0.244
Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets= 10 ] = 0.715
Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets=100 ] = 0.764
Average Recall (AR) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = -1.000
Average Recall (AR) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = -1.000
Average Recall (AR) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.764
2020-09-24 21:03:44,287 train.py[line:446] INFO: Created checkpoint directory
2020-09-24 21:03:44,572 train.py[line:451] INFO: Checkpoint 300 saved !
Epoch 300/300: 96%|\u2589| 24/25 [00:29<00:01, 1.22s/
-----------------------------------
Preprocess : 0.025719
Model Inference : 0.110292
-----------------------------------
-----------------------------------
max and argmax : 0.001573
nms : 0.000841
Post processing total : 0.002414
-----------------------------------
-----------------------------------
Preprocess : 0.012659
Model Inference : 0.051989
-----------------------------------
-----------------------------------
max and argmax : 0.001905
nms : 0.000938
Post processing total : 0.002843
-----------------------------------
1yuan: 0.994108
1yuan: 0.992459
1yuan: 0.978318
1yuan: 0.977262
1yuan: 0.944226
1yuan: 0.766804
5jiao: 0.977799
5jiao: 0.658348
1jiao: 0.891799
1jiao: 0.581562
save plot results to predictions.jpg