我已经使用multi_gpu_model实用程序训练了一个模型,并使用了例行回调来检查点并保存模型权重。该模型在4 gpus上训练。
现在进行推断,我希望仅使用单个gpu(以下代码是针对单个gpu的,与使用multi_gpu_model实用程序的训练不同),但是当我尝试加载权重时会出现错误。
input_seq = Input(shape=(40,32,16,1))
a = ConvLSTM2D(256, (3, 3), activation='sigmoid', padding='same', return_sequences=True)(input_seq)
a = ConvLSTM2D(256, (3, 3), activation='sigmoid', padding='same', return_sequences=True)(a)
a = MaxPooling3D((2,2,2), padding='same')(a)
a = ConvLSTM2D(256, (3, 3), activation='sigmoid', padding='same', return_sequences=True)(a)
a = ConvLSTM2D(256, (3, 3), activation='sigmoid', padding='same', return_sequences=False)(a)
a = UpSampling3D((2, 2,2))(a)
for i in range(10):
out_frames.append(Conv2D(filters=1, kernel_size=(3, 3), activation='sigmoid',padding='same')(a))
model = Model(input_seq, out_frames)
model.compile(loss="binary_crossentropy", optimizer="adam")
weight_file="model_weights.hdf5"
但是它引发如下异常:
ValueError: You are trying to load a weight file containing 1 layers into a model with 14 layers.