赞
踩
很多常用术语不太懂,毕竟咱不是这专业的,也算个初学者,总之,菜是原罪,能学就学。
查看https://github.com/ultralytics/yolov5/wiki/Train-Custom-Data,里面有这样一句话。
For training command outputs and further details please see the training section of Google Colab Notebook.
打开这个notebook(需要点手段,你们懂的)。
总结一下,这个notebook中有关train 的信息。
--cfg
选择model文件(models/yolo5s.yaml)--data
选择datase文件(data/coco128.yaml)--weights
指定初始权重文件(随机初始化--weights ''
)然后就没了。。。。。显然对咱深入理解没啥帮助,也就勉强一用。
传参都在这了。
if __name__ == '__main__': check_git_status() parser = argparse.ArgumentParser() parser.add_argument('--cfg', type=str, default='models/yolov5s.yaml', help='model.yaml path') parser.add_argument('--data', type=str, default='data/coco128.yaml', help='data.yaml path') parser.add_argument('--hyp', type=str, default='', help='hyp.yaml path (optional)') parser.add_argument('--epochs', type=int, default=300) parser.add_argument('--batch-size', type=int, default=16) parser.add_argument('--img-size', nargs='+', type=int, default=[640, 640], help='train,test sizes') parser.add_argument('--rect', action='store_true', help='rectangular training') parser.add_argument('--resume', nargs='?', const='get_last', default=False, help='resume from given path/to/last.pt, or most recent run if blank.') parser.add_argument('--nosave', action='store_true', help='only save final checkpoint') parser.add_argument('--notest', action='store_true', help='only test final epoch') parser.add_argument('--noautoanchor', action='store_true', help='disable autoanchor check') parser.add_argument('--evolve', action='store_true', help='evolve hyperparameters') parser.add_argument('--bucket', type=str, default='', help='gsutil bucket') parser.add_argument('--cache-images', action='store_true', help='cache images for faster training') parser.add_argument('--weights', type=str, default='', help='initial weights path') parser.add_argument('--name', default='', help='renames results.txt to results_name.txt if supplied') parser.add_argument('--device', default='', help='cuda device, i.e. 0 or 0,1,2,3 or cpu') parser.add_argument('--multi-scale', action='store_true', help='vary img-size +/- 50%%') parser.add_argument('--single-cls', action='store_true', help='train as single-class dataset') opt = parser.parse_args()
总结一下:
nargs='+' 表示参数可设置一个或多个
;以下这些都没太看懂
noautoanchor:disable autoanchor check
nosave:only save final checkpoint
bucket:gsutil bucket(应该关于谷歌云,应该用不上)
multi-scale:vary img-size +/- 50%%
读下来我的命令行语句应该改为:
python train.py --epoch 53 --data .\data\junk2020.yaml --cfg .\models\yolov5s.yaml --weight runs\exp10\weights\best.pt --evolve --cache-images
测试一下
内存可能不太够,电脑差点崩掉,中途杀了python,所以那个cache没能力就先别加了。。。
evolve之后的hyp也不知道存在哪了,,,明天再说吧。。。。
python train.py --epoch 80 --data .\data\junk2020.yaml --cfg .\models\yolov5s.yaml --weight runs\exp10\weights\best.pt --evolve
结果就是evolve出错
Traceback (most recent call last):
File "train.py", line 449, in <module>
print_mutation(hyp, results, opt.bucket)
File "D:\ForSpeed\junk_yolov5\yolov5\utils\utils.py", line 823, in print_mutation
b = '%10.3g' * len(hyp) % tuple(hyp.values()) # hyperparam values
TypeError: must be real number, not str
由于不好debug,这边先把evolve去了。
解释一下result.png里都是啥:
Traceback (most recent call last):
File "train.py", line 449, in <module>
print_mutation(hyp, results, opt.bucket)
File "D:\ForSpeed\junk_yolov5\yolov5\utils\utils.py", line 823, in print_mutation
b = '%10.3g' * len(hyp) % tuple(hyp.values()) # hyperparam values
TypeError: must be real number, not str
这波看这句b = '%10.3g' * len(hyp) % tuple(hyp.values())
,意思是把hyp这个字典的value都提出来形成一个元组,然后以10.3g批量格式化。
hyp = {'optimizer': 'SGD', # ['adam', 'SGD', None] if none, default is SGD 'lr0': 0.01, # initial learning rate (SGD=1E-2, Adam=1E-3) 'momentum': 0.937, # SGD momentum/Adam beta1 'weight_decay': 5e-4, # optimizer weight decay 'giou': 0.05, # giou loss gain 'cls': 0.58, # cls loss gain 'cls_pw': 1.0, # cls BCELoss positive_weight 'obj': 1.0, # obj loss gain (*=img_size/320 if img_size != 320) 'obj_pw': 1.0, # obj BCELoss positive_weight 'iou_t': 0.20, # iou training threshold 'anchor_t': 4.0, # anchor-multiple threshold 'fl_gamma': 0.0, # focal loss gamma (efficientDet default is gamma=1.5) 'hsv_h': 0.014, # image HSV-Hue augmentation (fraction) 'hsv_s': 0.68, # image HSV-Saturation augmentation (fraction) 'hsv_v': 0.36, # image HSV-Value augmentation (fraction) 'degrees': 0.0, # image rotation (+/- deg) 'translate': 0.0, # image translation (+/- fraction) 'scale': 0.5, # image scale (+/- gain) 'shear': 0.0} # image shear (+/- deg)
观察values,第一项为字符串’SGD’,所以格式化出现了问题。
将b = '%10.3g' * len(hyp) % tuple(hyp.values())
改为
b = '%10s' * 1 % (list(hyp.values())[0],) + '%10.3g' * (len(hyp) - 1) % tuple( list(hyp.values())[1:])
训练一轮试试
Traceback (most recent call last):
File "train.py", line 449, in <module>
print_mutation(hyp, results, opt.bucket)
File "D:\ForSpeed\junk_yolov5\yolov5\utils\utils.py", line 837, in print_mutation
x = np.unique(np.loadtxt('evolve.txt', ndmin=2), axis=0) # load unique rows
File "C:\Users\15518\AppData\Local\Programs\Python\Python37\lib\site-packages\numpy\lib\npyio.py", line 1146, in loadtxt
for x in read_data(_loadtxt_chunksize):
File "C:\Users\15518\AppData\Local\Programs\Python\Python37\lib\site-packages\numpy\lib\npyio.py", line 1074, in read_data
items = [conv(val) for (conv, val) in zip(converters, vals)]
File "C:\Users\15518\AppData\Local\Programs\Python\Python37\lib\site-packages\numpy\lib\npyio.py", line 1074, in <listcomp>
items = [conv(val) for (conv, val) in zip(converters, vals)]
File "C:\Users\15518\AppData\Local\Programs\Python\Python37\lib\site-packages\numpy\lib\npyio.py", line 781, in floatconv
return float(x)
ValueError: could not convert string to float: 'SGD'
这里是np.loadtxt('evolve.txt', ndmin=2)
这里txt里有字符串,所以出错。
把第一项去掉看看
Traceback (most recent call last):
File "train.py", line 437, in <module>
hyp[k] = x[i + 7] * v[i] # mutate
IndexError: index 18 is out of bounds for axis 0 with size 18
待续。。。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。