Giter Site home page Giter Site logo

pytorch-named-dims's Introduction

pytorch-named-dims

PyTorch tensor dimension names for all nn.Modules.

Extends PyTorch Named Tensors (new in PyTorch 1.4.0, still experimental as of PyTorch 1.5.0). It works in Python 3.6+.

Inspired by:

Installation

Not yet on PyPI. Install:

pip install git+git://github.com/stared/pytorch-named-dims.git

Example

import torch
from torch import nn
from pytorch_named_dims import nm

convs = nn.Sequential(
    nm.Conv2d(3, 5, kernel_size=3, padding=1),
    nn.ReLU(),  # preserves dims on its own
    nm.MaxPool2d(2, 2),
    nm.Conv2d(5, 2, kernel_size=3, padding=1)
)

x_input_1 = torch.rand((4, 3, 2, 2), names=('N', 'C', 'H', 'W'))  # good
x_input_2 = torch.rand((4, 3, 2, 2), names=('N', 'C', 'W', 'H'))  # bad

convs(x_input_1)  # returns ('N', 'C', 'H', 'W')
convs(x_input_2)  # raises:
# Layer Conv2d requires dimensions ['N', 'C', 'H', 'W'] but got ('N', 'C', 'W', 'H') instead.
  • TODO: Colab

Funding

Project is supported by Program Operacyjny Inteligentny Rozwój grant for ECC Games for GearShift project.

pytorch-named-dims's People

Contributors

bartolo1024 avatar stared avatar

Watchers

 avatar  avatar  avatar

Forkers

bartolo1024

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.