Keras: What is in keras 2 ? After updating to keras 2.0.2 working code is giving errors

Created on 27 Mar 2017  路  9Comments  路  Source: keras-team/keras

My code was already causing issues but only in fit_generator (#6000) so I thought I should update keras because I have not updated since 2-3 months
This is the new set of error I encountered:

  1. import keras.utils.visualize_util was not found then I found this in folder keras.utils.vis_utils so I imported it. Instead of keras.utils.vis_utils.plot I found that it might be keras.utils.vis_utils.plot_model
  2. In convolution layer I am stuck with this so instead of reading source code I want to know where I should look for changes
    Previously I used to wrote model something as:
#First
#Conv Layer 1
model.add(Convolution2D(112,3,3, border_mode='same',init='uniform',input_shape=(136,136,3),dim_ordering='tf',name='conv_1.1'))
model.add(Activation('relu'))
model.add(ZeroPadding2D(padding=(1, 1), dim_ordering='tf'))
model.add(Convolution2D(64,2,2, subsample=(2,2),border_mode='valid',dim_ordering='tf',name='conv_1.2'))
model.add(Activation('relu'))
model.add(BatchNormalization(epsilon=1e-05,axis=1,momentum=0.99))
#Conv Layer 2
model.add(ZeroPadding2D(padding=(1, 1), dim_ordering='tf'))
model.add(Convolution2D(64,3,3, border_mode='valid',dim_ordering='tf',name='conv_2.1'))
model.add(Activation('relu'))
model.add(ZeroPadding2D(padding=(1, 1), dim_ordering='tf'))
model.add(Convolution2D(128,3,3,border_mode='valid',subsample=(2,2),dim_ordering='tf',name='conv_2.3'))
model.add(Activation('relu'))
model.add(BatchNormalization(epsilon=1e-05,momentum=0.99,weights=None,beta_init='zero',gamma_init='one',gamma_regularizer=None,beta_regularizer=None))

Warning Message:

/home/qayyum/anaconda2/lib/python2.7/site-packages/ipykernel/__main__.py:5: UserWarning: Update your Conv2D call to the Keras 2 API: Conv2D(112, (3, 3), kernel_initializer="uniform", name="conv_1.1", data_format="channels_last", input_shape=(136, 136,..., padding="same")

Errors

AttributeError                            Traceback (most recent call last)
<ipython-input-4-63b7503655f7> in <module>()
      3 
      4 #Conv Layer 1
----> 5 model.add(Convolution2D(112,3,3, border_mode='same',init='uniform',input_shape=(136,136,3),dim_ordering='tf',name='conv_1.1'))
      6 print ("C1:" , model.output_shape)
      7 model.add(Activation('relu'))

/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)
   2882     x = _preprocess_conv2d_input(x, data_format)
   2883     padding = _preprocess_padding(padding)
-> 2884     x = tf.nn.convolution(
   2885         input=x,
   2886         filter=kernel,

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

Most helpful comment

"what is in Keras 2?" -> Google "Keras 2 release notes", click the first result.

All 9 comments

Strange: Change
model.add(Convolution2D(112,3,3, border_mode='same',init='uniform',input_shape=(136,136,3),dim_ordering='tf',name='conv_1.1'))
to this:
model.add(Conv2D(112,(3,3), border_mode='same',kernel_initializer='uniform',input_shape=(136,136,3),dim_ordering='tf',name='conv_1.1'))
still same problem

@abdulqayyum Check out the new documentation, almost all the above keyword arguments have changed, border_mode has become padding, dim_ordering is data_format etc

"what is in Keras 2?" -> Google "Keras 2 release notes", click the first result.

Thank you, I was unaware of big changes. I need to go through all of my work again.

See the Release note wiki-page for the details.

yes ,Convolution2D is not support ,instead of by Conv2D. I fount the keras2 have many diffrent to keras1.2 . I use pip install keras==1.2.2 it work.

Convolution2D is still supported as alias of Conv2D. But see this issue https://github.com/fchollet/keras/issues/6044 for my two cents on the renaming.

Thanks, this was useful.

this is working now
classifier.add(Conv2D(32, (3, 3), input_shape = (64, 64, 3), activation= 'relu'))
instead of
classifier.add(Convolution2D(32, 3, 3, input_shape = (64, 64, 3), activation= 'relu'))

Thank you very much

Was this page helpful?
0 / 5 - 0 ratings