Skip to main content

Neural network helper for Pytorch.

Project description

nn-helper

About The Project

This project is a wrapper for Pytorch neural networks (NNs) to obfuscate functionalities that are always used during training and testing of NNs. Such as loggers, training loops, and saving of NNs.

(back to top)

Built With

These are the libraries and frameworks with which the library is constructed:

(back to top)

Getting Started Locally

This section explains how to set-up the repository locally from this repository. Note that this explanation is compatible for a MacOS / Linux environment.

Prerequisites

  1. Have at least Python 3.8 installed on your local machine.
  2. Make sure to have make installed. Else, you can copy paste commands from the Makefile into your terminal.

Installation

  1. Clone the repo and cd into it
    git clone https://gitlab.com/markdeblaauw/nn-helper.git
    
  2. Create a Python virtual environment
    make virtual_env
    . venv/bin/activate
    
  3. Install the development Python package
    make install_dev_package
    

(back to top)

Usage

You can find the following example of using the library in the examples folder:

import math

import models.linear_regression as linear_model
import torch

import nn_helper
from nn_helper.callbacks.verbose_logger import VerboseLogger


def run_model():
    # Create Tensors to hold input and outputs.
    x = torch.linspace(-math.pi, math.pi, 2000)
    y = torch.sin(x)

    p = torch.tensor([1, 2, 3])
    xx = x.unsqueeze(-1).pow(p)

    # Only 1 sample. Hence, batch size of 1.
    data_loader = torch.utils.data.DataLoader(dataset=linear_model.Dataset(x=xx, y=y), batch_size=1)

    loss_fn = torch.nn.MSELoss()

    model = linear_model.LinearRegression()

    optimizer = torch.optim.Adam(params=model.parameters(), lr=1e-2)

    # Train the model with 10 epochs and use
    # Verbose Logger to put metrics to terminal.
    nn_helper.fit(
        model=model,
        data_loader=data_loader,
        epochs=10,
        loss_fn=loss_fn,
        optimizer=optimizer,
        callbacks=[VerboseLogger()],
    )

Testing

You can run unit tests locally as follows:

make tests

A coverage report can be generated with the intention of 100% coverage:

make coverage_report

(back to top)

Roadmap

The library is not complete yet. Certain features, such as metric computation, testing and many callbacks, are not implemented yet. These will be implemented in due time.

(back to top)

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

nn_helper-1.1.1.tar.gz (10.4 kB view hashes)

Uploaded Source

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