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
发布评论