hunglc007 / tensorflow-yolov4-tflite

YOLOv4, YOLOv4-tiny, YOLOv3, YOLOv3-tiny Implemented in Tensorflow 2.0, Android. Convert YOLO v4 .weights tensorflow, tensorrt and tflite
https://github.com/hunglc007/tensorflow-yolov4-tflite
MIT License
2.24k stars 1.24k forks source link

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

Open Ryotarosaba opened 3 years ago

Ryotarosaba commented 3 years ago

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.

ehsansouri23 commented 3 years ago

any update?

ryotaro137 commented 3 years ago

No、same condition.

nagi1995 commented 3 years ago

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 commented 3 years ago

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
HosseinMohammadii commented 3 years ago

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

haimin777 commented 2 years ago

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

ryotaro137 commented 2 years ago

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.

nagi1995 commented 2 years ago

This should help

ryotaro137 commented 2 years ago

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 commented 2 years ago

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.