tensorflow-yolov4-tflite icon indicating copy to clipboard operation
tensorflow-yolov4-tflite copied to clipboard

ValueError: cannot reshape array of size 5370 into shape (30,256,1,1)

Open Ryotarosaba opened this issue 3 years ago • 10 comments

I am facing the following error:

ValueError: cannot reshape array of size 5370 into shape (30,256,1,1)

What I did -Changed config.py as follows.

# YOLO options
__C.YOLO                      = edict()

__C.YOLO.CLASSES              = "./data/classes/obj.names"
__C.YOLO.ANCHORS              = [12,16, 19,36, 40,28, 36,75, 76,55, 72,146, 142,110, 192,243, 459,401]
__C.YOLO.ANCHORS_V3           = [10,13, 16,30, 33,23, 30,61, 62,45, 59,119, 116,90, 156,198, 373,326]
__C.YOLO.ANCHORS_TINY         = [23,27, 37,58, 81,82, 81,82, 135,169, 344,319]
__C.YOLO.STRIDES              = [8, 16, 32]
__C.YOLO.STRIDES_TINY         = [16, 32]
__C.YOLO.XYSCALE              = [1.2, 1.1, 1.05]
__C.YOLO.XYSCALE_TINY         = [1.05, 1.05]
__C.YOLO.ANCHOR_PER_SCALE     = 3
__C.YOLO.IOU_LOSS_THRESH      = 0.5

-The execution code is as follows.

!python save_model.py --weights ./data/yolov4_final.weights --output ./checkpoints/yolov4-512 --input_size 512 --model yolov4 
!python save_model.py --weights ./data/yolov4-tiny_custom_final.weights --output ./checkpoints/yolov4-tiny-416 --input_size 416 --model yolov4 --tiny true

-obj.names is as follows.

Can
Person
Bottle
Box

Would you please solve this problem? Thank you.

Ryotarosaba avatar Sep 16 '21 10:09 Ryotarosaba

any update?

ehsansouri23 avatar Sep 17 '21 13:09 ehsansouri23

No、same condition.

ryotaro137 avatar Sep 18 '21 11:09 ryotaro137

I have used this repo for converting my custom YOLO v4 tiny model to TensorFlow. I too faced the same error. When I dug deeper into code, by default the code in "./core/utils.py" is taking "./data/classes/coco.names" in line no. 78. I gave the path to my own "obj.names" and it worked. Please give the path of your "obj.names" or "*.names" in line no. 78 of "./core/utils.py".

Sample:

with open("path/to/your/obj.names", 'r') as data:

Or edit __C.YOLO.CLASSES = "path/to/your/obj.names" in config.py in line no. 14

nagi1995 avatar Sep 26 '21 04:09 nagi1995

To nagi1995 I made the correction as you pointed out. Then, I was able to execute it without any error! Thank you for your advice! !! !!

I have used this repo for converting my custom YOLO v4 tiny model to TensorFlow. I too faced the same error. When I dug deeper into code, by default the code in "./core/utils.py" is taking "./data/classes/coco.names" in line no. 78. I gave the path to my own "obj.names" and it worked. Please give the path of your "obj.names" or "*.names" in line no. 78 of "./core/utils.py".

Sample:

with open("path/to/your/obj.names", 'r') as data:

Or edit __C.YOLO.CLASSES = "path/to/your/obj.names" in config.py in line no. 14

ryotaro137 avatar Sep 26 '21 14:09 ryotaro137

@nagi1995 Thank you so much bro. It fixed that. you did me so much favor. @hunglc007 and please fix this bug.

HosseinMohammadii avatar Oct 04 '21 14:10 HosseinMohammadii

Check that there is no empty lines in your obj.names. That helps me.

haimin777 avatar Nov 23 '21 10:11 haimin777

I have same issue when I run save_model.py.

!python save_model.py \ --weights yolov4-tiny_ver3_final.weights \ --output ./checkpoints/yolov4-tiny_ver3 \ --input_size 416 \ --model yolov4 \ --tiny true \ --framework tflite error belows: image

Please help me.

ryotaro137 avatar Apr 04 '22 13:04 ryotaro137

This should help

nagi1995 avatar Apr 04 '22 13:04 nagi1995

Thank you. However, I am still getting the same error with this repo. Please let me know if there is another solution. Thank you in advance.

ryotaro137 avatar Apr 05 '22 01:04 ryotaro137

Sorry,the reason for the error was probably because the model was trained on my original cfg. (different number of convs). So, I need to rewrite YOLOv4_tiny in /core/yolov4.py.

ryotaro137 avatar Apr 05 '22 05:04 ryotaro137