tensorflow-yolov4-tflite: 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.

About this issue

  • Original URL
  • State: open
  • Created 4 years ago
  • Reactions: 5
  • Comments: 25

Most upvoted comments

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

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.

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 ‘’’

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?

@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.

Me as well, but with yolov4-tiny!