[英]Model object has no attribute '_is_graph_network', when I try to save my model to tflite
Tensorflow version - 1.14.0 Python version - 3.7.5 Tensorflow 版本 - 1.14.0 Python 版本 - 3.7.5
This is the model I created这是我创建的 model
from tensorflow import keras
import tensorflow.python.keras.backend as K
from tensorflow.python.keras import callbacks
from tensorflow.python.keras import Sequential
from tensorflow.python.keras.models import Model
from tensorflow.python.keras.layers import Conv2D, MaxPooling2D, Flatten, Dense, Dropout, BatchNormalization, GlobalAveragePooling2D
from tensorflow.python.keras.preprocessing.image import ImageDataGenerator
from tensorflow.python.keras.callbacks import ModelCheckpoint, EarlyStopping
def create_model_v1():
model = keras.Sequential()
model.add(Conv2D(filters = 64, kernel_size = 3, padding='same', activation = 'relu', input_shape=(img_rows, img_cols, color_type)))
model.add(MaxPooling2D(pool_size = 2))
model.add(Conv2D(filters = 128, padding='same', kernel_size = 3, activation = 'relu'))
model.add(MaxPooling2D(pool_size = 2))def create_model_v1():
model_v1 = create_model_v1()
history_v1 = model_v1.fit(x_train, y_train,
validation_data=(x_test, y_test),callbacks=callbacks,
epochs=nb_epoch, batch_size=batch_size, verbose=1)
This is the code for exporting into tflite:这是导出到 tflite 的代码:
keras_file = 'saved_models/history1.h5'
keras.models.save_model(history_v1, keras_file)
converter = tf.lite.TocoConverter.from_keras_model_file(keras_file)
tflite_model = converter.convert()
open('linear.tflite', 'wb').write(tflite_model)
This is the error:这是错误:
'History' object has no attribute '_is_graph_network'
'历史' object 没有属性 '_is_graph_network'
You need to pass model_v1
to converter, not history_v1
.您需要将
model_v1
传递给转换器,而不是history_v1
。
https://www.tensorflow.org/lite/convert/python_api#converting_a_keras_model_ https://www.tensorflow.org/lite/convert/python_api#converting_a_keras_model_
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.