Skip to main content

A simplified framework and utilities for PyTorch.

Project description

Poutyne Logo

License: LGPL v3 Continuous Integration codecov

Here is Poutyne.

Poutyne is a simplified framework for PyTorch and handles much of the boilerplating code needed to train neural networks.

Use Poutyne to:

  • Train models easily.
  • Use callbacks to save your best model, perform early stopping and much more.

Read the documentation at Poutyne.org.

Poutyne is compatible with the latest version of PyTorch and Python >= 3.6.

Cite

@misc{Paradis_Poutyne_A_Simplified_2020,
    author = {Paradis, Frédérik and Beauchemin, David and Godbout, Mathieu and Alain, Mathieu and Garneau, Nicolas and Otte, Stefan and Tremblay, Alexis and Bélanger, Marc-Antoine and Laviolette, François},
    title  = {{Poutyne: A Simplified Framework for Deep Learning}},
    year   = {2020},
    url    = {https://poutyne.org}
}

Getting started: few seconds to Poutyne

The core data structure of Poutyne is a Model, a way to train your own PyTorch neural networks.

How Poutyne works is that you create your PyTorch module (neural network) as usual but when comes the time to train it you feed it into the Poutyne Model, which handles all the steps, stats and callbacks, similar to what Keras does.

Here is a simple example:

# Import the Poutyne Model and define a toy dataset
from poutyne import Model
import torch
import torch.nn as nn
import numpy as np
import torchmetrics

num_features = 20
num_classes = 5
hidden_state_size = 100

num_train_samples = 800
train_x = np.random.randn(num_train_samples, num_features).astype('float32')
train_y = np.random.randint(num_classes, size=num_train_samples).astype('int64')

num_valid_samples = 200
valid_x = np.random.randn(num_valid_samples, num_features).astype('float32')
valid_y = np.random.randint(num_classes, size=num_valid_samples).astype('int64')

num_test_samples = 200
test_x = np.random.randn(num_test_samples, num_features).astype('float32')
test_y = np.random.randint(num_classes, size=num_test_samples).astype('int64')

Select a PyTorch device so that it runs on GPU if you have one:

cuda_device = 0
device = torch.device("cuda:%d" % cuda_device if torch.cuda.is_available() else "cpu")

Create yourself a PyTorch network:

network = nn.Sequential(
    nn.Linear(num_features, hidden_state_size),
    nn.ReLU(),
    nn.Linear(hidden_state_size, num_classes)
)

You can now use Poutyne's model to train your network easily:

model = Model(
    network,
    'sgd',
    'cross_entropy',
    batch_metrics=['accuracy'],
    epoch_metrics=['f1', torchmetrics.AUROC(num_classes=num_classes)],
    device=device
)
model.fit(
    train_x, train_y,
    validation_data=(valid_x, valid_y),
    epochs=5,
    batch_size=32
)

Since Poutyne is inspired by Keras, one might have notice that this is really similar to some of its functions.

You can evaluate the performances of your network using the evaluate method of Poutyne's model:

loss, (accuracy, f1score) = model.evaluate(test_x, test_y)

Or only predict on new data:

predictions = model.predict(test_x)

See the complete code here. Also, see this for an example for regression.

One of the strengths Poutyne are callbacks. They allow you to save checkpoints, log training statistics and more. See this notebook for an introduction to callbacks. In that vein, Poutyne also offers an ModelBundle class that offers automatic checkpointing, logging and more using callbacks under the hood. Here is an example of usage.

from poutyne import ModelBundle

# Everything is saved in ./saves/my_classification_network
model_bundle = ModelBundle.from_network(
    './saves/my_classification_network', network, optimizer='sgd', task='classif', device=device
)

model_bundle.train_data(train_x, train_y, validation_data=(valid_x, valid_y), epochs=5)

model_bundle.test_data(test_x, test_y)

See the complete code here. Also, see this for an example for regression.


Installation

Before installing Poutyne, you must have the latest version of PyTorch in your environment.

  • Install the stable version of Poutyne:
pip install poutyne
  • Install the latest development version of Poutyne:
pip install -U git+https://github.com/GRAAL-Research/poutyne.git@dev

Learning Material

Blog posts

  • Medium PyTorch post - Presentation of the basics of Poutyne and how it can help you be more efficient when developing neural networks with PyTorch.

Examples

Look at notebook files with full working examples:

or in Google Colab:

Videos


Contributing to Poutyne

We welcome user input, whether it is regarding bugs found in the library or feature propositions ! Make sure to have a look at our contributing guidelines for more details on this matter.


License

Poutyne is LGPLv3 licensed, as found in the LICENSE file.


Why this name, Poutyne?

Poutyne's name comes from poutine, the well-known dish from Quebec. It is usually composed of French fries, squeaky cheese curds and brown gravy. However, in Quebec, poutine also has the meaning of something that is an "ordinary or common subject or activity". Thus, Poutyne will get rid of the ordinary boilerplate code that plain PyTorch training usually entails.

Poutine Yuri Long from Arlington, VA, USA [CC BY 2.0]


Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

Poutyne-1.10.1.tar.gz (131.3 kB view details)

Uploaded Source

Built Distribution

Poutyne-1.10.1-py3-none-any.whl (210.2 kB view details)

Uploaded Python 3

File details

Details for the file Poutyne-1.10.1.tar.gz.

File metadata

  • Download URL: Poutyne-1.10.1.tar.gz
  • Upload date:
  • Size: 131.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.8.12

File hashes

Hashes for Poutyne-1.10.1.tar.gz
Algorithm Hash digest
SHA256 ce6ed5441c917e6403c13ec083b5a046141dfd1363f91796c1129f8edc3b1ba1
MD5 972179697a80f5db3a485cf7721ddce1
BLAKE2b-256 239c4b2378ac2f4fd35e4a6031d085d9cedeb4d348b587761978563101d7fd4c

See more details on using hashes here.

File details

Details for the file Poutyne-1.10.1-py3-none-any.whl.

File metadata

  • Download URL: Poutyne-1.10.1-py3-none-any.whl
  • Upload date:
  • Size: 210.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.8.12

File hashes

Hashes for Poutyne-1.10.1-py3-none-any.whl
Algorithm Hash digest
SHA256 bcbf828dcfba9504004c270757e41afab9a3ae224115f1872f3b33fb177f1075
MD5 c212744e9470c6f252a26b099021474e
BLAKE2b-256 2afe70ccaca7975ca69267ea4f18b23e78221119fec32d42d1db0902688cb11c

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page