Я строю объединение моделей с ResNet50 и DenseNet121 из keras.applications, но при сохранении модели возникает ошибка.
Если я использую только одну сеть из ResNet50 и DenseNet121, например, только DenseNet, нет проблем
fusion с ResNet50 и DenseNet121:
img_input = Input(shape=input_shape)
densenet = app.DenseNet121(
include_top=False,
input_tensor=img_input,
input_shape=input_shape,
weights=base_weights)
resnet = app.ResNet50(
include_top=False,
input_tensor=img_input,
input_shape=input_shape,
weights=base_weights)
x1 = densenet.output
x1 = GlobalAveragePooling2D(name='dn_gap_last')(x1)
# then x1.shape is (batch, 1024)
x2 = resnet.output
x2 = Flatten()(x2) # then x2.shape is (batch, 2048)
x = concatenate([x1, x2], axis=-1)
predictions = Dense(len(class_names), activation="sigmoid", name="predictions")(x)
model = Model(inputs=img_input, outputs=predictions)
и сохранение модели через ModelCheckpoint
checkpoint = ModelCheckpoint(
output_weights_path,
save_weights_only=True,
save_best_only=True,
verbose=1,
)
но выдает ошибку при сохранении mdoel
Epoch 00001: val_loss improved from inf to 0.72018, saving model to ./experiments/8/weights.h5
Traceback (most recent call last):
File "train.py", line 229, in <module>
main()
File "train.py", line 212, in main
shuffle=False,
File "/home/hqt/chest-x-ray-project/code/venv/lib/python3.6/site-packages/keras/legacy/interfaces.py", line 91, in wrapper
return func(*args, **kwargs)
File "/home/hqt/chest-x-ray-project/code/venv/lib/python3.6/site-packages/keras/engine/training.py", line 2280, in fit_generator
callbacks.on_epoch_end(epoch, epoch_logs)
File "/home/hqt/chest-x-ray-project/code/venv/lib/python3.6/site-packages/keras/callbacks.py", line 77, in on_epoch_end
callback.on_epoch_end(epoch, logs)
File "/home/hqt/chest-x-ray-project/code/venv/lib/python3.6/site-packages/keras/callbacks.py", line 445, in on_epoch_end
self.model.save_weights(filepath, overwrite=True)
File "/home/hqt/chest-x-ray-project/code/venv/lib/python3.6/site-packages/keras/engine/topology.py", line 2607, in save_weights
save_weights_to_hdf5_group(f, self.layers)
File "/home/hqt/chest-x-ray-project/code/venv/lib/python3.6/site-packages/keras/engine/topology.py", line 2878, in save_weights_to_hdf5_group
g = f.create_group(layer.name)
File "/home/hqt/chest-x-ray-project/code/venv/lib/python3.6/site-packages/h5py/_hl/group.py", line 50, in create_group
gid = h5g.create(self.id, name, lcpl=lcpl)
File "h5py/_objects.pyx", line 54, in h5py._objects.with_phil.wrapper
File "h5py/_objects.pyx", line 55, in h5py._objects.with_phil.wrapper
File "h5py/h5g.pyx", line 151, in h5py.h5g.create
ValueError: Unable to create group (name already exists)