简体   繁体   English

当我尝试将 model 保存到 tflite 时,Model object 没有属性“_is_graph_network”

[英]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.

相关问题 将Keras模型导出到TensorFlow时,``顺序''对象没有属性'_is_graph_network' - 'Sequential' object has no attribute '_is_graph_network' when exporting Keras model to TensorFlow 'str' object 在将.model 转换为 tflite 文件时没有属性 'call' - 'str' object has no attribute 'call' when converting .model to tflite file 模型对象没有属性保存 - Model object has no attribute save 当我尝试保存模型时,gensim lda权限被拒绝 - gensim lda permission denied when I try to save my model 当我尝试保存聊天机器人时收到警告 model - getting warning when I try to save my chatbot model “顺序”对象没有“损失”属性 - 当我使用 GridSearchCV 调整我的 Keras 模型时 - 'Sequential' object has no attribute 'loss' - When I used GridSearchCV to tuning my Keras model Django模型表单保存,“ int”对象没有属性“ save” - Django model form save, 'int' object has no attribute 'save' 模型对象在减小 CoreML 大小的同时没有保存属性? - Model object has no attribute save while reducing size of CoreML? Django 模型保存 () - AttributeError: 'NoneType' 对象没有属性 'append' - Django model save() - AttributeError: 'NoneType' object has no attribute 'append' 即使使用顺序 model,我也会收到“AttributeError: 'Model' object has no attribute 'predict_classes'” - Even when using Sequential model, I am getting “AttributeError: 'Model' object has no attribute 'predict_classes' ”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM