Giter Site home page Giter Site logo

Comments (15)

sterlingrpi avatar sterlingrpi commented on May 17, 2024

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

from tensorflow-yolov4-tflite.

wwdok avatar wwdok commented on May 17, 2024

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.

from tensorflow-yolov4-tflite.

sterlingrpi avatar sterlingrpi commented on May 17, 2024

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.

from tensorflow-yolov4-tflite.

wwdok avatar wwdok commented on May 17, 2024

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

from tensorflow-yolov4-tflite.

sterlingrpi avatar sterlingrpi commented on May 17, 2024

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.

from tensorflow-yolov4-tflite.

wwdok avatar wwdok commented on May 17, 2024

@hunglc007 Can you update and fix the typo of #convert-to-tflite part

from tensorflow-yolov4-tflite.

wwdok avatar wwdok commented on May 17, 2024

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 ?
Yxx6b9.png

from tensorflow-yolov4-tflite.

sterlingrpi avatar sterlingrpi commented on May 17, 2024

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.

from tensorflow-yolov4-tflite.

wwdok avatar wwdok commented on May 17, 2024

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 !

from tensorflow-yolov4-tflite.

nightfuryyy avatar nightfuryyy commented on May 17, 2024

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 ?
Yxx6b9.png

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

from tensorflow-yolov4-tflite.

EuphoriaCelestial avatar EuphoriaCelestial commented on May 17, 2024

@sterlingrpi where did you put the .tflite file?

from tensorflow-yolov4-tflite.

sterlingrpi avatar sterlingrpi commented on May 17, 2024

@sterlingrpi where did you put the .tflite file?

I left it in the default data directory

from tensorflow-yolov4-tflite.

EuphoriaCelestial avatar EuphoriaCelestial commented on May 17, 2024

@sterlingrpi how does it perform on your phone? I installed on Google Pixel XL, it painfully slow

from tensorflow-yolov4-tflite.

sterlingrpi avatar sterlingrpi commented on May 17, 2024

@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 #53

from tensorflow-yolov4-tflite.

codeman008 avatar codeman008 commented on May 17, 2024

我没有尝试优化尺寸。但是认为这是值得尝试的,因为这是一个容易的更改。
完整的int8量化需要一个有代表性的数据集,因此它可以找到每个激活的完整动态范围。因此,您将需要数据。但是,我没有针对您的情况提出建议,因为我认为这不会导致文件变小,因为常规tflite文件中的所有权重已为8位。据我所知,Full int 8也使所有激活都为8位。

是的,你提醒我!以下屏幕截图是代表性数据集的内容-val2017.txt。这是否意味着在/ media / user / Source / Data / coco_dataset / coco / images / val2017 /的文件夹中,我必须拥有这些真实图像,并且随后的整数是什么意思?
Yxx6b9.png

I also met the same problem. How did you solve it? thank you

from tensorflow-yolov4-tflite.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.