/lightweight

algorithmic booty maximiser 💪🎯💪

Primary LanguageJupyter NotebookApache License 2.0Apache-2.0

lightweight 💪🎯💪

A squat detector algorithm running on fastai and alphapose.

The classifier uses the AlphaPose network as an intermediate step, and trains quickly using a pretrained resnet34 courtesy of fastai v2. Each frame is classified as one of 7 labels that I made up from my exercise routine.


image 💪😬💪 💪😙💪 💪🤪💪

I spent a long time trying to make this train on the regular unprocessed images from my webcam feed – it didn’t work.

The whole secret to training this network so simply and quickly (which I eventually figured out) was to use an intermediate network – in this case AlphaPose, a paper from 2018. Alphapose estimates the pose position and draws the colorful lines between the nodes.

As soon as the resnet34 was looking at the colorful pose outputs, instead of the raw images, it converged within a handful of epochs. It was cool to see the power of stacking these networks together.

image

Dataset

I built the dataset myself by taking a couple of videos and extracting the noteworthy frames, then uploading them to labelbox.com.

I manually labelled them into 6 categories (took me about 1 hour) the whole thing was free – and also the entire dataset was only 196 images.

Run

> conda activate lightweight
# webcam
> python lightweight.py 
# sample vid 
> python lightweight.py --vid --saveframe

Installation

> conda create -n lightweight python=3.8 pip jupyter
> conda activate lightweight
> conda install -c fastai -c pytorch -c anaconda fastai gh anaconda
> pip install -r requirements.txt

OpenPose Installation

CMU-Perceptual-Computing-Lab/openpose

AlphaPose Installation

MVIG-SJTU/AlphaPose

# 1. New conda env
conda create -n alphapose python=3.6 pip jupyter -y
conda activate alphapose

# 2. Install PyTorch
conda install pytorch==1.1.0 torchvision==0.3.0

Get AlphaPose

git clone https://github.com/MVIG-SJTU/AlphaPose.git
# git pull origin pull/592/head if you use PyTorch>=1.5
cd AlphaPose

# 4. install
-- export PATH=/usr/local/cuda/bin/:$PATH
-- export LD_LIBRARY_PATH=/usr/local/cuda/lib64/:$LD_LIBRARY_PATH
python -m pip install cython