mystic123 / tensorflow-yolo-v3

Implementation of YOLO v3 object detector in Tensorflow (TF-Slim)
https://medium.com/@pawekapica_31302/implementing-yolo-v3-in-tensorflow-tf-slim-c3c55ff59dbe
Apache License 2.0
890 stars 353 forks source link

Error: cannot reshape array of size 284695 into shape (256,128,3,3) #64

Closed Akshaypatil15 closed 4 years ago

Akshaypatil15 commented 5 years ago

Already saw #15 solution but didn't worked. I had made change in default yolov3.cfg file. Final layer consist of 24 filters instead if 255. my.cfg

layer filters size input output 74 Shortcut Layer: 71 75 conv 512 1 x 1 / 1 13 x 13 x1024 -> 13 x 13 x 512 0.177 BF 76 conv 1024 3 x 3 / 1 13 x 13 x 512 -> 13 x 13 x1024 1.595 BF 77 conv 512 1 x 1 / 1 13 x 13 x1024 -> 13 x 13 x 512 0.177 BF 78 conv 1024 3 x 3 / 1 13 x 13 x 512 -> 13 x 13 x1024 1.595 BF 79 conv 512 1 x 1 / 1 13 x 13 x1024 -> 13 x 13 x 512 0.177 BF 80 conv 1024 3 x 3 / 1 13 x 13 x 512 -> 13 x 13 x1024 1.595 BF 81 conv 24 1 x 1 / 1 13 x 13 x1024 -> 13 x 13 x 24 0.008 BF 82 yolo 83 route 79 84 conv 256 1 x 1 / 1 13 x 13 x 512 -> 13 x 13 x 256 0.044 BF 85 upsample 2x 13 x 13 x 256 -> 26 x 26 x 256 86 route 85 61 87 conv 256 1 x 1 / 1 26 x 26 x 768 -> 26 x 26 x 256 0.266 BF 88 conv 512 3 x 3 / 1 26 x 26 x 256 -> 26 x 26 x 512 1.595 BF 89 conv 256 1 x 1 / 1 26 x 26 x 512 -> 26 x 26 x 256 0.177 BF 90 conv 512 3 x 3 / 1 26 x 26 x 256 -> 26 x 26 x 512 1.595 BF 91 conv 256 1 x 1 / 1 26 x 26 x 512 -> 26 x 26 x 256 0.177 BF 92 conv 512 3 x 3 / 1 26 x 26 x 256 -> 26 x 26 x 512 1.595 BF 93 conv 24 1 x 1 / 1 26 x 26 x 512 -> 26 x 26 x 24 0.017 BF 94 yolo 95 route 91 96 conv 128 1 x 1 / 1 26 x 26 x 256 -> 26 x 26 x 128 0.044 BF 97 upsample 4x 26 x 26 x 128 -> 104 x 104 x 128 98 route 97 11 99 conv 128 1 x 1 / 1 104 x 104 x 256 -> 104 x 104 x 128 0.709 BF 100 conv 256 3 x 3 / 1 104 x 104 x 128 -> 104 x 104 x 256 6.380 BF 101 conv 128 1 x 1 / 1 104 x 104 x 256 -> 104 x 104 x 128 0.709 BF 102 conv 256 3 x 3 / 1 104 x 104 x 128 -> 104 x 104 x 256 6.380 BF 103 conv 128 1 x 1 / 1 104 x 104 x 256 -> 104 x 104 x 128 0.709 BF 104 conv 256 3 x 3 / 1 104 x 104 x 128 -> 104 x 104 x 256 6.380 BF 105 conv 24 1 x 1 / 1 104 x 104 x 256 -> 104 x 104 x 24 0.133 BF 106 yolo

yolov3.cfg

