Skip to main content

A lightweight PyTorch wrapper for fast and easy neural network training and evaluation.

Project description

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.

from simple_pytorch_wrapper import PytorchWrapper, FNNGenerator, NetworkType
from simple_pytorch_wrapper import set_seed, load_language_digit_example_dataset
import torch.nn as nn

def main():
    # For reproducibility
    set_seed(0)

    # Example data
    X, Y = load_language_digit_example_dataset()

    # Transform shape of *image* data accordingly
    X, Y = PytorchWrapper.vectorize_image_data(X, Y, NetworkType.FNN) 

    # Pytorch wrapper
    wrapper = PytorchWrapper(X, Y, classification=True) 
    
    # Generate a feedforward neural network
    network = FNNGenerator(
    input_size=64*64,  
    output_size=10,   
    hidden_layers=[100, 500],  
    hidden_activations=[nn.ReLU(), nn.ReLU()]
    )
    
    # Upload python network to wrapper
    wrapper.upload_pytorch_network(network) 

    # Training
    wrapper.setup_training(batch_size=32, learning_rate=0.001, epochs=10)
    wrapper.train_network(plot=False)

    # Visuals
    wrapper.visualize()

if __name__ == "__main__":
    main()

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. In case of image analysis, this is already implemented for a feedforward and CNN, these are already implemented by the vectorize_image_data(*args) function. If you already have correctly formatted your image_data, then this static function call is not necessary.

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: int,
                image_height: int, 
                image_width: int,
                seed: Optional[int] = None,
                use_pooling: bool = False
            )

The image_height and image_widthare necessary to get the dimensionality of the forward layers in the CNN right.

Turning off warnings

There has been implemented several warnings to ensure proper use. To turn off these warnings, place suppress_warnings() at the top of your code.

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

simple_pytorch_wrapper-0.0.6.tar.gz (8.8 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

simple_pytorch_wrapper-0.0.6-py3-none-any.whl (8.9 MB view details)

Uploaded Python 3

File details

Details for the file simple_pytorch_wrapper-0.0.6.tar.gz.

File metadata

  • Download URL: simple_pytorch_wrapper-0.0.6.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

Hashes for simple_pytorch_wrapper-0.0.6.tar.gz
Algorithm Hash digest
SHA256 467f4db0ed450679b94ebf2de2ce0897735ea6e8edc523f2ce96849a122f2c50
MD5 2f0a3715989dfebdb8bc42d2a06e83ff
BLAKE2b-256 5a26ee2378451108ef3d4a52fd1f847347281754f5330fb45f78ba9fc23d4d1d

See more details on using hashes here.

File details

Details for the file simple_pytorch_wrapper-0.0.6-py3-none-any.whl.

File metadata

File hashes

Hashes for simple_pytorch_wrapper-0.0.6-py3-none-any.whl
Algorithm Hash digest
SHA256 29b3568145baa83e77c96b3a3f9033a08698d6e849d3731a42b5f71d284aa79d
MD5 d3930450258e7240ae7b95ac099d16a4
BLAKE2b-256 0208bce97fca068c0107ac20b31a4bbe3d58f7b2207e9a0960e3b1d335de2fcf

See more details on using hashes here.

Supported by

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