Pramod Patil
Pramod Patil

Reputation: 827

Getting Attribute error while adding Conv2D in sequential model of Keras

from keras.models import Sequential
from keras.layers import Dense, Dropout, Flatten
from keras.layers import Conv2D, MaxPooling2D
from keras.optimizers import SGD

model = Sequential()
model.add(Conv2D(32, (3, 3), activation='relu', input_shape=(100, 100,3)))

input: 100x100 images with 3 channels 32 convolution filters of size 3x3 each Getting the following error:

AttributeError                            Traceback (most recent call last)
<ipython-input-1-8045ebb1a70a> in <module>()
      7 # input: 100x100 images with 3 channels -> (100, 100, 3) tensors.
      8 # this applies 32 convolution filters of size 3x3 each.
----> 9 model.add(Conv2D(32, (3, 3), activation='relu', input_shape=(100, 100, 3)))

/usr/local/lib/python2.7/dist-packages/keras/models.pyc in add(self, layer)
    420                 # and create the node connecting the current layer
    421                 # to the input layer we just created.
--> 422                 layer(x)
    423 
    424             if len(layer.inbound_nodes) != 1:

/usr/local/lib/python2.7/dist-packages/keras/engine/topology.pyc in __call__(self, inputs, **kwargs)
    552 
    553             # Actually call the layer, collecting output(s), mask(s), and shape(s).
--> 554             output = self.call(inputs, **kwargs)
    555             output_mask = self.compute_mask(inputs, previous_mask)
    556 

/usr/local/lib/python2.7/dist-packages/keras/layers/convolutional.pyc in call(self, inputs)
    162                 padding=self.padding,
    163                 data_format=self.data_format,
--> 164                 dilation_rate=self.dilation_rate)
    165         if self.rank == 3:
    166             outputs = K.conv3d(

/usr/local/lib/python2.7/dist-packages/keras/backend/tensorflow_backend.pyc in conv2d(x, kernel, strides, padding, data_format, dilation_rate)
   2854     x = _preprocess_conv2d_input(x, data_format)
   2855     padding = _preprocess_padding(padding)
-> 2856     x = tf.nn.convolution(
   2857         input=x,
   2858         filter=kernel,

AttributeError: 'module' object has no attribute 'convolution'

Can anyone help with this? Is this problem because of new distribution keras 2.0?

Upvotes: 1

Views: 2032

Answers (1)

Pramod Patil
Pramod Patil

Reputation: 827

Upgrading TensorFlow to TensorFlow 1.0 is prerequisite for Keras 2.0. Though it is not mentioned on Keras Official site.

Above problem is resolved by just upgrading to Tensorflow 1.0

To Upgrade Tensorflow follow this link.

Upvotes: 2

Related Questions