Я использую активацию LeakyReLU в моей модели.Я могу тренировать это.Но когда я тренируюсь, чтобы сохранить модель,
discriminator_model.save(os.path.join(output_folder_path, 'discriminator_model_{0}.h5'.format(iteration_no)))
я получаю ошибку ниже
AttributeError: 'LeakyReLU' object has no attribute '__name__'
Я использую keras-gpu 2.2.4 с бэкэндом tenorflow-gpu 1.12.0,Это моя модель:
discriminator_model = Sequential()
discriminator_model.add(Conv2D(64, 5, strides=2, input_shape=(28, 28, 1), padding='same', activation=LeakyReLU(alpha=0.2)))
discriminator_model.add(Dropout(0.4))
discriminator_model.add(Conv2D(128, 5, strides=2, padding='same'))
discriminator_model.add(LeakyReLU(alpha=0.2))
discriminator_model.add(Dropout(0.4))
discriminator_model.add(Conv2D(256, 5, strides=2, padding='same'))
discriminator_model.add(LeakyReLU(alpha=0.2))
discriminator_model.add(Dropout(0.4))
discriminator_model.add(Conv2D(512, 5, strides=2, padding='same'))
discriminator_model.add(LeakyReLU(alpha=0.2))
discriminator_model.add(Dropout(0.4))
discriminator_model.add(Flatten())
discriminator_model.add(Dense(1))
discriminator_model.add(Activation('sigmoid'))
discriminator_model.summary()
Изначально я использовал
discriminator_model.add(Conv2D(128, 5, strides=2, padding='same', activation=LeakyReLU(alpha=0.2)))
Но было предложено здесь и здесь , чтобы добавить LeakyReLUкак отдельный слой активации.Не повезло, даже после этого.
Полная трассировка стека:
Traceback (most recent call last):
File "/opt/PyCharm/pycharm-community-2018.3.3/helpers/pydev/pydevd.py", line 1741, in <module>
main()
File "/opt/PyCharm/pycharm-community-2018.3.3/helpers/pydev/pydevd.py", line 1735, in main
globals = debugger.run(setup['file'], None, None, is_module)
File "/opt/PyCharm/pycharm-community-2018.3.3/helpers/pydev/pydevd.py", line 1135, in run
pydev_imports.execfile(file, globals, locals) # execute the script
File "/opt/PyCharm/pycharm-community-2018.3.3/helpers/pydev/_pydev_imps/_pydev_execfile.py", line 18, in execfile
exec(compile(contents+"\n", file, 'exec'), glob, loc)
File "..../Workspace/src/v01/MnistTrainer.py", line 100, in <module>
main()
File "..../Workspace/src/v01/MnistTrainer.py", line 92, in main
mnist_trainer.train(train_steps=100, log_interval=1, save_interval=1)
File "..../Workspace/src/v01/MnistTrainer.py", line 56, in train
self.save_models(output_folder_path, i + 1)
File "..../Workspace/src/v01/MnistTrainer.py", line 69, in save_models
os.path.join(output_folder_path, 'discriminator_model_{0}.h5'.format(iteration_no)))
File "..../.conda/envs/e0_270_ml_3.6/lib/python3.6/site-packages/keras/engine/network.py", line 1090, in save
save_model(self, filepath, overwrite, include_optimizer)
File "..../.conda/envs/e0_270_ml_3.6/lib/python3.6/site-packages/keras/engine/saving.py", line 382, in save_model
_serialize_model(model, f, include_optimizer)
File "..../.conda/envs/e0_270_ml_3.6/lib/python3.6/site-packages/keras/engine/saving.py", line 83, in _serialize_model
model_config['config'] = model.get_config()
File "..../.conda/envs/e0_270_ml_3.6/lib/python3.6/site-packages/keras/engine/sequential.py", line 278, in get_config
'config': layer.get_config()
File "..../.conda/envs/e0_270_ml_3.6/lib/python3.6/site-packages/keras/layers/convolutional.py", line 493, in get_config
config = super(Conv2D, self).get_config()
File "..../.conda/envs/e0_270_ml_3.6/lib/python3.6/site-packages/keras/layers/convolutional.py", line 226, in get_config
'activation': activations.serialize(self.activation),
File "..../.conda/envs/e0_270_ml_3.6/lib/python3.6/site-packages/keras/activations.py", line 176, in serialize
return activation.__name__
AttributeError: 'LeakyReLU' object has no attribute '__name__'