【问题标题】:Converting h5 to tflite [closed]将 h5 转换为 tflite [关闭]
【发布时间】:2022-12-22 02:02:34
【问题描述】:

我一直在尝试将这个零样本文本分类joeddav / xlm-roberta-large-xnli从h5转换为tflite文件(https://huggingface.co/joeddav/xlm-roberta-large-xnli),但是弹出这个错误并且我在网上找不到它的描述,它是如何修复的?如果不能,是否有另一个我可以使用的零样本文本分类器即使在成为 tflite 之后也能产生类似的准确性?

AttributeError: 'T5ForConditionalGeneration' object has no attribute 'call'

我一直在尝试一些不同的教程,而我目前拥有的 google colab 文件是其中几个的混合体。 https://colab.research.google.com/drive/1sYQJqvhM_KEvMt2IP15d8Ud9L-ApiYv6?usp=sharing

【问题讨论】:

    标签: tensorflow tensorflow-lite huggingface-transformers text-classification huggingface


    【解决方案1】:

    [将 TFLite 从保存的 .h5 模型转换为 TFLite 模型]

    转换使用tflite convert有多种方式

    1. TF-Lite 转换器TF-Lite convertor
    2. TF.Lite.TFLiteConverter 或其他

      从目前提供的链接中,他们尝试将保存的模型 .h5 转换为 TFLite,以确认他们的问题。

      [ 样本 ]:

      """""""""""""""""""""""""""""""""""""""""""""""""""""""""
      : Model Initialize
      """""""""""""""""""""""""""""""""""""""""""""""""""""""""
      model = tf.keras.models.Sequential([
          tf.keras.layers.InputLayer(input_shape=( 32, 32, 3 )),
          tf.keras.layers.Dense(128, activation='relu'),
      ])
      model.compile(optimizer='sgd', loss='mean_squared_error') # compile the model
      model.summary()
      
      model.save_weights(checkpoint_path)
      
      """""""""""""""""""""""""""""""""""""""""""""""""""""""""
      : FileWriter
      """""""""""""""""""""""""""""""""""""""""""""""""""""""""
      if exists(checkpoint_path) :
          model.load_weights(checkpoint_path)
          print("model load: " + checkpoint_path)
      
      
      tf_lite_model_converter = tf.lite.TFLiteConverter.from_keras_model(
          model
      ) # <tensorflow.lite.python.lite.TFLiteKerasModelConverterV2 object at 0x0000021095194E80>
      tflite_model = tf_lite_model_converter.convert()
      
      # Save the model.
      with open(checkpoint_dir + '\model.tflite', 'wb') as f:
          f.write(tflite_model)
      

    【讨论】:

      猜你喜欢
      • 2020-09-10
      • 2020-10-10
      • 1970-01-01
      • 2019-04-14
      • 2020-12-15
      • 2021-06-11
      • 2021-12-09
      • 2019-06-10
      • 2021-11-30
      相关资源
      最近更新 更多