SpursLipu / YOLOv3v4-ModelCompression-MultidatasetTraining-Multibackbone

YOLO ModelCompression MultidatasetTraining
GNU General Public License v3.0
445 stars 136 forks source link

我只有一类目标,可以用你在项目中给出的coco80类的yolov3-mobilenet.weights预训练模型吗? #50

Closed chenjunson closed 4 years ago

chenjunson commented 4 years ago

我只有一类目标,可以用你在项目中给出的coco的80类的yolov3-mobilenet.weights预训练模型吗?我用这个预训练模型会报错,是需要改一下什么地方吗?

SpursLipu commented 4 years ago

可以使用预训练模型的,你在指令里面加上pt就可以了

chenjunson commented 4 years ago

加上- pt后报错如下: chenjunsong@chenjunsong-GJ5CN64:~/U-YOLOv3$ python3 train.py --data data/obj.data --batch-size 5 --cfg cfg/yolov3-mobilenet/yolov3-mobilenet.cfg --weights weights/yolov3-mobilenet.weights -pt Apex recommended for faster mixed precision training: https://github.com/NVIDIA/apex Namespace(KDstr=-1, adam=False, batch_size=5, bucket='', cache_images=False, cfg='./cfg/yolov3-mobilenet/yolov3-mobilenet.cfg', data='data/obj.data', device='', ema=False, epochs=601, evolve=False, img_size=[320, 640], multi_scale=False, name='', nosave=False, notest=False, prune=-1, pt=True, qlayers=-1, quantized=-1, rect=False, resume=False, s=0.001, single_cls=False, sr=False, t_cfg='', t_weights='', weights='weights/yolov3-mobilenet.weights') Using CUDA device0 _CudaDeviceProperties(name='GeForce GTX 1060', total_memory=6072MB)

Start Tensorboard with "tensorboard --logdir=runs", view at http://localhost:6006/ Model Summary: 229 layers, 2.37856e+07 parameters, 2.37856e+07 gradients Optimizer groups: 70 .bias, 55 Conv2d.weight, 104 other Traceback (most recent call last): File "train.py", line 523, in train(hyp) # train normally File "train.py", line 151, in train load_darknet_weights(model, weights, pt=opt.pt) File "/home/chenjunsong/U-YOLOv3/models.py", line 568, in load_darknet_weights assert ptr == len(weights) AssertionError

chenjunson commented 4 years ago

我把yolov3-mobilenet.weights改为yolov3-mobilenet.pt错误就变成这样了:chenjunsong@chenjunsong-GJ5CN64:~/U-YOLOv3$ python3 train.py --data data/obj.data --batch-size 5 --cfg cfg/yolov3-mobilenet/yolov3-mobilenet.cfg --weights weights/yolov3-mobilenet.pt -pt Apex recommended for faster mixed precision training: https://github.com/NVIDIA/apex Namespace(KDstr=-1, adam=False, batch_size=5, bucket='', cache_images=False, cfg='./cfg/yolov3-mobilenet/yolov3-mobilenet.cfg', data='data/obj.data', device='', ema=False, epochs=601, evolve=False, img_size=[320, 640], multi_scale=False, name='', nosave=False, notest=False, prune=-1, pt=True, qlayers=-1, quantized=-1, rect=False, resume=False, s=0.001, single_cls=False, sr=False, t_cfg='', t_weights='', weights='weights/yolov3-mobilenet.pt') Using CUDA device0 _CudaDeviceProperties(name='GeForce GTX 1060', total_memory=6072MB)

Start Tensorboard with "tensorboard --logdir=runs", view at http://localhost:6006/ Model Summary: 229 layers, 2.37856e+07 parameters, 2.37856e+07 gradients Optimizer groups: 70 .bias, 55 Conv2d.weight, 104 other Traceback (most recent call last): File "train.py", line 523, in train(hyp) # train normally File "train.py", line 125, in train chkpt = torch.load(weights, map_location=device) File "/home/chenjunsong/anaconda3/lib/python3.7/site-packages/torch/serialization.py", line 387, in load return _load(f, map_location, pickle_module, pickle_load_args) File "/home/chenjunsong/anaconda3/lib/python3.7/site-packages/torch/serialization.py", line 564, in _load magic_number = pickle_module.load(f, pickle_load_args) _pickle.UnpicklingError: invalid load key, '\x00'.

chenjunson commented 4 years ago

似乎注释掉assert ptr == len(weights)这行命令就能训练了。但注释掉这行后训练,算是加载了预训练模型,还是没有呢?

SpursLipu commented 4 years ago

--cfg cfg/yolov3-mobilenet/yolov3-mobilenet.cfg 这块,你的cfg文件需要重写一下,你可以参照我的不同数据集上的cfg文件,更改类别,yolo层前的一层卷积的通道数,重写一个cfg文件再训练就可以了

chenjunson commented 4 years ago

那个cfg文件我改过了,类别改得1,那个yolo层前的一层卷积的通道数改成了18。你说的是要改这两个部分吧,三处的yolo层都改过了。 [convolutional] size=1 stride=1 pad=1 filters=18 activation=linear

[yolo] mask = 6,7,8 anchors = 10,13, 16,30, 33,23, 30,61, 62,45, 59,119, 116,90, 156,198, 373,326 classes=1 num=9 jitter=.3 ignore_thresh = .7 truth_thresh = 1 random=1

chenjunson commented 4 years ago

我用你项目里面带的那个yolov3-mobilenet-hand.cfg也是只有一类目标,可以对我的数据集进行训练,可能是我的那个cfg文件那块有问题,我去对比找找看,非常感谢。

SpursLipu commented 4 years ago

如果是单分类你可以用hand的那个,不过建议你最好重新聚类一下anchor

chenjunson commented 4 years ago

嗯,是的,我去重新聚类一下anchor。