16.03.2021 Views

Advanced Deep Learning with Keras

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

num_filters=num_filters_out,

kernel_size=1,

conv_first=False)

if res_block == 0:

# linear projection residual shortcut connection

# to match changed dims

x = resnet_layer(inputs=x,

num_filters=num_filters_out,

kernel_size=1,

strides=strides,

activation=None,

batch_normalization=False)

x = add([x, y])

num_filters_in = num_filters_out

# add classifier on top.

# v2 has BN-ReLU before Pooling

x = BatchNormalization()(x)

x = Activation('relu')(x)

x = AveragePooling2D(pool_size=8)(x)

y = Flatten()(x)

outputs = Dense(num_classes,

activation='softmax',

kernel_initializer='he_normal')(y)

# instantiate model.

model = Model(inputs=inputs, outputs=outputs)

return model

ResNet v2's model builder is shown in the following code. For example, to build

ResNet110 v2, we'll use n = 12:

n = 12

[ 61 ]

Chapter 2

# model version

# orig paper: version = 1 (ResNet v1), Improved ResNet: version = 2

(ResNet v2)

version = 2

# computed depth from supplied model parameter n

if version == 1:

depth = n * 6 + 2

elif version == 2:

depth = n * 9 + 2

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!