AttributeError:“节点"对象没有属性"output_masks" [英] AttributeError: 'Node' object has no attribute 'output_masks'
问题描述
我使用Keras预训练模型VGG16.问题在于,将tensorflow配置为使用GPU后,出现了使用CPU之前没有的错误.
I use Keras pretrained model VGG16. The problem is that after configuring tensorflow to use the GPU I get an error that I didn't have before when using the 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'
我在执行以下代码后得到了它:
I get it after executing this code :
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)
我有keras(2.2.2)和tensorflow(1.10.0rc1).我也尝试过keras 2.2.0和同样的错误.事实是,我使用的python环境可以在其他非预训练的NN上工作.
EDIT1 : I've got keras (2.2.2) and tensorflow(1.10.0rc1). I've also tried on keras 2.2.0 and same error. The thing is that the python environment I use works on others non-pretrained NN.
我可以连接两个自制模型.只有受过训练的人才有问题,而不仅仅是VGG16.
EDIT2 : I'm able to connect two homemade models. It's only whith the pretrained ones there is a problem and not only VGG16.
推荐答案
您可能会从tensorflow.keras导入tf.keras.layers或tf.keras.applications或其他keras模块,并将这些对象与基于版本等不兼容的纯" keras软件包.我建议您查看是否可以从纯" keras模块导入并运行所有内容;调试时不要使用tf.keras,因为它们不一定兼容.我遇到了同样的问题,并且此解决方案对我有用.
You're likely importing tf.keras.layers or tf.keras.applications or other keras modules from tensorflow.keras, and mixing these objects with objects from the "pure" keras package, which is not compatible, based upon version, etc. I recommend seeing if you can import and run everything from the "pure" keras modules; don't use tf.keras while debugging, as they're not necessarily compatible. I had the same problem, and this solution is working for me.
这篇关于AttributeError:“节点"对象没有属性"output_masks"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!