A lightweight PyTorch wrapper for fast and easy neural network training and evaluation.
Project description
Simple-PyTorch-wrapper: assess fast and easy your neural network
Importance of easy and quick assessment of quality
A lightweight PyTorch wrapper that can be used to fasten process of training and setting up arbitrary Neural Network to quickly test an idea/setup. The wrapper provides an interface for both standard neural networks and CNNs, but can be extended to any architecture, with built-in visualization and performance tracking capabilities. The wrapper is customizable and aims to be used on any dataset.
Usage
pip install simple_pytorch_wrapper
This package is aimed to be as simple as possible. The following example trains on the example dataset in this package, using a simple feedforward network.
def main():
# For reproducibility
set_seed(0)
# Example data
X, Y = load_language_digit_example_dataset()
# Transform data accordingly (vectorizing) + squeezing for batching
X, Y = PytorchWrapper.vectorize_data(X, Y, NetworkType.FNN)
# Pytorch wrapper
wrapper = PytorchWrapper(X, Y)
network = FNNGenerator(
input_size=64*64, # flattened value of image of example dataset
output_size=10, # number of outputs
hidden_layers=[100, 500], # sizes of hidden layers
hidden_activations=[nn.ReLU(), nn.ReLU()], # activation functions for each hidden layer
)
# Create custom pytorch network
wrapper.upload_pyTorch_network(network)
wrapper.setup_training(batch_size=32, learning_rate=0.01, epochs=10)
# Training
wrapper.train_network(plot=True) # Enable plotting
# Visualization
wrapper.visualize()
You see that training a network from start to finish, with a clean visualization in less than 15 effective lines!
Upload your own network!
The network variable above is there to be defined by you. This is aimed to take in any Neural network design. The only caveat is to correctly shape your input. For a feedforward and CNN, these are already implemented by the vectorize_data(*args) function.
To get you started on the networks, there has been provided already NN generator classes for a feed-forward NN and a convolutional one. These can be used respectively by calling FNNGenerator(*args) and CNNGenerator(*args).
The function signature of the FNNGenerator is:
network = FNNGenerator(input_size: int,
output_size: int,
hidden_layers: List[int],
hidden_activations: Optional[List[nn.Module]]
)
While for the CNNGenerator, this is:
network = CNNGenerator(input_channels: int,
conv_layers: List[Dict[str, int]],
fc_layers: List[int],
output_size: int,
batch_size: Optional[int] = None,
use_pooling: bool = True)
Example runs
It can be hard to know the power of a tool, without having a solid example. By calling FNN_example_run() with the training params as function arguments, you get a run on the example data set for a FNN architecture. The CNN_example_run() does it with a CNN architecture.
Dataset
The data used for the example is the Sign Language Digits Dataset from the Turkey Ankara Ayrancı Anadolu High School students. This dataset is available at ardamavi/Sign-Language-Digits-Dataset.
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file simple_pytorch_wrapper-0.0.1.tar.gz.
File metadata
- Download URL: simple_pytorch_wrapper-0.0.1.tar.gz
- Upload date:
- Size: 8.8 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.12.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f6586e9ea91213625041e4e80ec72f87f03c0dbfa016761a10335ec8079483f4
|
|
| MD5 |
4bae5a572e0e1a68ea332bffed43614d
|
|
| BLAKE2b-256 |
58a608214949f32978de567e0fbdcddca39abb587372d906ad3a1c2a8cbec766
|
File details
Details for the file simple_pytorch_wrapper-0.0.1-py3-none-any.whl.
File metadata
- Download URL: simple_pytorch_wrapper-0.0.1-py3-none-any.whl
- Upload date:
- Size: 8.9 MB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.12.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a28e9584153113ee8a76246d3be42499ac6064ff8ce02b5859b3e022bda418f9
|
|
| MD5 |
8b8ac3867b8f35ea2e320e4971d7e2dc
|
|
| BLAKE2b-256 |
81e4a8eddd3b81f9ec35c111443fa7a86d4604d6859e2ec0b9aa8363e95e8a67
|