keras: AttributeError: 'Node' object has no attribute 'output_masks'
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.
The error is the following one:
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)
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.
Moreover, I’m able to connect two homemade models. It’s only whith the pretrained ones there is a problem and not only VGG16.
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 7
- Comments: 22 (3 by maintainers)
+1. Native keras doesn’t go well with tf.keras.
Hi Please see the libraries you imported … import everything of keras …do not mix up tensorflow
Nightly TF builds are, hmm, nightly, so Keras haven’t become compatible with all its features yet. If using latest version of TF isn’t important for you, downgrade to TensorFlow 1.9, there’s no this bug.
I had a similar issue, but with different architecture. As people suggested, it’s important not to mix keras with tensorflow.keras, so try swapping
to:
Also make sure, you don’t use keras.something inside your code (not only imports) as well, hope it helps : ) Also, I used Keras 2.2.4 with tensorflow 1.10.0
I solved this issue by reinstalling keras to the latest version(2.2.4).