layer filters size input output
71 Shortcut Layer: 68 72 conv 512 1 x 1 / 1 13 x 13 x1024 -> 13 x 13 x 512 0.177 BF 73 conv 1024 3 x 3 / 1 13 x 13 x 512 -> 13 x 13 x1024 1.595 BF 74 Shortcut Layer: 71 75 conv 512 1 x 1 / 1 13 x 13 x1024 -> 13 x 13 x 512 0.177 BF 76 conv 1024 3 x 3 / 1 13 x 13 x 512 -> 13 x 13 x1024 1.595 BF 77 conv 512 1 x 1 / 1 13 x 13 x1024 -> 13 x 13 x 512 0.177 BF 78 conv 1024 3 x 3 / 1 13 x 13 x 512 -> 13 x 13 x1024 1.595 BF 79 conv 512 1 x 1 / 1 13 x 13 x1024 -> 13 x 13 x 512 0.177 BF 80 conv 1024 3 x 3 / 1 13 x 13 x 512 -> 13 x 13 x1024 1.595 BF 81 conv 255 1 x 1 / 1 13 x 13 x1024 -> 13 x 13 x 255 0.088 BF 82 yolo 83 route 79 84 conv 256 1 x 1 / 1 13 x 13 x 512 -> 13 x 13 x 256 0.044 BF 85 upsample 2x 13 x 13 x 256 -> 26 x 26 x 256 86 route 85 61 87 conv 256 1 x 1 / 1 26 x 26 x 768 -> 26 x 26 x 256 0.266 BF 88 conv 512 3 x 3 / 1 26 x 26 x 256 -> 26 x 26 x 512 1.595 BF 89 conv 256 1 x 1 / 1 26 x 26 x 512 -> 26 x 26 x 256 0.177 BF 90 conv 512 3 x 3 / 1 26 x 26 x 256 -> 26 x 26 x 512 1.595 BF 91 conv 256 1 x 1 / 1 26 x 26 x 512 -> 26 x 26 x 256 0.177 BF 92 conv 512 3 x 3 / 1 26 x 26 x 256 -> 26 x 26 x 512 1.595 BF 93 conv 255 1 x 1 / 1 26 x 26 x 512 -> 26 x 26 x 255 0.177 BF 94 yolo 95 route 91 96 conv 128 1 x 1 / 1 26 x 26 x 256 -> 26 x 26 x 128 0.044 BF 97 upsample 2x 26 x 26 x 128 -> 52 x 52 x 128 98 route 97 36 99 conv 128 1 x 1 / 1 52 x 52 x 384 -> 52 x 52 x 128 0.266 BF 100 conv 256 3 x 3 / 1 52 x 52 x 128 -> 52 x 52 x 256 1.595 BF 101 conv 128 1 x 1 / 1 52 x 52 x 256 -> 52 x 52 x 128 0.177 BF 102 conv 256 3 x 3 / 1 52 x 52 x 128 -> 52 x 52 x 256 1.595 BF 103 conv 128 1 x 1 / 1 52 x 52 x 256 -> 52 x 52 x 128 0.177 BF 104 conv 256 3 x 3 / 1 52 x 52 x 128 -> 52 x 52 x 256 1.595 BF 105 conv 255 1 x 1 / 1 52 x 52 x 256 -> 52 x 52 x 255 0.353 BF 106 yolo

I am also using custom anchors =>anchors = 41,11, 63,14, 87,18, 113,19, 143,27, 108,45, 166,44, 207,41, 267,74 So what changes should I do? Please help me. Thanking You.

xiayq1 commented 5 years ago

ValueError: cannot reshape array of size 291081 into shape (256,128,3,3)

I have met the same problem here:

I have change the cfg file : w ,height to 224,224 Then I change the src code:

placeholder for detector inputs

#inputs = tf.placeholder(tf.float32, [None, FLAGS.size, FLAGS.size, 3], "inputs")
inputs = tf.placeholder(tf.float32, [None, 224, 224, 3], "inputs")

Is there anyone who can solve the problem? Please help me. Thanking You.

gcharko2018 commented 5 years ago

I have seen the same issue with 1 class YoloV3 & tiny YoloV3. My conclusion is that the converter works without error only with standard Yolo configuartion -> COCO & VOC. My workaround is that I trained a 20 class (VOC) Yolov3 with just a single class. During inference I filter out all the other class erroneous detentions.

ashuezy commented 5 years ago

@gcharko2018 Did you fill you names file with dummy categories ?

gcharko2018 commented 5 years ago

@ashuezy Yes I did but you may leave them as they are except category 0 that is the custom name. Since categories >0 can be filtered out using 2 lines of code, the name of the other categories are never shown.

Akshaypatil15 commented 5 years ago

ValueError: cannot reshape array of size 291081 into shape (256,128,3,3)

I have met the same problem here:

I have change the cfg file : w ,height to 224,224 Then I change the src code:

placeholder for detector inputs

#inputs = tf.placeholder(tf.float32, [None, FLAGS.size, FLAGS.size, 3], "inputs")
inputs = tf.placeholder(tf.float32, [None, 224, 224, 3], "inputs")

Is there anyone who can solve the problem? Please help me. Thanking You.

@xiayq1 In my case, the cfg file contains default : w ,height as 416 ,416

Thank you guys for your efforts but I found that changing upsample strides=2 to strides=3 create problem. My other model which is basically trained on default strides=2 is successfully converted to ckpt file but with loss in accuracy.

karandeepdps commented 5 years ago

Change your labels.txt to appropriate length.

Akshaypatil15 commented 5 years ago

Change your labels.txt to appropriate length.

Thank you.. but already checked label.txt and removed all possible blank newline... Issue was number of upsample strides in cfg file.

abuzahid commented 4 years ago

This happens for problem in (.names) file. You should check tow things to solve this.

  1. If you are training on all classes please check if there is extra new line at the last of class names.
  2. If you have training on specific some classes please remove the extra class from (.names) file either you used all class names during training.
AbdoElfathi commented 4 years ago

just set the number of classes with number of classes that you have in convert.py