GithubHelp home page GithubHelp logo

bill4278 / pytorch_refinenet Goto Github PK

View Code? Open in Web Editor NEW

This project forked from thomasjpfan/pytorch_refinenet

0.0 0.0 0.0 24 KB

Pytorch Implementation of Refinenet

License: MIT License

Python 100.00%

pytorch_refinenet's Introduction

Pytorch Implementation of RefineNet

Build Status

This is a Pytorch implementation of the Multipath RefineNet architecture from the paper.

Installation

Install PyTorch following instructions on their website. Then install this package:

pip install git+https://github.com/thomasjpfan/pytorch_refinenet.git

Implemented versions

  • Multi-path 4-Cascaded RefineNet: RefineNet4Cascade
  • Multi-path 4-Cascaded RefineNet With Improved Pooling: RefineNet4CascadePoolingImproved

There are diagrams of these two versions in the author's github repo. The improved pooling version adds an additional pooling/convolution layer and flips the order of the pooling/convolution layers in the Chained Residual Pooling block.

Usage

This implementation of the Multipath RefineNet has the following initialization:

class RefineNet4Cascade(nn.Module):

    def __init__(self,
                 input_shape,
                 num_classes=1,
                 features=256,
                 resnet_factory=models.resnet101,
                 pretrained=True,
                 freeze_resnet=True):
        ...

The input_shape is a tuple of(channels, size) which denotes the number of channels in the input image and the input width/height. For an input to flow cleanly through the resnet layers, the input size should be divisible by 32. The input size is assumed to be a square image/patch. For example the RefineNet4Cascade can be defined to intake 3x224x224 images:

import torch
from pytorch_refinenet import RefineNet4Cascade

net = RefineNet4Cascade((3, 224), num_classes=10)
x = torch.randn(1, 3, 224, 224)
y = net(x)
y.size()
# torch.Size([1, 10, 56, 56])

The number of channels outputed will equal num_classes and the size will be 1/4 the size of the input as described in the paper. You can upscale the to get back to the original resolution.

Training

The refinenet backbone is frozen by default, which means they will not be updated with gradients during training. The parameters method in RefineNet4Cascade was redefined to only return the parameters that require a gradident. Thus this will work for training:

net = RefineNet4Cascade((3, 224), num_classes=10)
opt = optim.Adam(net.parameters())

x = torch.randn(1, 3, 224, 224)
y = net(x)
...

pytorch_refinenet's People

Contributors

thomasjpfan 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.