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.25k stars 1.24k forks source link

Reshape error while running demo code. #85

Open saikrishnadas opened 4 years ago

saikrishnadas commented 4 years ago

python detect.py --weights ./data/yolov4.weights --framework tf --size 608 --image ./data/kite.jpg

ERROR LOG:

  File "/content/tensorflow-yolov4-tflite/core/utils.py", line 114, in load_weights
    conv_weights = conv_weights.reshape(conv_shape).transpose([2, 3, 1, 0])
ValueError: cannot reshape array of size 13979 into shape (128,128,3,3)
zateyev commented 4 years ago

Where did you download yolov4.weights? I have the same error with darknet yolov3.weights. The demo works fine with the weights: https://drive.google.com/open?id=1cewMfusmPjYWbrnuJRuKhPMwRe_b9PaT

saikrishnadas commented 4 years ago

@zateyev I did download it from that drive but still i get that error :(

osehmathias commented 4 years ago

@saikrishnadas @zateyev try changing the .names file in ./data/classes

karanpatel1993 commented 4 years ago

I am getting a similar error: ValueError: cannot reshape array of size 4576092 into shape (1024,512,3,3). I have trained a custom dataset on the darknet framework and wish to migrate it to tensorflow.

zateyev commented 4 years ago

@karanpatel1993 It seems you are just picking the wrong version. Try to run: python convert_tflite.py --weights ./data/yolov4.weights --output ./data/udl_tiny1.tflite --model yolov4

To convert a model trained on a custom dataset I've changed utils.load_weights(model, FLAGS.weights) to model.load_weights(FLAGS.weights).expect_partial() in convert_tflite.py and run python convert_tflite.py --weights ./checkpoints/yolov4 --output ./data/yolov4.tflite --model yolov4

saikrishnadas commented 4 years ago

@zateyev For me when i run the demo script detect.py on yolov4.weight file from the repo's drive and same error when I try to convert that weight into TensorRT :(

    conv_weights = conv_weights.reshape(conv_shape).transpose([2, 3, 1, 0])
ValueError: cannot reshape array of size 1665179 into shape (512,512,3,3) 
PJaderbrink commented 4 years ago

@saikrishnadas @zateyev try changing the .names file in ./data/classes

I can confirm that this works. I edited the coco.names and entered my classes from classes.txt that labelimg creates. Thanks alot!

saikrishnadas commented 4 years ago

@PJaderbrink I tried converting the original yolov4.weight file that was trained on coco dataset. So I think there isn't any need for me to change the coco.names :( Is there anything I can do to make it convert the weight ?

PJaderbrink commented 4 years ago

@PJaderbrink I tried converting the original yolov4.weight file that was trained on coco dataset. So I think there isn't any need for me to change the coco.names :( Is there anything I can do to make it convert the weight ?

Oh ok, in that case I don't know. I've not tried to convert the original weights, just a custom model.

saikrishnadas commented 4 years ago

@zateyev @mathiasjose @hunglc007 any updates on the issue? "Covert the original weight to tensorrt"

molimat commented 4 years ago

@saikrishnadas @zateyev try changing the .names file in ./data/classes

I had the same problem and it worked for me, actually I changed the config file so I won`t have to change coco.names, as I say here: https://github.com/hunglc007/tensorflow-yolov4-tflite/issues/82#issuecomment-650998273