I have got some problem for the below code of the following line new_model = load_model('124446.model', custom_objects=None, compile=True) Here is the code:
import tensorflow as tf
from tensorflow.keras.models import load_model
mnist = tf.keras.datasets.mnist
(x_train,y_train), (x_test,y_test) = mnist.load_data()
x_train = tf.keras.utils.normalize(x_train,axis=1)
x_test = tf.keras.utils.normalize(x_test,axis=1)
model = tf.keras.models.Sequential()
model.add(tf.keras.layers.Flatten())
model.add(tf.keras.layers.Dense(128,activation=tf.nn.relu))
model.add(tf.keras.layers.Dense(128,activation=tf.nn.relu))
model.add(tf.keras.layers.Dense(10,activation=tf.nn.softmax))
model.compile(optimizer='adam',
loss='sparse_categorical_crossentropy',
metrics=['accuracy'])
model.fit(x_train,y_train,epochs=3)
tf.keras.models.save_model(model,'124446.model')
val_loss, val_acc = model.evaluate(x_test,y_test)
print(val_loss, val_acc)
new_model = load_model('124446.model', custom_objects=None, compile=True)
prediction = new_model.predict([x_test])
print(prediction)
Errors are:
Traceback (most recent call last): File "C:/Users/TanveerIslam/PycharmProjects/DeepLearningPractice/1.py", line 32, in new_model = load_model('124446.model', custom_objects=None, compile=True) File "C:\Users\TanveerIslam\PycharmProjects\DeepLearningPractice\venv\lib\site-packages\tensorflow\python\keras\engine\saving.py", line 262, in load_model sample_weight_mode=sample_weight_mode) File "C:\Users\TanveerIslam\PycharmProjects\DeepLearningPractice\venv\lib\site-packages\tensorflow\python\training\checkpointable\base.py", line 426, in _method_wrapper method(self, *args, **kwargs) File "C:\Users\TanveerIslam\PycharmProjects\DeepLearningPractice\venv\lib\site-packages\tensorflow\python\keras\engine\training.py", line 525, in compile metrics, self.output_names)
AttributeError: 'Sequential' object has no attribute 'output_names'
So can any one give me ant solution.
Note: I use pycharm as IDE.