Visitar URL original
DeepLabCut 3.0 - Updates to COLABs and Notebooks for the PyTorch Engine by n-poulsen · Pull Request #2868 · DeepLabCut/DeepLabCut · GitHub
Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
update openfield COLAB
  • Loading branch information
Niels Poulsen
Niels Poulsen committed Feb 7, 2025
commit ba8569d4bc6f54d91e3f7852658005c4b231bfa1
76 changes: 44 additions & 32 deletions examples/COLAB/COLAB_DEMO_mouse_openfield.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,12 @@
"id": "TGChzLdc-lUJ"
},
"source": [
"# DeepLabCut Toolbox - Colab Demo on Topview Mouse Data\n",
"https://github.com/DeepLabCut/DeepLabCut\n",
"# DeepLabCut 3.0 Toolbox - Colab Demo on TopView Mouse Data\n",
"\n",
"Some useful links:\n",
"\n",
"- [DeepLabCut's GitHub: github.com/DeepLabCut/DeepLabCut](https://github.com/DeepLabCut/DeepLabCut)\n",
"- [DeepLabCut's Documentation: User Guide for Single Animal projects](https://deeplabcut.github.io/DeepLabCut/docs/standardDeepLabCut_UserGuide.html)\n",
"\n",
"![alt text](https://images.squarespace-cdn.com/content/v1/57f6d51c9f74566f55ecf271/1559935526258-KFYZC8BDHK01ZIDPNVIX/mouse_skel_trail.gif?format=450w)\n",
"\n",
Expand All @@ -42,17 +46,9 @@
"id": "txoddlM8hLKm"
},
"source": [
"## First, go to \"Runtime\" ->\"change runtime type\"->select \"Python3\", and then select \"GPU\""
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Installs a CUDA version compatible with tensorflow on COLAB\n",
"!apt update && apt install cuda-11-8"
"## Installation\n",
"\n",
"### First, go to \"Runtime\" ->\"change runtime type\"->select \"Python3\", and then select \"GPU\""
]
},
{
Expand Down Expand Up @@ -91,7 +87,7 @@
"source": [
"# Install the latest DeepLabCut version (this will take a few minutes to install all the dependencies!)\n",
"%cd /content/cloned-DLC-repo/\n",
"!pip install \".[tf]\""
"%pip install \".\""
]
},
{
Expand All @@ -100,7 +96,7 @@
"id": "XymV_Hnlp1OJ"
},
"source": [
"## PLEASE, click \"restart runtime\" from the output above before proceeding! "
"### PLEASE, click \"restart runtime\" from the output above before proceeding!"
]
},
{
Expand All @@ -122,7 +118,7 @@
},
"outputs": [],
"source": [
"#create a path variable that links to the config file:\n",
"# Create a path variable that links to the config file:\n",
"path_config_file = '/content/cloned-DLC-repo/examples/openfield-Pranav-2018-10-30/config.yaml'\n",
"\n",
"# Loading example data set:\n",
Expand All @@ -147,14 +143,26 @@
},
"outputs": [],
"source": [
"#let's also change the display and save_iters just in case Colab takes away the GPU... \n",
"#if that happens, you can reload from a saved point. Typically, you want to train to 200,000 + iterations.\n",
"#more info and there are more things you can set: https://github.com/DeepLabCut/DeepLabCut/wiki/DOCSTRINGS#train_network\n",
"# Let's also change the display and save_epochs just in case Colab takes away\n",
"# the GPU... If that happens, you can reload from a saved point using the\n",
"# `snapshot_path` argument to `deeplabcut.train_network`:\n",
"# deeplabcut.train_network(..., snapshot_path=\"/content/.../snapshot-050.pt\")\n",
"\n",
"# Typically, you want to train to ~200 epochs. We set the batch size to 8 to\n",
"# utilize the GPU's capabilities.\n",
"\n",
"deeplabcut.train_network(path_config_file, shuffle=1, displayiters=100,saveiters=500, maxiters=10000)\n",
"# More info and there are more things you can set:\n",
"# https://deeplabcut.github.io/DeepLabCut/docs/standardDeepLabCut_UserGuide.html#g-train-the-network\n",
"\n",
"#this will run until you stop it (CTRL+C), or hit \"STOP\" icon, or when it hits the end (default, 1.03M iterations). \n",
"#Whichever you chose, you will see what looks like an error message, but it's not an error - don't worry...."
"deeplabcut.train_network(\n",
" path_config_file,\n",
" shuffle=1,\n",
" save_epochs=5,\n",
" epochs=200,\n",
" batch_size=8,\n",
")\n",
"\n",
"# This will run until you stop it (CTRL+C), or hit \"STOP\" icon, or when it hits the end."
]
},
{
Expand All @@ -163,7 +171,9 @@
"id": "RiDwIVf5-3H_"
},
"source": [
"We recommend you run this for ~1,000 iterations, just as a demo. This should take around 20 min. Note, that **when you hit \"STOP\" you will get a KeyInterrupt \"error\"! No worries! :)**"
"We recommend you run this for ~100 epochs, just as a demo. This should take around 15 minutes. Note, that **when you hit \"STOP\" you will get a `KeyboardInterrupt` \"error\"! No worries! :)**\n",
"\n",
"A new snapshot is saved every `save_epochs` epochs. So once you hit 80 epochs, your latest snapshot in `/content/cloned-DLC-repo/examples/openfield-Pranav-2018-10-30/dlc-models-pytorch/iteration-0/openfieldOct30-trainset95shuffle1/train` should be `snapshot-80.pt`. The best snapshot evaluated during training is saved, and is named `snapshot-best-XX.pt`, where `XX` is the number of epochs the model was trained with."
]
},
{
Expand All @@ -185,10 +195,10 @@
},
"outputs": [],
"source": [
"%matplotlib notebook\n",
"deeplabcut.evaluate_network(path_config_file,plotting=True)\n",
"deeplabcut.evaluate_network(path_config_file, plotting=True)\n",
"\n",
"# Here you want to see a low pixel error! Of course, it can only be as good as the labeler, so be sure your labels are good!"
"# Here you want to see a low pixel error! Of course, it can only be as\n",
"# good as the labeler, so be sure your labels are good!"
]
},
{
Expand All @@ -198,7 +208,8 @@
},
"source": [
"**Check the images**:\n",
"You can go look in the newly created \"evalutaion-results\" folder at the images. At around 3500 iterations, the error is ~3 pixels (but this can vary on how your demo data was split for training)"
"\n",
"You can go look in the newly created `\"evalutaion-results-pytorch\"` folder at the images. At around 100 epochs, the error is ~3 pixels (but this can vary on how your demo data was split for training)."
]
},
{
Expand All @@ -212,7 +223,7 @@
"\n",
"The results are stored in hd5 file in the same directory where the video resides. \n",
"\n",
"**On the demo data, this should take around ~ 3 min! (The demo frames are 640x480, which should run around 35 FPS on the google-provided GPU)**"
"**On the demo data, this should take around ~ 90 seconds! (The demo frames are 640x480, which should run around 25 FPS on the google-provided T4 GPU)**"
]
},
{
Expand All @@ -223,8 +234,9 @@
},
"outputs": [],
"source": [
"videofile_path = ['/content/cloned-DLC-repo/examples/openfield-Pranav-2018-10-30/videos/m3v1mp4.mp4'] #Enter the list of videos to analyze.\n",
"deeplabcut.analyze_videos(path_config_file,videofile_path, videotype='.mp4')"
"# Enter the list of videos to analyze.\n",
"videofile_path = [\"/content/cloned-DLC-repo/examples/openfield-Pranav-2018-10-30/videos/m3v1mp4.mp4\"]\n",
"deeplabcut.analyze_videos(path_config_file, videofile_path, videotype=\".mp4\")"
]
},
{
Expand All @@ -245,7 +257,7 @@
},
"outputs": [],
"source": [
"deeplabcut.create_labeled_video(path_config_file,videofile_path)"
"deeplabcut.create_labeled_video(path_config_file, videofile_path)"
]
},
{
Expand All @@ -266,7 +278,7 @@
},
"outputs": [],
"source": [
"deeplabcut.plot_trajectories(path_config_file,videofile_path)"
"deeplabcut.plot_trajectories(path_config_file, videofile_path)"
]
}
],
Expand Down