PyToune: Deep Learning framework for PyTorch
PyToune is a Keras-like framework for PyTorch and handles much of the boilerplating code needed to train neural networks.
Use PyToune to:
- Train models easily.
- Use callbacks to save your best model, perform early stopping and much more.
Read the documentation at PyToune.org.
PyToune is compatible with PyTorch >= 0.3.0 and Python >= 3.5.
The core data structure of PyToune is a Model
, a way to train your own PyTorch neural networks.
How PyToune 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 PyToune Model, which handles all the steps, stats and callbacks, similar to what Keras does.
Here is a simple example:
# Import the PyToune Model and define a toy dataset
from pytoune.framework import Model
num_train_samples = 800
train_x = torch.rand(num_train_samples, num_features)
train_y = torch.rand(num_train_samples, 1)
num_valid_samples = 200
valid_x = torch.rand(num_valid_samples, num_features)
valid_y = torch.rand(num_valid_samples, 1)
Create yourself a PyTorch network, a loss function and an optimizer;
pytorch_module = torch.nn.Linear(num_features, 1)
loss_function = torch.nn.MSELoss()
optimizer = torch.optim.SGD(pytorch_module.parameters(), lr=1e-3)
You can now use PyToune's model to train your network easily;
model = Model(pytorch_module, optimizer, loss_function)
model.fit(
train_x, train_y,
validation_x=valid_x,
validation_y=valid_y,
epochs=num_epochs,
batch_size=batch_size
)
This is really similar to the model.compile
function as in Keras;
# Keras way to compile and train
model.compile(loss='categorical_crossentropy',
optimizer='sgd',
metrics=['accuracy'])
model.fit(x_train, y_train, epochs=5, batch_size=32)
You can evaluate the performances of your network using the evaluate
method of PyToune's model;
loss_and_metrics = model.evaluate(x_test, y_test)
Or only predict on new data;
predictions = model.predict(x_test)
As you can see, PyToune is inspired a lot by the friendliness of Keras. See the PyToune documentation at PyToune.org for more.
Before installing PyToune, you must have a working version of PyTorch 0.3.0 in your environment.
- Install the stable version of PyToune:
pip install pytoune
- Install the latest version of PyToune:
pip install -U git+https://github.com/ulaval-graal/pytoune.git
PyToune (or pitoune in Québécois) used to be wood logs that flowed through the rivers. It was an efficient way to travel large pieces of wood across the country. We hope that PyToune will make your PyTorch neural networks training flow easily just like the "pitounes" used to.