pb模型转tflite(fp16, uint8)

本文介绍了如何将TensorFlow的.pb模型转换为TFLite格式,包括转换为半精度(FP16)和Uint8量化模型。详细步骤涵盖了从.pb模型的转换到TFLite模型的调用。
摘要由CSDN通过智能技术生成

@[TOC](pb模型转tflite(fp16, uint8))

pb模型转tflite

def convert_pb_into_tflite_file():
    
    # create a session
    input_tensor_name=["pb网络输入名"]
    input_tensor_shape={
   "pb网络输入名":[x,x,x,x]} #输入shape
    
    out_tensor_name = ["pb网络输出名"]
    converter = tf.lite.TFLiteConverter.from_frozen_graph(pb_PATH,
                                            input_tensor_name, out_tensor_name,
                                            input_shapes = input_tensor_shape)
    tflite_model = converter.convert()
    with open(OUTPUT_FILE_PATH,"wb") as f:
        f.write(tflite_model)

pb模型转tflite-fp16

def convert_pb_into_tflite_file():
    
    # create a session
    input_tensor_name=["pb网络输入名"]
    input_tensor_shape={
   "pb网络输入名":[x,x,x,x]} #输入shape
    
    out_tensor_name = ["pb网络输出名"]
    converter 
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要将TFLite模型从uint8换为int8,你可以按照以下步骤进行操作: 1. 首先,确保你已经使用TFLiteConverter将模型换为uint8格式。参考引用中的代码,你可以使用`TFLiteConverter.from_frozen_graph()`方法将模型换为uint8格式,并将`inference_type`设置为`tf.uint8`。 2. 在换为uint8格式后,你可以使用以下代码将模型换为int8格式: ```python import tensorflow as tf # 读取之前换好的uint8模型 tflite_uint8_model = open("uint8.tflite", "rb").read() # 加载uint8模型 interpreter = tf.lite.Interpreter(model_content=tflite_uint8_model) # 设置输入输出数据类型为int8 interpreter.allocate_tensors() interpreter.quantization = {'input_type': tf.int8} # 将模型换为int8格式 tflite_int8_model = interpreter.convert() # 保存换后的int8模型 open("int8.tflite", "wb").write(tflite_int8_model) ``` 通过以上步骤,你可以将TFLite模型从uint8换为int8格式。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* [Tensorflow模型量化4 --pbtflite(uint8量化)小结](https://blog.csdn.net/qq_36387683/article/details/108107714)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *3* [keras的.h5文件换为.tflite文件](https://blog.csdn.net/always115/article/details/129599804)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值