Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make code compatible with TF2 🔥 #1323

Merged
merged 48 commits into from Jun 30, 2021
Merged

Make code compatible with TF2 🔥 #1323

merged 48 commits into from Jun 30, 2021

Conversation

jeylau
Copy link
Member

@jeylau jeylau commented Jun 14, 2021

  • Refactored PoseDatasets and PoseNets and made code TensorFlow 2 compatible.

  • Benchmarked on 4 datasets (single- and multi-animal, w/ grayscale and color images) with TensorFlow (TF)1.15.5 (which serves as reference), TF2.3, and TF2.5; batch size 8, 30k iterations (except for the marmosets: 20k); 3 backbones (resnet_50, mobilenet_v2_0.5, efficientnet-b0); 2 GPU devices (TITAN RTX & GEFORCE GTX 1080). No significant main effects of either backbone or tf version were found. Training duration is reported relative to TF1 training time (Y axis, and value printed above each bar), and in seconds (underneath/within the bar).
    profiling

  • Not shown here is training with batch size 1 and TF2.5 with a single-animal project (openfield), which is ~4 min (~15%) slower than with TF1. Note that this is not observed with TF2.3.

# Conflicts:
#	conda-environments/DLC-CPU.yaml
#	deeplabcut/pose_estimation_tensorflow/__init__.py
#	deeplabcut/pose_estimation_tensorflow/core/predict.py
#	deeplabcut/pose_estimation_tensorflow/core/train.py
#	deeplabcut/pose_estimation_tensorflow/core/train_multianimal.py
#	deeplabcut/pose_estimation_tensorflow/dataset/factory.py
#	deeplabcut/pose_estimation_tensorflow/dataset/pose_dataset_scalecrop.py
#	deeplabcut/pose_estimation_tensorflow/datasets/pose_defaultdataset.py
#	deeplabcut/pose_estimation_tensorflow/datasets/pose_deterministic.py
#	deeplabcut/pose_estimation_tensorflow/datasets/pose_imgaug.py
#	deeplabcut/pose_estimation_tensorflow/datasets/pose_multianimal_imgaug.py
#	deeplabcut/pose_estimation_tensorflow/datasets/pose_tensorpack.py
#	deeplabcut/pose_estimation_tensorflow/nnet/efficientnet_builder.py
#	deeplabcut/pose_estimation_tensorflow/nnet/efficientnet_model.py
#	deeplabcut/pose_estimation_tensorflow/nnet/net_factory.py
#	deeplabcut/pose_estimation_tensorflow/nnet/pose_net.py
#	deeplabcut/pose_estimation_tensorflow/nnet/pose_net_efficientnet.py
#	deeplabcut/pose_estimation_tensorflow/nnet/pose_net_mobilenet.py
#	deeplabcut/pose_estimation_tensorflow/nnet/utils.py
#	deeplabcut/pose_estimation_tensorflow/predict_videos.py
#	setup.py
# Conflicts:
#	deeplabcut/pose_estimation_tensorflow/core/evaluate_multianimal.py
#	deeplabcut/pose_estimation_tensorflow/core/predict.py
#	deeplabcut/pose_estimation_tensorflow/core/train_multianimal.py
#	setup.py
@jeylau jeylau marked this pull request as draft June 14, 2021 18:45
@jeylau jeylau added the enhancement New feature or request label Jun 14, 2021
@jeylau jeylau marked this pull request as ready for review June 15, 2021 21:03
@MMathisLab MMathisLab self-requested a review June 29, 2021 15:51
@MMathisLab
Copy link
Member

Not sure why it's failing ... I attempted to pin tables, yet:

ERROR: Could not find a version that satisfies the requirement tables==3.6.1 (from versions: 2.3, 2.3.1, 2.4.0, 3.0.0, 3.1.0, 3.1.1, 3.2.0rc1, 3.2.0rc2, 3.2.0, 3.2.1.1, 3.2.2, 3.2.3, 3.2.3.1, 3.3.0, 3.4.0, 3.4.1, 3.4.2, 3.4.3, 3.4.4, 3.5.1, 3.5.2, 3.6.1)
ERROR: No matching distribution found for tables==3.6.1
Error: Process completed with exit code 1.

@jeylau
Copy link
Member Author

jeylau commented Jun 29, 2021

Yeah, that's odd; locally it builds fine with the same settings though (macOS/python3.9.5/updated pip). I also confirm that conda install -c conda-forge pytables solves the issue 🤔

@MMathisLab
Copy link
Member

MMathisLab commented Jun 30, 2021

Alright; order of operations matters here; and seems pytables might not have wheels for the latest 3.9.

That being said, as Jessy mentions above, using the conda file for installation works, as tables is built from conda forge. Tests pass on ubuntu for 3.9. For now, we will pin 3.8 in the conda file but to users, it is compatible with 3.9.

Screen Shot 2021-06-30 at 1 01 41 PM

Otherwise, all testscripts pass for me on MacOS and Ubuntu 20.04 LTS; for future ubunut 20.04 users, note there can be issues with wxPython wheels, so I made a how-to here: https://github.com/DeepLabCut/Docker4DeepLabCut2.0/wiki/ubuntu-20.04-LTS-fresh-install-guide

Next, I used a TF1 project and analyzed a video without issue in TF2.5; i.e., it's backwards compatible for single animal and latest maDLC projects. Thus, to use TF the only change is a fresh install with the new DEEPLABCUT.yaml is required.

@MMathisLab MMathisLab changed the title Make training-related code compatible with TF2 Make code compatible with TF2 Jun 30, 2021
Copy link
Member

@AlexEMG AlexEMG left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great job @jeylau!

@MMathisLab MMathisLab changed the title Make code compatible with TF2 Make code compatible with TF2 🔥 Jun 30, 2021
@AlexEMG AlexEMG merged commit 34eb7f6 into DeepLabCut:master Jun 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request Tensorflow 2
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants