Coder Social home page Coder Social logo

yukkyo / pytorch-filterresponsenormalizationlayer Goto Github PK

View Code? Open in Web Editor NEW
85.0 5.0 9.0 41 KB

PyTorch implementation of "Filter Response Normalization Layer: Eliminating Batch Dependence in the Training of Deep Neural Networks"

Home Page: https://arxiv.org/abs/1911.09737

Python 99.37% Shell 0.63%
python pytorch catalyst batchnorm2d deep-neural-networks frn

pytorch-filterresponsenormalizationlayer's Introduction

PyTorch-Filter Response Normalization Layer(FRN)

PyTorch implementation of Filter Response Normalization Layer(FRN)

[1911.09737] Filter Response Normalization Layer: Eliminating Batch Dependence in the Training of Deep Neural Networks

0. How to apply FRN to your model

Replace BatchNorm2d + ReLU in the model with FRN + TLU yourself. Currently, it is difficult to easily replace them with functions. Because many models use the same ReLU in various places.

1. Experiment(Classification)

We use Best Artworks of All Time | Kaggle dataset. This dataset contains 49 artists and their pictures.
In this experiment, we classify artist by picture.

1.0 Assumed libraries

  • torch==1.3.1
  • catalyst==19.11.6
  • albumentations==0.4.3
  • NVIDIA/apex
    • If you use --fp16 option

1.1 Get dataset

If you can use kaggle API command, you can download easily

$ cd input
$ kaggle datasets download -d ikarus777/best-artworks-of-all-time
$ unzip best-artworks-of-all-time.zip -d artworks

Or download directly from Best Artworks of All Time | Kaggle

I assume the following directory structure.

input
├── artworks
│   ├── artists.csv
│   ├── images
│   │   └── images
│   │       ├── Alfred_Sisley
│   │       │   ├── Alfred_Sisley_1.jpg
│   │       │   ├── Alfred_Sisley_10.jpg
│   │       │   ├── ...

1.2 Train(and Valid)

You can use --fp16 if you installed nvidia/apex. But FRN is not tuned for FP16, you should turn off --fp16 when use --frn.

$ python train_cls.py --fp16
$ python train_cls.py --frn

pytorch-filterresponsenormalizationlayer's People

Contributors

yukkyo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

pytorch-filterresponsenormalizationlayer's Issues

tau and epsilon

Hello, thanks for your work.
I have read your codes and found something mismatching with original paper.
The first is the 'tau' in TLU. In paper, it's said that tau is a vector of size num_channels. But in your codes, It's just a single value.
The second is the epsilon. In paper, it's said when using in conv, epsilon is a constant value of 10^-6. but in your codes , it's a learnable parameter.
Will these mismatches hurt the preformance?

senet_frn first stage bn or frn?

https://github.com/yukkyo/PyTorch-FilterResponseNormalizationLayer/blob/master/senet_frn.py#L287

        if input_3x3:
            layer0_modules = [
                ('conv1', nn.Conv2d(3, 64, 3, stride=2, padding=1,
                                    bias=False)),
                ('bn1', nn.BatchNorm2d(64)),
                ('relu1', nn.ReLU(inplace=True)),
                ('conv2', nn.Conv2d(64, 64, 3, stride=1, padding=1,
                                    bias=False)),
                ('bn2', nn.BatchNorm2d(64)),
                ('relu2', nn.ReLU(inplace=True)),
                ('conv3', nn.Conv2d(64, inplanes, 3, stride=1, padding=1,
                                    bias=False)),
                ('bn3', nn.BatchNorm2d(inplanes)),
                ('relu3', nn.ReLU(inplace=True)),
            ]
        else:
            layer0_modules = [
                ('conv1', nn.Conv2d(3, inplanes, kernel_size=7, stride=2,
                                    padding=3, bias=False)),
                ('bn1', nn.BatchNorm2d(inplanes)),
                ('relu1', nn.ReLU(inplace=True)),
            ]
        # To preserve compatibility with Caffe weights `ceil_mode=True`
        # is used instead of `padding=1`.
        layer0_modules.append(('pool', nn.MaxPool2d(3, stride=2,
                                                    ceil_mode=True)))

Sorry but I'm a little confused. When using FRN in senet, should all batch norms be replaced by FRN?

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.