Привет. Я пытаюсь сохранить свои «сохраненные модели» (файлы h5) в виде файла tenorflow. Это код, который я использовал.
import tensorflow as tf
def tensor_function(i):
tf.keras.backend.set_learning_phase(0) # Ignore dropout at inference
model = tf.keras.models.load_model('/home/ram/Downloads/AutoEncoderModels_ch2/19_hour/autoencoder_models_ram/auto_encoder_model_pos_' + str(i) + '.h5')
export_path = '/home/ram/Desktop/tensor/' + str(i)
#sess = tf.Session()
# Fetch the Keras session and save the model
# The signature definition is defined by the input and output tensors
# And stored with the default serving key
with tf.keras.backend.get_session() as sess:
tf.saved_model.simple_save(
sess,
export_path,
inputs={'input_image': model.input},
outputs={t.name: t for t in model.outputs})
sess.close()
for i in range(4954):
tensor_function(i)
Я попытался открыть сеанс вручную с помощью sess = tf.session()
(также удалено with
), но напрасно
И вышеупомянутая ошибка, которую я получил, когда использовал ноутбук Jupyter и запускал то же самое в терминале Linux. Я получаю следующую ошибку
tensorflow.python.framework.errors_impl.FailedPreconditionError: Error while reading resource variable dense_73/bias from Container: localhost. This could mean that the variable was uninitialized. Not found: Container localhost does not exist. (Could not find resource: localhost/dense_73/bias)
[[{{node dense_73/bias/Read/ReadVariableOp}} = ReadVariableOp[_class=["loc:@dense_73/bias"], dtype=DT_FLOAT, _device="/job:localhost/replica:0/task:0/device:CPU:0"](dense_73/bias)]]
И когда я пытался сохранить только один «сохраненный файл модели», он запускался успешно. Проблемы возникают только тогда, когда я пытаюсь запустить его в цикле (возможно, из-за проблем с сеансом).
Я пытался этот ответ в СО, но мало помог.