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

Yolo2 model type not working #183

Open mdatre opened 3 years ago

mdatre commented 3 years ago

Hi,

I have Yolo2 darknet19 weights and cfg files pretrained on a custom dataset. I converted those to TF h5 weights using the convert.py script, which also created an anchors file. However when I try to use these with yolo.py script for detection, it gives errors as follows:

$ python3 yolo.py --model_type yolo2_darknet --weights_path weights/yolov2_my_pretrained.h5 --anchors_path configs/yolov2_my_pretrained_anchors.txt --classes_path configs/my_classes.txt --image

ValueError: You are trying to load a weight file containing 43 layers into a model with 45 layers.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "yolo.py", line 437, in <module>
    main()
  File "yolo.py", line 409, in main
    yolo = YOLO_np(**vars(args))
  File "yolo.py", line 69, in __init__
    self.yolo_model = self._generate_model()
  File "yolo.py", line 105, in _generate_model
    num_anchors/len(yolo_model.output) * (num_classes + 5), \
  File "/home/user1/.local/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 853, in __len__
    "shape information.".format(self.name))
TypeError: len is not well defined for symbolic Tensors. (predict_conv/BiasAdd:0) Please call `x.shape` rather than `len(x)` for shape information.

I tried using other Yolo2 model types too like yolo2_mobilenet but none is working. The default one tiny_yolo3_darknet and yolo3_darknet worked as per the examples given on readme as well in some other issues logged here.

Any idea how to get custom trained Yolo2 darknet weights and cfg file working with this or am I missing something?

david8862 commented 3 years ago

@mdatre what's your cfg and weights? I double checked with official COCO pretrained yolo2_darknet weights and it works fine.

mdatre commented 3 years ago

@mdatre what's your cfg and weights? I double checked with official COCO pretrained yolo2_darknet weights and it works fine.

@david8862 I am using this Yolo2 weights and cfg file mentioned on this blog.

But I changed a few things in your code. I created a yolo2 model from the JSON file and loaded weights from h5 file (saved separately by modifying convert.py), without building Darknet19 as done in your code. Then I ran yolo.py detection with --image option using yolo2 VOC anchors file. That worked for a couple of examples I tried. I am wondering what is the difference between your Darknet19 model and AlexyAB's one on which the above weights were trained.

Why the VOC anchor file generated after running convert.py on PJ Reddie's Yolo2 cfg and weights does not work with yolo.py detection?

I noticed that you have a different VOC anchor file yolo2-voc_anchors.txt in configs folder. yolo2_anchors.txt does not produce good detection on the above mentioned model/weights. Why don't the extracted anchors from original Darknet's cfg files do not work?

Could you please clarify these doubts?

mdatre commented 3 years ago

@david8862 Also I wanted to know what is the minimal computing configuration expected to do training from scratch using train.py script? We tried to run it on a modest 1 GPU, 16 GB GPU mem and 32 GB RAM, and the script was killed by the OS within a few minutes with "out of memory" error message.

On a slightly higher configuration machine, the speed seemed quite slow with 11 epochs per hour, when we wanted to train for a few thousand epochs.

david8862 commented 3 years ago

@mdatre Oh for yolo2 I change anchor definition to align YOLOv2/v3 anchor definitions and postprocess. You can refer #108 For GPU consumption in training, it depends on related config (model_type, batch_size, etc.). And the time for 1 epoch depends on dataset size.