wangermeng2021 / Scaled-YOLOv4-tensorflow2

A Tensorflow2.x implementation of Scaled-YOLOv4 as described in Scaled-YOLOv4: Scaling Cross Stage Partial Network
Apache License 2.0
47 stars 18 forks source link

Training with datasets in COCO format #3

Open sakulh opened 3 years ago

sakulh commented 3 years ago

Hi, first of all, thank you for your work!

I'am trying to train COCO 2017 dataset and also my own dataset in COCO format but without success:

!python train.py --use-pretrain True\
                 --model-type p5\
                 --dataset-type coco\
                 --dataset dataset/coco/\
                 --num-classes 32\
                 --class-names coco.names\
                 --coco-train-set train2017\
                 --coco-valid-set val2017\
                 --epochs 200\
                 --batch-size 8\
                 --multi-scale 416\
                 --augment ssd_random_crop 

Output:

...
Load p5 weight successfully!
Tensorboard engine is running at http://localhost:6006/
loading dataset...
  0%|                                                   | 0/625 [00:00<?, ?it/s]
Traceback (most recent call last):
  File "train.py", line 298, in <module>
    main(args)
  File "train.py", line 194, in main
    coco_map_callback = CocoMapCallback(pred_generator,model,args,mAP_writer)
  File "/tf/parkinto-object-detection/Scaled-YOLOv4-tensorflow2/utils/fit_coco_map.py", line 30, in __init__
    for batch_img, batch_boxes, batch_valids in pred_generator_tqdm:
  File "/usr/local/lib/python3.6/dist-packages/tqdm/std.py", line 1170, in __iter__
    for obj in iterable:
  File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/utils/data_utils.py", line 483, in __iter__
    for item in (self[i] for i in range(len(self))):
  File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/utils/data_utils.py", line 483, in <genexpr>
    for item in (self[i] for i in range(len(self))):
  File "/tf/parkinto-object-detection/Scaled-YOLOv4-tensorflow2/generator/coco_generator.py", line 183, in __getitem__
    y_true = get_y_true(self.max_side, batch_boxes, groundtruth_valids, self._args)
  File "/tf/parkinto-object-detection/Scaled-YOLOv4-tensorflow2/generator/get_y_true.py", line 92, in get_y_true
    grids[grid_index][batch_index][grid_xy[1]][grid_xy[0]][grid_anchor_index][5+batch_boxes[batch_index][box_index][4].astype(np.int32)] = 1
IndexError: index 44 is out of bounds for axis 0 with size 37

I'am using TF 2.4.1

Is possible to train on datasets in COCO format or I have to convert them to VOC format? Thank you

wangermeng2021 commented 3 years ago

Sorry for late replay, It's seem that batch_boxes[batch_index][box_index][4].astype(np.int32) exceed max limit 5+32(num-classes), because your num-classes is 32, but one of your classes included in your coco dataset is 39, so 39+5=44>5+32, it's just my guess, I will recheck and test the coco generator class(last update is a little rushed), thank you for your feedback.

sakulh commented 3 years ago

Thank you. I finally converted my coco dataset to voc format and everything seems that is ok.