Skip to content

1enn0/intro-ml-with-pytorch

Repository files navigation

Introduction to Machine Learning with PyTorch

This repository contains some tutorials on machine learning using JupyterLab notebook and PyTorch.

Contents of this Repository

  • inference-cpp: code for the c++ inference application
  • notebooks: Jupyter notebooks containing the tutorials (including code)
    • 0_intro_machine_learning.ipynb: Basic introduction to machine learning
    • 1_pytorch_basic.ipynb: Train a simple neural network to learn a line equation
    • 2_pytorch_advanced.ipynb: Train an audio classification model using transfer learning
  • train: default training directory (used to saved trained model and spectrogram config)
  • test/data: directory containing some audio files used for testing

Setup

First, you neeed to clone this repository. Make sure to include the submodule(s) when cloning by running

git clone --recurse-submodules https://stash.steinberg-intra.net/scm/~lhannink/intro-ml-with-pytorch.git

In case you did a bare clone without the submodule flag, run

git submodule sync
git submodule update --init --recursive

to download the submodules for an existing checkout.

Dependencies

General

In order to run the tutorial notebooks and build the C++ application, you need to have the following stuff installed on your system:

  • cmake + supported build system for your platform (Ninja, Make, VS, Xcode, ...)
  • Python 3.8
  • pipenv

If you don't have Python 3.8 and pipenv installed have a look at INSTALLING_PYTHON.md.

Create Virtual Environment

The tutorial notebooks are intended to be run from within a Python virtual environment.

Open up a terminal in the directory of this repository and run

pipenv install

to automatically create a new virtual environment using the correct Python version and install the package dependencies.

Unfortunately, installing PyTorch through pipenv is not possible at the moment due to a bug, so we will have to use raw pip to install it:

CPU Version

Install this if you don't know if you have a CUDA-capable GPU. The training will be slower using the CPU version but there is no additional setup required.

pipenv run pip install torch==1.7.1+cpu torchvision==0.8.2+cpu torchaudio==0.7.1 -f https://download.pytorch.org/whl/torch_stable.html
pipenv run pip install fastai==2.1.9 fastaudio==0.1.4

CUDA Version

If you have a CUDA-capable GPU and have a working CUDA 11.0 installation (including corresponding cuDNN version), you can install the CUDA-enabled version:

pipenv run pip install torch==1.7.1+cu110 torchvision==0.8.2+cu110 torchaudio==0.7.1 -f https://download.pytorch.org/whl/torch_stable.html
pipenv run pip install fastai==2.1.9 fastaudio==0.1.4

Start JupyterLab

Start the JupyterLab server inside of your new virtual environment by running

pipenv run jupyter lab

still inside the directory of this repo.

A new instance of the Juypter server will be started and automatically open up the JupyterLab start page in your browser. We will only be interacting with the browser front-end from now on but you need to leave the server running in the background.

Using the file browser in the left pane, navigate into the notebooks/ directory and open up the first .ipynb file.

Test Sounds

This repository contains some sounds from freesound.org for testing purposes. The following sounds have been used:

About

Introduction to Machine Learning with PyTorch

Resources

Stars

Watchers

Forks