Closed GuillaumeDrillaud closed 6 years ago
Hi Please see the libraries you imported .. import everything of keras ..do not mix up tensorflow
+1. Native keras doesn't go well with tf.keras.
Even this example from https://keras.io/applications/ is not working. The same error is coming on the line with GlobalAveragePooling2D.
from keras.preprocessing import image
from keras.models import Model
from keras.layers import Dense, GlobalAveragePooling2D
from keras import backend as K
# create the base pre-trained model
base_model = InceptionV3(weights='imagenet', include_top=False)
# add a global spatial average pooling layer
x = base_model.output
x = GlobalAveragePooling2D()(x)
# let's add a fully-connected layer
x = Dense(1024, activation='relu')(x)
# and a logistic layer -- let's say we have 200 classes
predictions = Dense(200, activation='softmax')(x)
I have the same problem. I guess the output tensor of the vgg16 model cannot be used properly.
I used the output tensor of the vgg16 model in the following simple code. The versions of Keras and TensorFlow were 2.2.2 and 1.10.0rc1, respectively.
The error messages were:
Traceback (most recent call last):
File "test_vgg16_1.py", line 31, in <module>
model = Model( inputs=vgg16_conv_model.input , outputs=fc_model(vgg16_conv_model.output) )
File "/usr/local/lib64/python3.6/site-packages/keras/engine/base_layer.py", line 443, in __call__
previous_mask = _collect_previous_mask(inputs)
File "/usr/local/lib64/python3.6/site-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 ran the following code:
#
# Setting the image attributes
#
resized_image_height = 150
resized_image_width = 150
no_image_channels = 3
max_pixel_value = 255
#
# Setting the convolutional network of the VGG16 model
#
from keras.applications.vgg16 import VGG16
vgg16_conv_model = VGG16( include_top=False , # remove the fully-connnected network
weights='imagenet' ,
input_shape=( resized_image_height , resized_image_width , no_image_channels ) )
#
# Setting a new fully-connected network
#
from keras.models import Sequential, Model
from keras.layers import Flatten, Dropout, Dense
fc_model = Sequential()
fc_model.add(Flatten(input_shape=vgg16_conv_model.output_shape[1:]))
fc_model.add(Dropout(0.2))
fc_model.add(Dense( 512 , activation='relu' ))
fc_model.add(Dense( 1 , activation='sigmoid' ))
#
# Combining the models
#
model = Model( inputs=vgg16_conv_model.input , outputs=fc_model(vgg16_conv_model.output) )
I would appreciate it if you could give me some advice to resolve this error.
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.
@arquolo you are right! I have the same problem. I downgrade to TensorFlow 1.9 with Keras 2.2.2, it's OK!
I have TF 1.9 and keras 2.2.2 and it's not working
C:\Users\abdo\Anaconda3\python.exe C:/Users/abdo/PycharmProjects/TGSChallenge/modelscript.py
C:\Users\abdo\Anaconda3\lib\site-packages\h5py__init.py:36: FutureWarning: Conversion of the second argument of issubdtype from float
to np.floating
is deprecated. In future, it will be treated as np.float64 == np.dtype(float).type
.
from ._conv import register_converters as _registerconverters
Using TensorFlow backend.
Traceback (most recent call last):
File "C:/Users/abdo/PycharmProjects/TGSChallenge/modelscript.py", line 91, in
I had a similar problem. I was trying to use VGG16 and got this error AttributeError: 'InputLayer' object has no attribute 'outbound_nodes'
.
My tensor flow-gpu version was 1.11 and after I downgraded it to 1.9 according to @arquolo it works now! Thanks a lot!
I have encountered the same problem. The most minimal code example already reproduces it:
from keras.layers import GlobalAveragePooling2D
from keras.applications.inception_v3 import InceptionV3
base_model = InceptionV3(weights=None, include_top=False)
x = base_model.output
x = GlobalAveragePooling2D()(x)
The versions are:
Keras 2.2.4
Keras-Applications 1.0.4
Keras-Preprocessing 1.0.2
tensorboard 1.12.0
tensorflow-gpu 1.12.0
Is there no solution save downgrading to older versions of keras and tf-gpu?
It feels so defeatist to have to do that...
@felix-tracxpoint Update keras_applications and keras_prreprocessing to the latest versions, it should work
@arquolo Thanks, that did the trick!!
P.S. I had been under the impression that the main keras package upgrades the others during piping. Obviously I could not have been more wrong.
Closing this issue since its resolved. Feel to reopen if the issue still persists. Thanks!
I solved this issue by reinstalling keras to the latest version(2.2.4).
same issue as @abdelrahmanmohamed i am getting even after installing tensorflow-gpu 1.9.0 and keras latest version 2.2.4 as well as 2.2.2, in both the cases i am getting error saying AttributeError: 'InputLayer' object has no attribute 'outbound_nodes'
Please help
According to this post, it appears that keras-contrib requires Keras 2.1.1
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
from keras.preprocessing import image
from keras.models import Model
from keras.layers import Dense, GlobalAveragePooling2D
from keras import backend as K
to:
from tensorflow.keras.preprocessing import image
from tensorflow.keras.models import Model
from tensorflow.keras.layers import Dense, GlobalAveragePooling2D
from tensorflow.keras import backend as K
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
keras | 2.2.5 | 2.2.4 keras-applications | 1.0.8 | 1.0.8 keras-preprocessing | 1.1.0 | 1.1.0 scipy | 1.3.1 | 1.3.1 setuptools | 39.1.0 | 41.0.1 six | 1.12.0 | 1.12.0 tensorboard | 1.9.0 | 1.14.0 tensorflow | 1.9.0 | 1.14.0 tensorflow-estimator | 1.14.0 | 1.14.0 tensorflow-gpu | 1.9.0 | 1.14.0 termcolor | 1.1.0 | 1.1.0 theano | 1.0.2 | 1.0.3
I have the same issue ! although I downgraded everything to be compatible with the above mentioned versions !!
keras | 2.2.5 | 2.2.4 keras-applications | 1.0.8 | 1.0.8 keras-preprocessing | 1.1.0 | 1.1.0 scipy | 1.3.1 | 1.3.1 setuptools | 39.1.0 | 41.0.1 six | 1.12.0 | 1.12.0 tensorboard | 1.9.0 | 1.14.0 tensorflow | 1.9.0 | 1.14.0 tensorflow-estimator | 1.14.0 | 1.14.0 tensorflow-gpu | 1.9.0 | 1.14.0 termcolor | 1.1.0 | 1.1.0 theano | 1.0.2 | 1.0.3
I have the same issue ! although I downgraded everything to be compatible with the above mentioned versions !!
Try using either keras or tensorflow.keras, but don't mix the two of them together. This was what fixed my issue.
extremely annoying issue, I have installed the latest versions of TF and keras. But, have the same problem.
tf - '2.2.0' keras - 2.3.0-tf
If you are using YOLO. This what you have to do. As Raseth said.
from keras.preprocessing import image from keras.models import Model from keras.layers import Dense, GlobalAveragePooling2D from keras import backend as K to:
from tensorflow.keras.preprocessing import image from tensorflow.keras.models import Model from tensorflow.keras.layers import Dense, GlobalAveragePooling2D from tensorflow.keras import backend as K
My only solution was to fork the GIT and edit it there.
I did not need to downgrade Keras or Tensorflow.
Just in case using Yolo also Change K.control_flow_ops.while_loop to tf.while_loop
@luisvivasg solution works. I used tensorflow.keras instead of keras. I am using tensorflow-gpu=2.0.0
I have same problem.
File "/data2/wangxinsheng/yft/yft_semantic_train_model/keras_textclassification/base/embedding.py", line 283, in build self.output = NonMaskingLayer()(encoder_layer) File "/data/anaconda3/envs/miss_torch_develop/lib/python3.7/site-packages/keras/engine/base_layer.py", line 443, in __call__ previous_mask = _collect_previous_mask(inputs) File "/data/anaconda3/envs/miss_torch_develop/lib/python3.7/site-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'
K! I can't get tensorflow 1.9. There is no tensorflow 1.9 in https://pypi.org/project/tensorflow-gpu/1.15.2/#history.
Do you know how to fix it?
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:
I get it after executing this code :
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.