h5转tflite解决:AttributeError: type object ‘TFLiteConverterV2‘ has no attribute ‘from

编程入门 行业动态 更新时间:2024-10-26 04:25:45

h5转tflite解决:<a href=https://www.elefans.com/category/jswz/34/1769517.html style=AttributeError: type object ‘TFLiteConverterV2‘ has no attribute ‘from"/>

h5转tflite解决:AttributeError: type object ‘TFLiteConverterV2‘ has no attribute ‘from

查阅:help(tf.lite.TFLiteConverter)

 |    # Converting a SavedModel to a TensorFlow Lite model.|    converter = lite.TFLiteConverter.from_saved_model(saved_model_dir)|    tflite_model = converter.convert()|  |    # Converting a tf.Keras model to a TensorFlow Lite model.|    converter = lite.TFLiteConverter.from_keras_model(model)|    tflite_model = converter.convert()|  |    # Converting ConcreteFunctions to a TensorFlow Lite model.|    converter = lite.TFLiteConverter.from_concrete_functions([func])|    tflite_model = converter.convert()

发现没有此方法
用model载入模型,改用TFLiteConverter.from_saved_model方法

model = generator()
model.load_weights('weights/srgan/gan_generator.h5')
converter = tf.lite.TFLiteConverter.from_keras_model(model)

完整代码

from keras.backend import clear_session
import numpy as np
import tensorflow as tf
from model.srgan import generator
clear_session()
np.set_printoptions(suppress=True)
input_graph_name = "./weights/srgan/gan_generator.h5"
output_graph_name = input_graph_name[:-3] + '.tflite'
model = generator()
model.load_weights('weights/srgan/gan_generator.h5')
converter = tf.lite.TFLiteConverter.from_keras_model(model)
converter.post_training_quantize = True
tflite_model = converter.convert()
open(output_graph_name, "wb").write(tflite_model)
print ("generate:",output_graph_name)

更多推荐

h5转tflite解决:AttributeError: type object ‘TFLiteConverterV2‘ has no attribute ‘fr

本文发布于:2024-02-07 05:31:55,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1753493.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:AttributeError   tflite   type   attribute   object

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!