tensorflow-yolov4-tflite
tensorflow-yolov4-tflite copied to clipboard
ValueError: cannot reshape array of size 2048 into shape (18,1024,1,1)
Hi,
I am trying to convert my custom YOLOv4 weights to TF using below command-
python save_model.py --weights ./data/yolo-obj_best.weights --output ./checkpoints/yolov4-704 --input_size 704 --model yolov4
But getting below error-
File "save_model.py", line 58, in <module> app.run(main) File "/usr/local/lib/python3.6/dist-packages/absl/app.py", line 299, in run _run_main(main, args) File "/usr/local/lib/python3.6/dist-packages/absl/app.py", line 250, in _run_main sys.exit(main(argv)) File "save_model.py", line 54, in main save_tf() File "save_model.py", line 49, in save_tf utils.load_weights(model, FLAGS.weights, FLAGS.model, FLAGS.tiny) File "/content/drive/My Drive/kaggle/tensorflow-yolov4-tflite/core/utils.py", line 63, in load_weights conv_weights = conv_weights.reshape(conv_shape).transpose([2, 3, 1, 0]) ValueError: cannot reshape array of size 2048 into shape (18,1024,1,1)
I have only one class in my data/classes/obj.names file- obj.txt
Please suggest how to solve this error.
Me as well, but with yolov4-tiny!
@vladimirhorvat I am able to successfully do the conversion but using below repository- https://github.com/david8862/keras-YOLOv3-model-set
Thank you. It's a good lead, although it doesn't work for tiny.
Any resolutions to this. My change from the default instructions at https://github.com/AlexeyAB/darknet#how-to-train-to-detect-your-custom-objects is to also include the changes recommended in "for training for small objects" which is part of https://github.com/AlexeyAB/darknet#how-to-improve-object-detection
@tobymcclean I recommend you to use following repo- https://github.com/david8862/keras-YOLOv3-model-set
The author of above repo is more active and replies asap. With this repo, I am able to convert my custom YOLOv4 into keras model.
I've just got exactly the same issue trying to convert tiny weights file trained with custom dataset following the instructions at https://github.com/AlexeyAB/darknet#how-to-train-to-detect-your-custom-objects and to convert weights to checkpoint I defined class list in the file data/classes/custom.names (one class per line) and pointed the code to use this classes here: https://github.com/hunglc007/tensorflow-yolov4-tflite/blob/master/core/config.py#L14 After this change convert succeeded
I've just got exactly the same issue trying to convert tiny weights file trained with custom dataset following the instructions at https://github.com/AlexeyAB/darknet#how-to-train-to-detect-your-custom-objects and to convert weights to checkpoint I defined class list in the file data/classes/custom.names (one class per line) and pointed the code to use this classes here: https://github.com/hunglc007/tensorflow-yolov4-tflite/blob/master/core/config.py#L14 After this change convert succeeded
I can confirm this is the solution - @hunglc007 please add command line argument support inorder to provide classnames to avoid future issues
Getting the same issue but not still resolved by me. Any suggestions?
Getting the same issue but not still resolved by me. Any suggestions?
me to #193
I've just got exactly the same issue trying to convert tiny weights file trained with custom dataset following the instructions at https://github.com/AlexeyAB/darknet#how-to-train-to-detect-your-custom-objects and to convert weights to checkpoint I defined class list in the file data/classes/custom.names (one class per line) and pointed the code to use this classes here: https://github.com/hunglc007/tensorflow-yolov4-tflite/blob/master/core/config.py#L14 After this change convert succeeded
Thanks, this work for me!
I've just got exactly the same issue trying to convert tiny weights file trained with custom dataset following the instructions at https://github.com/AlexeyAB/darknet#how-to-train-to-detect-your-custom-objects and to convert weights to checkpoint I defined class list in the file data/classes/custom.names (one class per line) and pointed the code to use this classes here: https://github.com/hunglc007/tensorflow-yolov4-tflite/blob/master/core/config.py#L14 After this change convert succeeded
Please could you detail a bit more this? Is just to change the default coco.names with your own one?
Maybe it because of the absolute path makes things work.
I've just got exactly the same issue trying to convert tiny weights file trained with custom dataset following the instructions at https://github.com/AlexeyAB/darknet#how-to-train-to-detect-your-custom-objects and to convert weights to checkpoint I defined class list in the file data/classes/custom.names (one class per line) and pointed the code to use this classes here: https://github.com/hunglc007/tensorflow-yolov4-tflite/blob/master/core/config.py#L14 After this change convert succeeded
Thank you. Conversion and inference worked for me after correcting this.
I can confirm this is the solution - @hunglc007 please add command line argument support inorder to provide classnames to avoid future issues
Supposing you're using Colab this command modifies the file name !sed -i "s/coco.names/custom.names/g" /content/tensorflow-yolov4-tflite/core/config.py
Getting the same issue but not still resolved by me. Any suggestions?
When train darknet,did you edit your custom *.cfg based on yolov4-custom.cfg instead of yolov4.cfg? There are some different in these two cfg data. You can edit your custom cfg based on yolov4.cfg and train again,that is how I solve the issue.
try to check class names defines properly
More updated code hosted by theAIGuysCode https://github.com/theAIGuysCode/tensorflow-yolov4-tflite. Has the instructions with images on what to change for the names when custom training.
I still don't understand how to solve this problem, can anyone explain it to me? Thanks
I had the same question like this,I tried all the suggestion above this coment,but still not got solved.... Had checked config.py "__C.YOLO.CLASSES = "./data/classes/*.names"" and *.names is just one class per line.(My calss id only one class lol) I also train my weights again followed Alexey's git . but it don't work...... anyone can help me ? Thanks.
I used black and white images to train, which means that I had to change the channel number to 1 in input_layer, line 19 in save_model.py:
input_layer = tf.keras.layers.Input([FLAGS.input_size, FLAGS.input_size, 1])
Simple solution Add the bellow code into /content/yolov4-deepsort/core/config.py ''' from easydict import EasyDict as edict
__C = edict()
Consumers can get config by: from config import cfg
cfg = __C
YOLO options
__C.YOLO = edict()
__C.YOLO.CLASSES = "./data/classes/coco.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
Train options
__C.TRAIN = edict()
__C.TRAIN.ANNOT_PATH = "./data/dataset/val2017.txt" __C.TRAIN.BATCH_SIZE = 2
__C.TRAIN.INPUT_SIZE = [320, 352, 384, 416, 448, 480, 512, 544, 576, 608]
__C.TRAIN.INPUT_SIZE = 416 __C.TRAIN.DATA_AUG = True __C.TRAIN.LR_INIT = 1e-3 __C.TRAIN.LR_END = 1e-6 __C.TRAIN.WARMUP_EPOCHS = 2 __C.TRAIN.FISRT_STAGE_EPOCHS = 20 __C.TRAIN.SECOND_STAGE_EPOCHS = 30
TEST options
__C.TEST = edict()
__C.TEST.ANNOT_PATH = "./data/dataset/val2017.txt" __C.TEST.BATCH_SIZE = 2 __C.TEST.INPUT_SIZE = 416 __C.TEST.DATA_AUG = False __C.TEST.DECTECTED_IMAGE_PATH = "./data/detection/" __C.TEST.SCORE_THRESHOLD = 0.25 __C.TEST.IOU_THRESHOLD = 0.5 '''
Thanks a lot!
Joel Jacob @.***> 於 2022年3月30日 週三 15:46 寫道:
Hi,
I am trying to convert my custom YOLOv4 weights to TF using below command- python save_model.py --weights ./data/yolo-obj_best.weights --output ./checkpoints/yolov4-704 --input_size 704 --model yolov4
But getting below error- File "save_model.py", line 58, in
app.run(main) File "/usr/local/lib/python3.6/dist-packages/absl/app.py", line 299, in run _run_main(main, args) File "/usr/local/lib/python3.6/dist-packages/absl/app.py", line 250, in _run_main sys.exit(main(argv)) File "save_model.py", line 54, in main save_tf() File "save_model.py", line 49, in save_tf utils.load_weights(model, FLAGS.weights, FLAGS.model, FLAGS.tiny) File "/content/drive/My Drive/kaggle/tensorflow-yolov4-tflite/core/utils.py", line 63, in load_weights conv_weights = conv_weights.reshape(conv_shape).transpose([2, 3, 1, 0]) ValueError: cannot reshape array of size 2048 into shape (18,1024,1,1) I have only one class in my data/classes/obj.names file- obj.txt https://github.com/hunglc007/tensorflow-yolov4-tflite/files/4924125/obj.txt
Please suggest how to solve this error.
I was facing the same error, I checked my config file where mistakenly changed the default number of filters, the default was 32 and I changed it to 21, when I corrected that, I was able to convert the model into tensorflow. Hope this helps.
— Reply to this email directly, view it on GitHub https://github.com/hunglc007/tensorflow-yolov4-tflite/issues/147#issuecomment-1082740343, or unsubscribe https://github.com/notifications/unsubscribe-auth/ATUJXHYAG27RPRVUS66YJMTVCQBDTANCNFSM4O2KWYCA . You are receiving this because you commented.Message ID: @.***>
Simple solution Add the bellow code into /content/yolov4-deepsort/core/config.py ''' from easydict import EasyDict as edict
__C = edict()
Consumers can get config by: from config import cfg
cfg = __C
YOLO options
__C.YOLO = edict()
__C.YOLO.CLASSES = "./data/classes/coco.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
Train options
__C.TRAIN = edict()
__C.TRAIN.ANNOT_PATH = "./data/dataset/val2017.txt" __C.TRAIN.BATCH_SIZE = 2
__C.TRAIN.INPUT_SIZE = [320, 352, 384, 416, 448, 480, 512, 544, 576, 608]
__C.TRAIN.INPUT_SIZE = 416 __C.TRAIN.DATA_AUG = True __C.TRAIN.LR_INIT = 1e-3 __C.TRAIN.LR_END = 1e-6 __C.TRAIN.WARMUP_EPOCHS = 2 __C.TRAIN.FISRT_STAGE_EPOCHS = 20 __C.TRAIN.SECOND_STAGE_EPOCHS = 30
TEST options
__C.TEST = edict()
__C.TEST.ANNOT_PATH = "./data/dataset/val2017.txt" __C.TEST.BATCH_SIZE = 2 __C.TEST.INPUT_SIZE = 416 __C.TEST.DATA_AUG = False __C.TEST.DECTECTED_IMAGE_PATH = "./data/detection/" __C.TEST.SCORE_THRESHOLD = 0.25 __C.TEST.IOU_THRESHOLD = 0.5 '''
Hi, thanks for the solution purposed. Still getting an error here. After applying this, the model shows the same error with different numbers. Now I have: cannot reshape array of size 28407 into shape (33,1024,1,1). I don't know what to do from here. Any help would be appreciated. Thanks
Hi, thanks for the solution purposed. Still getting an error here. After applying this, the model shows the same error with different numbers. Now I have: cannot reshape array of size 28407 into shape (33,1024,1,1). I don't know what to do from here. Any help would be appreciated. Thanks
Hi, thanks for the solution purposed. Still getting an error here. After applying this, the model shows the same error with different numbers. Now I have: cannot reshape array of size 28407 into shape (33,1024,1,1). I don't know what to do from here. Any help would be appreciated. Thanks
In tensorflow-yolov4-tflite
, you can make a copy of data/classes/coco.names
for later use. Then, overwrite your custom classes into coco.names