david8862 / keras-YOLOv3-model-set

end-to-end YOLOv4/v3/v2 object detection pipeline, implemented on tf.keras with different technologies
MIT License
640 stars 222 forks source link

Training yolov4 darknet model with yolov4 weights and custom cfg file #66

Open mon28 opened 4 years ago

mon28 commented 4 years ago

Hi,

I observe an error while trying to provide the yolov4.h5 model made using custom config file. Where the filters were based on my data.

But the program build of the backend weights of weights/cspdarknet53.h5. and throws an error when the weights_path parameter is pointed at yolov4.h5

File "train.py", line 287, in <module>
    main(args)
  File "train.py", line 150, in main
    model = get_train_model(args.model_type, anchors, num_classes, weights_path=args.weights_path, freeze_level=freeze_level, optimizer=optimizer, label_smoothing=args.label_smoothing, model_pruning=args.model_pruning, pruning_end_step=pruning_end_step)
  File "/data/mtare/keras-yolov4/yolo3/model.py", line 211, in get_yolo3_train_model
    model_body.load_weights(weights_path, by_name=True)#, skip_mismatch=True)
  File "/data/mtare/keras-yolov4/venv/lib/python3.6/site-packages/tensorflow/python/keras/engine/training.py", line 250, in load_weights
    return super(Model, self).load_weights(filepath, by_name, skip_mismatch)
  File "/data/mtare/keras-yolov4/venv/lib/python3.6/site-packages/tensorflow/python/keras/engine/network.py", line 1264, in load_weights
    f, self.layers, skip_mismatch=skip_mismatch)
  File "/data/mtare/keras-yolov4/venv/lib/python3.6/site-packages/tensorflow/python/keras/saving/hdf5_format.py", line 785, in load_weights_from_hdf5_group_by_name
    str(weight_values[i].shape) + '.')
ValueError: Layer #355 (named "conv2d_107"), weight <tf.Variable 'conv2d_107/kernel:0' shape=(3, 3, 3, 32) dtype=float32,
david8862 commented 4 years ago

@mon28 what's your training cmd?

mon28 commented 4 years ago

@david8862 yolov4.h5 was created as per your command. I tried the below train command.

python train.py --model_type=yolo4_darknet --weights_path=weights/yolov4.h5 --annotation_file=data/trainval.txt --classes_path=data/obj.names --model_image_size=416x416 --multiscale --rescale_interval=50 --learning_rate=0.001 --transfer_epoch=0 --total_epoch=10000 --eval_online --eval_epoch_interval=5 --save_eval_checkpoint --gpu_num=1

david8862 commented 4 years ago

@mon28 for custom dataset training, the backbone pretrained weights "cspdarknet53.h5" would be automatically loaded at model construction, so you don't need to load coco pretrained yolov4.h5 again with "--weights_path" again, which may lead to prediction filter number mismatch and errors.