DLC on Crane

Get started#

  • Run an interactive job on SLURM. For example:
$ srun --partition=gpu --gres=gpu --constraint='gpu_32gb&gpu_v100' --mem=32gb --ntasks-per-node=21 --nodes=1 --time=8:00:00 --pty $SHELL
  • Export your $HOME as your $WORK environment to aovid errors while installing packages, etc.
$ cd $HOME
$ export HOME=/work/group/user
$ cd $WORK

Load/Build DLC Environment#

  • Load required Anaconda and Cuda (for GPU use) into your session.
$ module load cuda
$ module load anaconda
  • Create a DeepLabCut-GPU environment from a .yaml file, install tensorflow-gpu, then start an IPython session.
$ wget "http://www.mousemotorlab.org/s/DLC-GPU.yaml"
$ conda env create -f DLC-GPU.yaml # run only once
$ conda install tensorflow-gpu==1.12 # run only once
$ conda activate DLC-GPU
$ nvidia-smi # check your GPU
$ ipython
  • Install DeepLabCutCore, import tensorflow, then import DLC in light mode.
In [ ]: !pip install deeplabcutcore
In [ ]: import tensorflow as tf
In [ ]: from tensorflow.python.client import device_lib # optional
In [ ]: device_lib.list_local_devices() # optional
In [ ]: import os
In [ ]: os.environ["DLClight"]="True"
In [ ]: import deeplabcutcore as deeplabcut

Train Your Neural Network#

  • Specify the path of your project's configuration file, config.yaml. Then, create your training dataset.
In [ ]: cfp = '/work/group/user/project/config.yaml'
In [ ]: deeplabcut.create_training_dataset(cfp,Shuffles=[1])
  • If the file resnet_v1_50.ckpt fail to load, try installing it again from source.
In [ ]: cd /work/group/user/.local/lib/python3.7/site-packages/deeplabcut/pose_estimation_tensorflow/models/pretrained/
In [ ]: !bash download.sh
  • Train your network (a minimum of ~200,000 iteration is recommended). If you want to save snapshots of your dataset, adjust saveiters=''. When you are satisifed with the number of iterations your neural network reached, you can stop it CTRL+C.
In [ ]: deeplabcut.train_network(cfp, shuffle=1, saveiters=1000, displayiters=10, maxiters=200000)

Evaluate Network and Label Video#

  • Evaluate you neural network, then analyze and label your video.
In [ ]: deeplabcut.evaluate_network(cfp, Shuffles=[1], plotting=True)
In [ ]: deeplabcut.extract_save_all_maps(cfp, Indices=[0, 5])
In [ ]: VideoType = '' # write down your video type
In [ ]: videofile_path = ['/work/group/user/project/videos/video.*']
In [ ]: deeplabcut.analyze_videos(cfp, videofile_path, videotype=VideoType, save_as_csv=True)
In [ ]: deeplabcut.create_labeled_video(cfp, videofile_path)