TensorFlow Lite Converter เป็นตัวแปลงโมเดล TensorFlow ตัวเต็ม ให้ย่อลงมาเป็นโมเดลขนาดเล็ก ที่ทำงานได้รวดเร็ว สำหรับรันกับ Interpreter บนอุปกรณ์ Edge Device ที่มี Resource จำกัด ด้วยเทคนิค Quantization โดยพิจารณาจาก Hardware ปลายทาง ที่จะนำโมเดลไป Deploy เช่น อุปกรณ์ IoT Device, มือถือ Mobile, Microcontroller ต่าง ๆ

TensorFlow Lite Converter คืออะไร

android gpu deligate demo.  Credit https://www.tensorflow.org/lite/performance/gpu
android gpu deligate demo. Credit https://www.tensorflow.org/lite/performance/gpu

TensorFlow Lite Converter จะแปลงโมเดล TensorFlow ไปเป็นไฟล์ TensorFlow Lite FlatBuffer (ไฟล์นามสกุล .tflite) โดยรองรับโมเดลต้นทางในรูปแบบ SavedModel, tf.keras, และ Concrete Function

เราจะนำไฟล์ FlatBuffer ของ TensorFlow Lite ไป Deploy บนอุปกรณ์ที่ต้องการ แล้วรันด้วย TensorFlow Lite Inteprter สำหรับ Platform นั้น ๆ ดังกระบวนการด้านล่าง

The TensorFlow Lite converter takes a TensorFlow model and generates a TensorFlow Lite FlatBuffer file (.tflite). The converter supports SavedModel directories, tf.keras models, and concrete functions. Credit https://www.tensorflow.org/lite/convert
The TensorFlow Lite converter takes a TensorFlow model and generates a TensorFlow Lite FlatBuffer file (.tflite). The converter supports SavedModel directories, tf.keras models, and concrete functions. Credit https://www.tensorflow.org/lite/convert

Converting models

เราควรเรียกใช้ TensorFlow Lite Converter ด้วย Python API จากภายในโปรแกรม ซึ่งจะทำการแปลงโมเดลทำได้ง่าย และเป็นส่วนหนึ่งของ Model Deveopment Pipeline

การใช้ Python API มีข้อดีคือช่วยให้เรารู้ปัญหาเรื่อง Compatibility แต่เนิ่น ๆ ลดปัญหาในระยะยาว

และนอกจากนี้ เรายังสามารถใช้ Command Line Tools ในการ Convert โมเดลที่ไม่ซับซ้อนมากได้

เรามาเริ่มกันเลยดีกว่า

Open In Colab

แชร์ให้เพื่อน:

Surapong Kanoktipsatharporn on FacebookSurapong Kanoktipsatharporn on LinkedinSurapong Kanoktipsatharporn on Rss
Surapong Kanoktipsatharporn
Solutions Architect at Bua Labs
The ultimate test of your knowledge is your capacity to convey it to another.

Published by Surapong Kanoktipsatharporn

The ultimate test of your knowledge is your capacity to convey it to another.