zzh8829 / yolov3-tf2

YoloV3 Implemented in Tensorflow 2.0
MIT License
2.51k stars 909 forks source link

"ValueError" issues concerning tensor shapes #325

Open tpostadjian opened 4 years ago

tpostadjian commented 4 years ago

Hi,

Thanks for the implementation ! I created the dataset with my own data accordingly to the Tensorflow TFrecord api. However, I am experiencing several issues with the training workflow.

  1. First, after the tfrecord is being loaded, the following instructions fails :

    train_dataset = train_dataset.map(lambda x, y: (transform_images(x, 416),
                                                transform_targets(
                                                    y, yolo_anchors, 
                                                    yolo_anchor_masks, 416)))

    with a traceback ValueError: Shape must be rank 3 but is rank 4 for 'Tile' (op: 'Tile') with input shapes: [?,1,2], [4].
    This issue occurs line 56 in the transform_targets function from dataset.py. I managed to address it by changing the line from

    box_wh = tf.tile(tf.expand_dims(box_wh, -2),  (1, 1, tf.shape(anchors)[0], 1))

    to

    box_wh = tf.tile(tf.expand_dims(box_wh, -2),  (1, tf.shape(anchors)[0], 1))

    (removing the second axis in the second arg). However, since no one reported this issue I am not very confident in this solution.

  2. The second issue occurs in the transform_targets_for_output function, line 21 of dataset.py :
    ValueError: Index out of range using input dim 0; input has only 0 dims for 'strided_slice_3' (op: 'StridedSlice') with input shapes: [], [1], [1], [1] and with computed input tensors: input[3] = <1>.

  3. Finally, I encounter an issue with the loss in the training process when ignoring the transformation mappings in the dataset. Just led this experiment to check if there was any problem before actually training. I get that message :
    ValueError: When passing a list as loss, it should have one entry per model outputs. The model has 4 outputs, but you passed loss=[<yolov3_tf2.yolo_models.YoloLoss object at 0x7f27ac0fbfd0>, <yolov3_tf2.yolo_models.YoloLoss object at 0x7f27c00817b8>, <yolov3_tf2.yolo_models.YoloLoss object at 0x7f26fb53a390>]
    The model outputs the bbox, scores, classes and valid detections, but there are 3 losses (1 per anchor mask).

VeeranjaneyuluToka commented 3 years ago

Hi, you have to call this line train_dataset = train_dataset.batch(batch_size) to get rid off the above error as it adds new dimension to your input.