Giter Site home page Giter Site logo

1050265390 / implement-resnext-with-keras Goto Github PK

View Code? Open in Web Editor NEW

This project forked from carmel-nzhinusoft/implement-resnext-with-keras

0.0 0.0 0.0 174 KB

This repository shows how to implement the ResNeXt networks with the Keras library.

Jupyter Notebook 93.02% Python 6.98%

implement-resnext-with-keras's Introduction

Implement-ResNeXt-with-Keras

ResNeXt is an important mileston in the growth of convolutional networks, especially for Residual Networks.

Here is a proposal to implement ReNeXt with Keras. Our implementation is inspired by ResNeXt-Tensorflow and Residual Networks

Requirements

  • Python 3.x
  • Tensorflow 1.x
  • Keras 2.2.4

Architectures

  1. The original building block of ResNeXt : Aggregated residual transformations
  2. First Reformulation, implemented as early concatenation
  3. Second Reformulation which includes grouped convolution

We implemented the first reformulation which consists of split, transform+merge and transition operations.

Principles

Split

Split the input channels into groups. The total number of groups is equals to the cardinality which is c=4 in our case

def split(inputs, cardinality):
    inputs_channels = inputs.shape[3]
    group_size = inputs_channels // cardinality    
    groups = list()
    for number in range(1, cardinality+1):
        begin = int((number-1)*group_size)
        end = int(number*group_size)
        block = Lambda(lambda x:x[:,:,:,begin:end])(inputs)
        groups.append(block)
    return groups

Transform + merge

Perform two consecutive convolution operations on each group: 1x1 and 3x3 (Transform) followed by concatenation (Merge)

def transform(groups, filters, strides, stage, block):
    f1, f2 = filters    
    conv_name = "conv2d-{stage}{block}-branch".format(stage=str(stage), block=str(block))
    bn_name = "batchnorm-{stage}{block}-branch".format(stage=str(stage), block=str(block))
    
    transformed_tensor = list()
    i = 1
    
    for inputs in groups:
        # first conv of the transformation phase
        x = Conv2D(filters=f1, kernel_size=(1,1), strides=strides, padding="valid", 
                   name=conv_name+'1a_split'+str(i), kernel_initializer=glorot_uniform(seed=0))(inputs)
        x = BatchNormalization(axis=3, name=bn_name+'1a_split'+str(i))(x)
        x = Activation('relu')(x)

        # second conv of the transformation phase
        x = Conv2D(filters=f2, kernel_size=(3,3), strides=(1,1), padding="same", 
                   name=conv_name+'1b_split'+str(i), kernel_initializer=glorot_uniform(seed=0))(x)
        x = BatchNormalization(axis=3, name=bn_name+'1b_split'+str(i))(x)
        x = Activation('relu')(x)
        
        # Add x to transformed tensor list
        transformed_tensor.append(x)
        i+=1
        
    # Concatenate all tensor from each group
    x = Concatenate(name='concat'+str(stage)+''+block)(transformed_tensor)
    
    return x

Transition

The last conv layer of the building block of (b)

def transition(inputs, filters, stage, block):
    x = Conv2D(filters=filters, kernel_size=(1,1), strides=(1,1), padding="valid", 
                   name='conv2d-trans'+str(stage)+''+block, kernel_initializer=glorot_uniform(seed=0))(inputs)
    x = BatchNormalization(axis=3, name='batchnorm-trans'+str(stage)+''+block)(x)
    x = Activation('relu')(x)
    
    return x

Building Blocks

The wall architecture is as follow

  • Identity Block : Building blocks contained is the same stage. They have same input and output dimensions
  • Downsampling Block : Transition between two building blocks whose the output dimension of the first block is different from that of the input of the other block.

Organization of the repository's files

resnext50-with-keras.ipynb : details on how the model and its functions work
resnext50.py : define the ResNeXt50 class
training-on-cifar10.py : training script on the cifar10 dataset

References

  1. Xie et al. (2017) Aggregated Residual Transformations for Deep Neural Networks
  2. He et al. (2015) Deep Residual Learning for Image Recognition
  3. Marco Peixeiro GitHub repository : Residual Networks
  4. GitHub Repository: ResNeXt-Tensorflow
  5. Keras Documentation : Trains a ResNet on the CIFAR10 dataset

Author

Carmel WENGA, R&D Engineer | Data Scientist - Nzhinusoft

Visit our Market Place

shoppinglist.cm

implement-resnext-with-keras's People

Contributors

carmel-nzhinusoft avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.