Open wwdok opened 4 years ago
Did you run convert_tflite.py? The repo doesn't come with the model. I had to download the yolov4 weights and then ran the below command to generate the tflite file. Hope this helps.
python convert_tflite.py --weights ./data/yolov4.weights --output ./data/yolov4.tflite
Did you run convert_tflite.py? The repo doesn't come with the model. I had to download the yolov4 weights and then ran the below command to generate the tflite file. Hope this helps.
python convert_tflite.py --weights ./data/yolov4.weights --output ./data/yolov4.tflite
Thank you for your tip ! But the exported yolov4.tflite is 63040 KB. I think this is too large to intergrate into android app, it is not suitable and practical.
That's about the size I got. Still less than the 240MB of the original model. You could try changing the optimizes on line 69 of convert_tflite.py from converter.optimizations = [tf.lite.Optimize.DEFAULT] to converter.optimizations = [tf.lite.Optimize.OPTIMIZE_FOR_SIZE]. Or try tiny the tiny version of YOLO. Not sure if weights are available or you will have to train your own though.
That's about the size I got. Still less than the 240MB of the original model. You could try changing the optimizes on line 69 of convert_tflite.py from converter.optimizations = [tf.lite.Optimize.DEFAULT] to converter.optimizations = [tf.lite.Optimize.OPTIMIZE_FOR_SIZE]. Or try tiny the tiny version of YOLO. Not sure if weights are available or you will have to train your own though.
Is converter.optimizations = [tf.lite.Optimize.OPTIMIZE_FOR_SIZE]
effective for you ? For me, it still export the same big size yolov4.tflite. By the way, i also try the other two command line :
# yolov4 quantize float16
python convert_tflite.py --weights ./data/yolov4.weights --output ./data/yolov4-fp16.tflite --quantize_mode float16
# yolov4 quantize int8
python convert_tflite.py --weights ./data/yolov4.weights --output ./data/yolov4-fp16.tflite --quantize_mode full_int8 --dataset ./coco_dataset/coco/val207.txt
the first command line produce a more big tflite file which is 125,789 KB, the second command line has two errors: one is the --dataset path, another is after corect the dadaset path, the terminal report : RuntimeError: Max and min for dynamic tensors should be recorded during calibration
I have not tried optimize for size no. But thought it worth a try since it's an easy change.
Full int8 quantization requires a representative dataset so it can find the full dynamic range of each activation. So you'll need data for that. However, I didn't suggest it for your case as I don't think it will result in a smaller file since all the weights are already 8 bit in the regular tflite file. Full int 8 makes all the activations 8 bit as well, as far as my understanding of it.
@hunglc007 Can you update and fix the typo of #convert-to-tflite part
I have not tried optimize for size no. But thought it worth a try since it's an easy change.
Full int8 quantization requires a representative dataset so it can find the full dynamic range of each activation. So you'll need data for that. However, I didn't suggest it for your case as I don't think it will result in a smaller file since all the weights are already 8 bit in the regular tflite file. Full int 8 makes all the activations 8 bit as well, as far as my understanding of it.
Yeah, you reminds me ! The following screenshot is the content of representative dataset - val2017.txt. Does it mean in the folder of /media/user/Source/Data/coco_dataset/coco/images/val2017/, i got to have these real images, and what does the subsequent integers mean ?
Right, this is the file that points to where the files are located. The integers are the bounding boxes and the object class. I suggest studying on how YOLO works.
There are tools that can help label your own images. Like Vott. Or there are existing labelled data sets.
Right, this is the file that points to where the files are located. The integers are the bounding boxes and the object class. I suggest studying on how YOLO works.
There are tools that can help label your own images. Like Vott. Or there are existing labelled data sets.
@sterlingrpi I got it !Thanks !
I have not tried optimize for size no. But thought it worth a try since it's an easy change. Full int8 quantization requires a representative dataset so it can find the full dynamic range of each activation. So you'll need data for that. However, I didn't suggest it for your case as I don't think it will result in a smaller file since all the weights are already 8 bit in the regular tflite file. Full int 8 makes all the activations 8 bit as well, as far as my understanding of it.
Yeah, you reminds me ! The following scr eenshot is the content of representative dataset - val2017.txt. Does it mean in the folder of /media/user/Source/Data/coco_dataset/coco/images/val2017/, i got to have these real images, and what does the subsequent integers mean ?
u can chage func def representative_data_gen in convert_tflite.py file fimage = open(FLAGS.dataset).read().split() for input_value in range(1000): path = "path_to_image/"+fimage[input_value] if os.path.exists(path): print(fimage[input_value]) original_image=cv2.imread(path) original_image = cv2.cvtColor(original_image, cv2.COLOR_BGR2RGB) image_data = utils.image_preporcess(np.copy(original_image), [FLAGS.input_size, FLAGS.input_size]) img_in = image_data[np.newaxis, ...].astype(np.float32) print(input_value) yield [img_in] else: print(path) continue
@sterlingrpi where did you put the .tflite file?
@sterlingrpi where did you put the .tflite file?
I left it in the default data directory
@sterlingrpi how does it perform on your phone? I installed on Google Pixel XL, it painfully slow
@EuphoriaCelestial haven't tried on a phone. I'm running on RPi. But I can concur it is slow. You can try full int8 quantization and/or YOLO tiny. We are working on this in another thread. But it's a process https://github.com/hunglc007/tensorflow-yolov4-tflite/issues/53
我没有尝试优化尺寸。但是认为这是值得尝试的,因为这是一个容易的更改。 完整的int8量化需要一个有代表性的数据集,因此它可以找到每个激活的完整动态范围。因此,您将需要数据。但是,我没有针对您的情况提出建议,因为我认为这不会导致文件变小,因为常规tflite文件中的所有权重已为8位。据我所知,Full int 8也使所有激活都为8位。
是的,你提醒我!以下屏幕截图是代表性数据集的内容-val2017.txt。这是否意味着在/ media / user / Source / Data / coco_dataset / coco / images / val2017 /的文件夹中,我必须拥有这些真实图像,并且随后的整数是什么意思?
I also met the same problem. How did you solve it? thank you
I tried to build and install this repo‘s android app, but it reports the error:
Caused by: java.lang.RuntimeException: java.io.FileNotFoundException: yolov4full.tflite