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

AssertionError: failed to read all data #58

Open akshayjaryal603 opened 4 years ago

akshayjaryal603 commented 4 years ago

Hi, @hunglc007

I trained my custom object detector through darknet custom object detection but when I run the "detectvideo.py" using my custom object detector .weights then I got this issue. Help needed I am stuck the whole weekend in same issue. I change the coco.names file also. But else I have to edit in the existing code for running the code successfully.

File "detectvideo.py", line 146, in app.run(main) File "/home/akshay/anaconda3/lib/python3.7/site-packages/absl/app.py", line 299, in run _run_main(main, args) File "/home/akshay/anaconda3/lib/python3.7/site-packages/absl/app.py", line 250, in _run_main sys.exit(main(argv)) File "detectvideo.py", line 77, in main utils.load_weights(model, FLAGS.weights) File "/home/akshay/tensorflow-yolov4-tflite/core/utils.py", line 122, in load_weights assert len(wf.read()) == 0, 'failed to read all data' AssertionError: failed to read all data

netqyq commented 4 years ago

I had the same issue.

akshayjaryal603 commented 4 years ago

@netqyq Have you solved the issue? @hunglc007 Please help!

netqyq commented 4 years ago

No, I haven't. @akshayjaryal603

cheolgyu commented 4 years ago

I had the same issue.

varad-more commented 4 years ago

I'm getting same error, anyone got it solved? I was trying with yolov3-tiny trained with custom anchors and dataset. I've changed in core/config.py file.

netqyq commented 4 years ago

@akshayjaryal603 @cheolgyu @varad-more

I have solved the problem, because the weights file, if you specify a wrong weights file which has unmatched structure with your own model, it will not be read in.

I trained my model using darknet(compiled C program), in this way you can get a correct weight file, then using this weigh file in this project.

All in all, the weights file must be matched with the model structure.

varad-more commented 4 years ago

@akshayjaryal603 @cheolgyu @varad-more

I have solved the problem, because the weights file, if you specify a wrong weights file which has unmatched structure with your own model, it will not be read in.

I trained my model using darknet(compiled C program), in this way you can get a correct weight file, then using this weigh file in this project.

All in all, the weights file must be matched with the model structure.

It worked for me in case of yolov3 but no good with v3 tiny.

akshayjaryal603 commented 4 years ago

@akshayjaryal603 @cheolgyu @varad-more

I have solved the problem, because the weights file, if you specify a wrong weights file which has unmatched structure with your own model, it will not be read in.

I trained my model using darknet(compiled C program), in this way you can get a correct weight file, then using this weigh file in this project.

All in all, the weights file must be matched with the model structure.

@netqyq have you tried with the custom object detection trained model or you trained with Yolov4 pretrained model.

I think for the custom trained models we have to change the .cfg file according to the training. But I haven't found any .cfg file to edit in the code.

akshayjaryal603 commented 4 years ago

@akshayjaryal603 @cheolgyu @varad-more I have solved the problem, because the weights file, if you specify a wrong weights file which has unmatched structure with your own model, it will not be read in. I trained my model using darknet(compiled C program), in this way you can get a correct weight file, then using this weigh file in this project. All in all, the weights file must be matched with the model structure.

It worked for me in case of yolov3 but no good with v3 tiny.

@varad-more please refer to the below GitHub link of Yolov3 implementation in OpenCV. If you have trained Yolov3 tiny weights and .cfg file then you have to make a few changes and you got the Inference results. https://github.com/akshayjaryal603/YOLO-Object-Detection-Project

varad-more commented 4 years ago

@varad-more please refer to the below GitHub link of Yolov3 implementation in OpenCV. If you have trained Yolov3 tiny weights and .cfg file then you have to make a few changes and you got the Inference results. https://github.com/akshayjaryal603/YOLO-Object-Detection-Project

Thank you @akshayjaryal603 , I was using cv2.dnn for predicting but I want to higher fps. That's why I need tensor-flow Implementation.

netqyq commented 4 years ago

@akshayjaryal603 @cheolgyu @varad-more I have solved the problem, because the weights file, if you specify a wrong weights file which has unmatched structure with your own model, it will not be read in. I trained my model using darknet(compiled C program), in this way you can get a correct weight file, then using this weigh file in this project. All in all, the weights file must be matched with the model structure.

@netqyq have you tried with the custom object detection trained model or you trained with Yolov4 pretrained model.

I think for the custom trained models we have to change the .cfg file according to the training. But I haven't found any .cfg file to edit in the code.

@akshayjaryal603 I am just using the default configuration, there is no cfg file, if you want to customize the structure, you have to change the code.

akshayjaryal603 commented 4 years ago

@varad-more please refer to the below GitHub link of Yolov3 implementation in OpenCV. If you have trained Yolov3 tiny weights and .cfg file then you have to make a few changes and you got the Inference results. https://github.com/akshayjaryal603/YOLO-Object-Detection-Project

Thank you @akshayjaryal603 , I was using cv2.dnn for predicting but I want to higher fps. That's why I need tensor-flow Implementation.

@varad-more I think cv2.dnn module is specially developed for the higher fps rate purpose and according to the Intel OpenCV inference using dnn module is 18X faster than Tensorflow. Correct me if I am wrong.

Best Regards, Akshay Jaryal

varad-more commented 4 years ago

@varad-more I think cv2.dnn module is specially developed for the higher fps rate purpose and according to the Intel OpenCV inference using dnn module is 18X faster than Tensorflow. Correct me if I am wrong.

Best Regards, Akshay Jaryal

@akshayjaryal603 thank you for suggesting, that's possible only if you build opencv with cuda cv.dnn.DNN_TARGET_CUDA I'm tried building from scratch, but still struggling with it. If you have a resource please share.

Thank you.

akshayjaryal603 commented 4 years ago

@varad-more follow this blog of Adrain PyImageSearch. Link below!

https://www.pyimagesearch.com/2020/02/03/how-to-use-opencvs-dnn-module-with-nvidia-gpus-cuda-and-cudnn/

iot-hunter commented 4 years ago
python detect.py --weights ./weights/yolov4.weights --framework tf --size 608 --image ./data/kite.jpg --tiny=False --model=yolov4

use this commnd

dongfang-steven-yang commented 4 years ago
python detect.py --weights ./weights/yolov4.weights --framework tf --size 608 --image ./data/kite.jpg --tiny=False --model=yolov4

use this commnd

Thanks a lot, it works! I guess the README should be updated. :+1: