Skip to Main Content
机器学习设计模式
book

机器学习设计模式

by Valliappa Lakshmanan, Sara Robinson, Michael Munn
September 2022
Beginner to intermediate content levelBeginner to intermediate
386 pages
7h 36m
Chinese
Southeast University Press
Content preview from 机器学习设计模式
具有弹性服务的设计模式
235
converter = tf.lite.TFLiteConverter.from_keras_model(model)
converter.optimizations = [tf.lite.Optimize.DEFAULT]
tflite_model = converter.convert()
open('converted_model.tflite', 'wb').write(tflite_model)
这是训练后量化模型的最快方法。使用
TF Lite
优化的默认设置,它将使模型的权值
减少到
8
位表示。当采用模型进行预测时,它还将在推理时量化输入。通过运行上面
的代码,最终导出的
TF Lite
模型的大小是不进行量化就导出时的四分之一。
为了进一步优化离线推理模型,还可以在训练期间量化模型权值,或除了权
值还量化模型所有的数学运算。在撰写本书时,
TensorFlow 2
模型的量化优
化训练已在路线图上(
https://oreil.ly/RuONn
)。
要在
TF Lite
模型上生成预测,可以使用
TF Lite
解释器,该解释器针对低延迟进行
了优化。你可能希望在
Android
iOS
设备上加载模型,并直接从你的应用程序生
成预测。这两种平台都有
API
,但是我们将在这里展示用于生成预测的
Python
代码,
以便你可以在创建模型的同一个
notebook
上运行它。首先,创建
TF Lite
解释器的一
个实例,并获取期望的输入和输出格式的详细信息:
interpreter = tf.lite.Interpreter(model_path="converted_model.tflite") ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

PyTorch深度学习

PyTorch深度学习

Posts & Telecom Press, Vishnu Subramanian
数据科学原理

数据科学原理

Posts & Telecom Press, Sinan Ozdemir
Rust程序设计

Rust程序设计

Jim Blandy, Jason Orendorff, Leonora F. S. Tindall

Publisher Resources

ISBN: 9787564196776