我使用Keras预训练模型VGG16。问题在于当我将tensorflow配置为使用GPU后,出现了一个之前在使用CPU时没有过的错误。
错误如下:
Traceback (most recent call last):
File "/home/guillaume/Documents/Allianz/ConstatOrNotConstatv3/train_network.py", line 109, in <module>
model = LeNet.build(width=100, height=100, depth=3, classes=5)
File "/home/guillaume/Documents/Allianz/ConstatOrNotConstatv3/lenet.py", line 39, in build
output = model(pretrainedOutput)
File "/usr/local/lib/python3.6/dist-packages/keras/engine/base_layer.py", line 443, in __call__
previous_mask = _collect_previous_mask(inputs)
File "/usr/local/lib/python3.6/dist-packages/keras/engine/base_layer.py", line 1311, in _collect_previous_mask
mask = node.output_masks[tensor_index]
AttributeError: 'Node' object has no attribute 'output_masks'
我在执行这段代码后明白了:
pretrained_model = VGG16(
include_top=False,
input_shape=(height, width, depth),
weights='imagenet'
)
for layer in pretrained_model.layers:
layer.trainable = False
model = Sequential()
# first (and only) set of FC => RELU layers
model.add(Flatten())
model.add(Dense(200, activation='relu'))
model.add(Dropout(0.5))
model.add(BatchNormalization())
model.add(Dense(400, activation='relu'))
model.add(Dropout(0.5))
model.add(BatchNormalization())
# softmax classifier
model.add(Dense(classes,activation='softmax'))
pretrainedInput = pretrained_model.input
pretrainedOutput = pretrained_model.output
output = model(pretrainedOutput)
model = Model(pretrainedInput, output)
编辑1:我已经获得了Keras(2.2.2)和TensorFlow(1.10.0rc1)。我也尝试过Keras 2.2.0,但仍然出现相同的错误。问题是我使用的Python环境可以在其他非预训练神经网络上正常工作。
编辑2:我能够连接两个自制模型。只有在预训练模型中存在问题,而不仅仅是VGG16。