TensorFlow Lite + PC

本文介绍了如何在Windows 10环境下,使用TensorFlow 2.3.1和Python 3.6安装TensorFlow Lite,并将基于TensorFlow训练的PB模型转换为Lite模型。内容包括模型转换的代码示例以及对Normalization和Quantization的解释。转换后的模型可用于TensorFlow Lite的推断过程。
摘要由CSDN通过智能技术生成

环境

  • Win10 x86 64
  • TensorFlow 2.3.1
  • Python3.6

目录

安装tflite

pip3 install https://dl.google.com/coral/python/tflite_runtime-2.1.0.post1-cp36-cp36m-win_amd64.whl

tflite下载地址平台版本对应

本机是intel的cpu但安装amd64也可以正常运行,毕竟windows里就没有x86的选项。

模型转换

将基于 TensorFlow 2.3.1训练得到的模型直接转换为 TensorFlow Lite 模型,官方指南,我的TensorFlow 模型是PB格式,转换代码如下:

import tensorflow as tf

if __name__ == '__main__':
    int_path = "TensorFlow_model_path_pb"
    out_path = ""

    # Converting a SavedModel to a TensorFlow Lite model.
    converter = tf.lite.TFLiteConverter.from_saved_model(int_path )
    #Normalization or quantization
    converter.post_training_quantize = True
    tflite_model = converter.convert()
    print(tflite_model)
    open(out_path, "wb").write(tflite_model)

其中有一个选项是Normalization and quantization pa

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值