Provides functional API for model creation in PyTorch.
Project description
Pytorch Functional
Pytorch Functional is a MIT licensed library that adds functional API for model creation to PyTorch.
Defining complex models in PyTorch requires creating classes. Defining models in Keras is easier. This makes it just as easy in PyTorch. With Pytorch Functional, you can create neural networks without tedious calculations of input shapes for each layer.
Features:
- Small extension to PyTorch
- No dependencies besides PyTorch
- Produces models entirely compatible with PyTorch
- Reduces the amount of code that you need to write
- Works well with complex architectures
New in 0.4.0
Using the new version of the API you can create functional model just like in Keras: by calling the layer with placeholders as arguments. Layer will be then automagically registered in your model.
from torch import nn
from pytorch_functional import FunctionalModel, Input
inputs = Input(shape=(1, 28, 28))
x = nn.Flatten()(inputs)
x = nn.Linear(x.shape[1], 10)(x)
outputs = nn.ReLU()(x)
model = FunctionalModel(inputs, outputs)
model
FunctionalModel(
(module000_depth001): Flatten(start_dim=1, end_dim=-1)
(module001_depth002): Linear(in_features=784, out_features=10, bias=True)
(module002_depth003): ReLU()
)
- 100% backward compatibile models
- You can mix the new and old API
- Works with multiple arguments
Example
To create a functional model, call a placeholder with the layer as an argument. This will return another placeholder, which you can use.
from torch import nn
from pytorch_functional import FunctionalModel, Input
inputs = Input(shape=(1, 28, 28))
x = inputs(nn.Flatten())
outputs = x(nn.Linear(x.shape[1], 10))(nn.ReLU())
model = FunctionalModel(inputs, outputs)
model
FunctionalModel(
(module000_depth001): Flatten(start_dim=1, end_dim=-1)
(module001_depth002): Linear(in_features=784, out_features=10, bias=True)
(module002_depth003): ReLU()
)
See more examples in Quick Start.
Installation
Install easily with pip:
pip install pytorch-functional
Links
Create an issue if you have noticed a problem! Send me an e-mail if you want to get involved: sjmikler@gmail.com.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Hashes for pytorch-functional-0.4.11.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | a8c7d67689bbd6e7a9ecb4f82a6321abe7e01b1b9a311623647034a9f0132a19 |
|
MD5 | df2d4520a4379185d4c53fa664bad89c |
|
BLAKE2b-256 | 5afa089e61b9a82899f03eca050304e2b0d7d5215ccc09eefd262c1fa19f913f |