VansFannel
VansFannel

Reputation: 45921

Mistake on Python code or CNN architecture feature that I don't understad

I'm newbie with Python and CNN.

I have found the following code in this Github repository:

### ----define U-net architecture--------------
def get_unet(img_shape = None):

        dim_ordering = 'tf'
        inputs = Input(shape = img_shape)
        concat_axis = -1
        ### the size of convolutional kernels is defined here    
        conv1 = Convolution2D(64, 5, 5, activation='relu', border_mode='same', dim_ordering=dim_ordering, name='conv1_1')(inputs)
        conv1 = Convolution2D(64, 5, 5, activation='relu', border_mode='same', dim_ordering=dim_ordering)(conv1)
        pool1 = MaxPooling2D(pool_size=(2, 2), dim_ordering=dim_ordering)(conv1)
        conv2 = Convolution2D(96, 3, 3, activation='relu', border_mode='same', dim_ordering=dim_ordering)(pool1)

        # The rest omitted by brevity

I don't understand this line:

conv1 = Convolution2D(64, 5, 5, activation='relu', border_mode='same', dim_ordering=dim_ordering)(conv1)

Why conv1 is equal to Convolution2D([...])(conv1)?

They are using conv1 at the begging and at the end on the sentence. Is a mistake?

Upvotes: 0

Views: 70

Answers (2)

Timbus Calin
Timbus Calin

Reputation: 14983

The reason why you think this is a mistake is that, up until this moment, you have used the so-called Sequential API in Keras.

What you are using here is called the Functional API. The latter is meant to allow more flexibility that the Sequential API.

You can read more about the Functional API and its applicability here: https://www.tensorflow.org/guide/keras/functional

Upvotes: 3

User
User

Reputation: 826

It's not a mistake, you can even write

input = ...
net = Conv2d(...)(input)
net = Conv2d(...)(net)
net = Pool(...)(net)
...

Upvotes: 3

Related Questions