Help us understand the problem. What is going on with this article?

ResNeXt 実装

ResNeXt

・入力を分岐させて畳み込み、最後に足し合わせる
・分岐する数をcardinalityとよぶ

image.png

実装


def _resblock(n_filters1, n_filters2, strides=(1,1)):
  def f(input):    
    x = Convolution2D(n_filters1, (1,1), strides=strides,
                                      kernel_initializer='he_normal', padding='same')(input)
    x = BatchNormalization()(x)
    x = Activation('relu')(x)
    x = Convolution2D(n_filters1, (3,3), strides=strides,
                                      kernel_initializer='he_normal', padding='same')(x)
    x = BatchNormalization()(x)
    x = Activation('relu')(x)
    x = Convolution2D(n_filters2, (1,1), strides=strides,
                                      kernel_initializer='he_normal', padding='same')(x)
    x = BatchNormalization()(x)

    return x

  return f

def resnext():

  inputs = Input(shape=(32, 32, 3))
  x = Convolution2D(32, (7,7), strides=(1,1),
                    kernel_initializer='he_normal', padding='same')(inputs)
  x = BatchNormalization()(x)
  x = Activation('relu')(x)
  x = MaxPooling2D((3, 3), strides=(2,2), padding='same')(x)

  residual = Convolution2D(256, 1, strides=1, padding='same')(x)
  residual = BatchNormalization()(residual)

  x1 = _resblock(n_filters1=4, n_filters2=256)(x)
  x2 = _resblock(n_filters1=4, n_filters2=256)(x)
  x3 = _resblock(n_filters1=4, n_filters2=256)(x)
  x4 = _resblock(n_filters1=4, n_filters2=256)(x)
  x5 = _resblock(n_filters1=4, n_filters2=256)(x)
  x6 = _resblock(n_filters1=4, n_filters2=256)(x)
  x7 = _resblock(n_filters1=4, n_filters2=256)(x)
  x8 = _resblock(n_filters1=4, n_filters2=256)(x)
  x9 = _resblock(n_filters1=4, n_filters2=256)(x)
  x10 = _resblock(n_filters1=4, n_filters2=256)(x)
  x11 = _resblock(n_filters1=4, n_filters2=256)(x)
  x12 = _resblock(n_filters1=4, n_filters2=256)(x)
  x13 = _resblock(n_filters1=4, n_filters2=256)(x)
  x14 = _resblock(n_filters1=4, n_filters2=256)(x)
  x15 = _resblock(n_filters1=4, n_filters2=256)(x)
  x16 = _resblock(n_filters1=4, n_filters2=256)(x)
  x17 = _resblock(n_filters1=4, n_filters2=256)(x)
  x18 = _resblock(n_filters1=4, n_filters2=256)(x)
  x19 = _resblock(n_filters1=4, n_filters2=256)(x)
  x20 = _resblock(n_filters1=4, n_filters2=256)(x)
  x21 = _resblock(n_filters1=4, n_filters2=256)(x)
  x22 = _resblock(n_filters1=4, n_filters2=256)(x)
  x23 = _resblock(n_filters1=4, n_filters2=256)(x)
  x24 = _resblock(n_filters1=4, n_filters2=256)(x)
  x25 = _resblock(n_filters1=4, n_filters2=256)(x)
  x26 = _resblock(n_filters1=4, n_filters2=256)(x)
  x27 = _resblock(n_filters1=4, n_filters2=256)(x)
  x28 = _resblock(n_filters1=4, n_filters2=256)(x)
  x29 = _resblock(n_filters1=4, n_filters2=256)(x)
  x30 = _resblock(n_filters1=4, n_filters2=256)(x)
  x31 = _resblock(n_filters1=4, n_filters2=256)(x)
  x32 = _resblock(n_filters1=4, n_filters2=256)(x)


  x_all = add([x1,x2,x3,x4,x5,x6,x7,x8,x9,x10,
               x11,x12,x13,x14,x15,x16,x17,x18,x19,x20,
               x21,x22,x23,x24,x25,x26,x27,x28,x29,x30,
               x31,x32])


  x = add([x_all, residual])

  x = MaxPooling2D((3, 3), strides=(2,2), padding='same')(x)
  residual = Convolution2D(512, 1, strides=1, padding='same')(x)
  residual = BatchNormalization()(residual)

  x1 = _resblock(n_filters1=8, n_filters2=512)(x)
  x2 = _resblock(n_filters1=8, n_filters2=512)(x)
  x3 = _resblock(n_filters1=8, n_filters2=512)(x)
  x4 = _resblock(n_filters1=8, n_filters2=512)(x)
  x5 = _resblock(n_filters1=8, n_filters2=512)(x)
  x6 = _resblock(n_filters1=8, n_filters2=512)(x)
  x7 = _resblock(n_filters1=8, n_filters2=512)(x)
  x8 = _resblock(n_filters1=8, n_filters2=512)(x)
  x9 = _resblock(n_filters1=8, n_filters2=512)(x)
  x10 = _resblock(n_filters1=8, n_filters2=512)(x)
  x11 = _resblock(n_filters1=8, n_filters2=512)(x)
  x12 = _resblock(n_filters1=8, n_filters2=512)(x)
  x13 = _resblock(n_filters1=8, n_filters2=512)(x)
  x14 = _resblock(n_filters1=8, n_filters2=512)(x)
  x15 = _resblock(n_filters1=8, n_filters2=512)(x)
  x16 = _resblock(n_filters1=8, n_filters2=512)(x)
  x17 = _resblock(n_filters1=8, n_filters2=512)(x)
  x18 = _resblock(n_filters1=8, n_filters2=512)(x)
  x19 = _resblock(n_filters1=8, n_filters2=512)(x)
  x20 = _resblock(n_filters1=8, n_filters2=512)(x)
  x21 = _resblock(n_filters1=8, n_filters2=512)(x)
  x22 = _resblock(n_filters1=8, n_filters2=512)(x)
  x23 = _resblock(n_filters1=8, n_filters2=512)(x)
  x24 = _resblock(n_filters1=8, n_filters2=512)(x)
  x25 = _resblock(n_filters1=8, n_filters2=512)(x)
  x26 = _resblock(n_filters1=8, n_filters2=512)(x)
  x27 = _resblock(n_filters1=8, n_filters2=512)(x)
  x28 = _resblock(n_filters1=8, n_filters2=512)(x)
  x29 = _resblock(n_filters1=8, n_filters2=512)(x)
  x30 = _resblock(n_filters1=8, n_filters2=512)(x)
  x31 = _resblock(n_filters1=8, n_filters2=512)(x)
  x32 = _resblock(n_filters1=8, n_filters2=512)(x)


  x_all = add([x1,x2,x3,x4,x5,x6,x7,x8,x9,x10,
               x11,x12,x13,x14,x15,x16,x17,x18,x19,x20,
               x21,x22,x23,x24,x25,x26,x27,x28,x29,x30,
               x31,x32])

  x = add([x_all, residual])

  x = GlobalAveragePooling2D()(x)
  x = Dense(10, kernel_initializer='he_normal', activation='softmax')(x)


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

model = resnext()

adam = Adam()
model.compile(optimizer=adam, loss='categorical_crossentropy', metrics=['accuracy'])


model.summary()

Why do not you register as a user and use Qiita more conveniently?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away