As I try to covert my yolov4-tiny custom weight to tftile, it always happen.
This is what I input:
python save_model.py --weights ./data/yolov4-tiny-obj-food_final.weights --output ./checkpoints/yolov4-tiny-416-tflite --input_size 416 --model yolov4 --framework tflite
And the wrong message appear.
conv_weights = conv_weights.reshape(conv_shape).transpose([2, 3, 1, 0]) ValueError: cannot reshape array of size 374698 into shape (256,256,3,3)
I have checked my labels.txt and there is no space or more lines.Also, I have changed the name in config.py.
Is there any way to solve this problem?
Thanks for help!
Attach part of my code, hope it helps.
Here is github:https://github.com/piggychu0w0/food-image-detection
.cfg:
[convolutional] size=1 stride=1 pad=1 filters=21 activation=linear [yolo] mask = 3,4,5 anchors = 10,14, 23,27, 37,58, 81,82, 135,169, 344,319 classes=2 num=6 jitter=.3 scale_x_y = 1.05 cls_normalizer=1.0 iou_normalizer=0.07 iou_loss=ciou ignore_thresh = .7 truth_thresh = 1 random=0 resize=1.5 nms_kind=greedynms beta_nms=0.6
.names:
rice toast
Advertisement
Answer
Short answer
You have to add --tiny
to the command. Which, from the command you gave in the question, will be.
python save_model.py --weights ./data/yolov4-tiny-obj-food_final.weights --output ./checkpoints/yolov4-tiny-416-tflite --input_size 416 --model yolov4 --framework tflite --tiny
Long answer
You see, there’s this line that if you set it to True
(by adding --tiny
) it will make the load_weights()
uses layer_size = 21
here instead of layer_size = 110
here.
The problem here is that the weights you have and the np.fromfile
command actually give you a big chunk of 1 dimensional array, in this particular file it’s size is (5882629,)
, and then you have to allocate those variable one by one to the layers.
So, when you create the big model instead of tiny. The tiny weighs file runs out of the variable at 49th layers, and hilariously with such a big prime number.