Я следую руководству от Sentdex, однако я попытался загрузить сохраненную модель из нового файла (run_test.py) и столкнулся со следующей ошибкой.
ValueError: Could not find matching function to call loaded from the SavedModel.
Got:
Positional arguments (1 total):
* Tensor("inputs:0", shape=(None, 28, 28), dtype=uint8)
Keyword arguments: {}
Expected these arguments to match one of the following 1 option(s):
Option 1:
Positional arguments (1 total):
* TensorSpec(shape=(None, 28, 28), dtype=tf.float32, name='inputs')
Keyword arguments: {}
main.py
import tensorflow as tf
import numpy as np
mnist = tf.keras.datasets.mnist
(x_train, y_train), (x_test, y_test) = mnist.load_data()
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=1) # run the training process 3 times
val_loss, val_acc = model.evaluate(x_test, y_test)
model.save('num_reader_basic.model')
run_test.py
import tensorflow as tf
import numpy as np
mnist = tf.keras.datasets.mnist
(x_train, y_train), (x_test, y_test) = mnist.load_data()
new_model = tf.keras.models.load_model('num_reader_basic.model')
predictions = new_model.predict(x_test)
print(np.argmax(predictions[0]))
При запуске команды загрузки в том же файле, что и обучающий файл модели (main.py), она не вызывает никаких ошибок, а вызывает ошибку только при запуске из отдельного файла. Есть ли ошибки во втором файле (run_test.py) или есть какие-то другие методы загрузки сохраненной модели из нового файла?