Giter Club home page Giter Club logo

deepposekit's Introduction

You have just found DeepPoseKit.

DeepPoseKit is a software toolkit with a high-level API for 2D pose estimation of user-defined keypoints using deep learning—written in Python and built using Tensorflow and Keras. Use DeepPoseKit if you need:

  • tools for annotating images or video frames with user-defined keypoints
  • a straightforward but flexible data augmentation pipeline using the imgaug package
  • a Keras-based interface for initializing, training, and evaluating pose estimation models
  • easy-to-use methods for saving and loading models and making predictions on new data

DeepPoseKit is designed with a focus on usability and extensibility, as being able to go from idea to result with the least possible delay is key to doing good research.

DeepPoseKit is currently limited to individual pose estimation. If individuals can be easily distinguished visually (i.e., they have differently colored bodies or are marked in some way), then multiple individuals can simply be labeled with separate keypoints (head1, tail1, head2, tail2, etc.). Otherwise DeepPoseKit can be extended to multiple individuals by first localizing, tracking, and cropping individuals with additional software such as idtracker.ai, pinpoint, or Tracktor.

Localization (without tracking) can also be achieved with deep learning software like keras-retinanet, the Tensorflow Object Detection API, or MatterPort's Mask R-CNN.

Check out our paper to find out more.

How to use DeepPoseKit

DeepPoseKit is designed for easy use. For example, training and saving a model requires only a few lines of code:

from deepposekit.io import DataGenerator, TrainingGenerator
from deepposekit.models import StackedDenseNet

data_generator = DataGenerator('/path/to/annotation_data.h5')
train_generator = TrainingGenerator(data_generator)
model = StackedDenseNet(train_generator)
model.fit(batch_size=16, n_workers=8)
model.save('/path/to/saved_model.h5')

Loading a trained model and running predictions on new data is also straightforward. For example, running predictions on a new video:

from deepposekit.models import load_model
from deepposekit.io import VideoReader

model = load_model('/path/to/saved_model.h5')
reader = VideoReader('/path/to/video.mp4')
predictions = model.predict(reader)

Using DeepPoseKit is a 4-step process:

For more details:

"I already have annotated data"

DeepPoseKit is designed to be extensible, so loading data in other formats is possible.

If you have annotated data from DeepLabCut (http://deeplabcut.org), try our (experimental) example notebook for loading data in this format. Open In Colab

Have data in another format? You can write your own custom generator to load it. Check out the example for writing custom data generators. Open In Colab

Installation

DeepPoseKit requires Tensorflow for training and using pose estimation models. Tensorflow should be manually installed, along with dependencies such as CUDA and cuDNN, before installing DeepPoseKit:

DeepPoseKit has only been tested on Ubuntu 18.04, which is the recommended system for using the toolkit.

Install the latest stable release with pip:

pip install --update deepposekit

Install the latest development version with pip:

pip install --update git+https://www.github.com/jgraving/deepposekit.git

You can download example datasets from our DeepPoseKit Data repository:

git clone https://www.github.com/jgraving/deepposekit-data

Installing with Anaconda on Windows

To install DeepPoseKit on Windows, you must first manually install Shapely, one of the dependencies for the imgaug package:

conda install -c conda-forge shapely

We also recommend installing DeepPoseKit from within Python rather than using the command line, either from within Jupyter or another IDE, to ensure it is installed in the correct working environment:

import sys
!{sys.executable} -m pip install --update deepposekit

Contributors and Development

DeepPoseKit was developed by Jake Graving and Daniel Chae, and is still being actively developed. .

We welcome community involvement and public contributions to the toolkit. If you wish to contribute, please fork the repository to make your modifications and submit a pull request.

If you'd like to get involved with developing DeepPoseKit, get in touch ([email protected]) and check out our development roadmap to see future plans for the package.

Issues

Please submit bugs or feature requests to the GitHub issue tracker. Please limit reported issues to the DeepPoseKit codebase and provide as much detail as you can with a minimal working example if possible.

If you experience problems with Tensorflow, such as installing CUDA or cuDNN dependencies, then please direct issues to those development teams.

License

Released under a Apache 2.0 License. See LICENSE for details.

References

If you use DeepPoseKit for your research please cite our open-access paper:

@article{graving2019deepposekit,
         title={DeepPoseKit, a software toolkit for fast and robust animal pose estimation using deep learning},
         author={Graving, Jacob M and Chae, Daniel and Naik, Hemal and Li, Liang and Koger, Benjamin and Costelloe, Blair R and Couzin, Iain D},
         journal={eLife},
         volume={8},
         pages={e47994},
         year={2019},
         publisher={eLife Sciences Publications Limited}
         url={https://doi.org/10.7554/eLife.47994},
         }

You can also read our open-access preprint.

If you use the imgaug package for data augmentation, please also consider citing it.

If you use data that was annotated with the DeepLabCut package (http://deeplabcut.org) for your research, be sure to cite it.

Please also consider citing the relevant references for the pose estimation model(s) used in your research, which can be found in the documentation (i.e., StackedDenseNet, StackedHourglass, DeepLabCut, LEAP).

News

deepposekit's People

Contributors

denispolygalov avatar eduramiba avatar enteee avatar jgraving avatar selmaan avatar urs-waldmann avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

deepposekit's Issues

Problem with defining a model in step 3 notebook

Screenshot from 2019-10-28 14-38-03

Screenshot from 2019-10-28 14-38-09

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-20-6e9a27fdca9a> in <module>()
----> 1 model = StackedDenseNet(train_generator, n_stacks=2, growth_rate=32, pretrained=True)
      2 
      3 #model = DeepLabCut(train_generator, backbone="resnet50")
      4 #model = DeepLabCut(train_generator, backbone="mobilenetv2", alpha=0.35) # Increase alpha to improve accuracy
      5 #model = DeepLabCut(train_generator, backbone="densenet121")

/scratch/sjn-p3/anaconda/anaconda3/lib/python3.6/site-packages/deepposekit/models/StackedDenseNet.py in __init__(self, train_generator, n_stacks, n_transitions, growth_rate, bottleneck_factor, compression_factor, pretrained, subpixel, **kwargs)
    127         self.n_transitions = n_transitions
    128         self.pretrained = pretrained
--> 129         super(StackedDenseNet, self).__init__(train_generator, subpixel, **kwargs)
    130 
    131     def __init_model__(self):

/scratch/sjn-p3/anaconda/anaconda3/lib/python3.6/site-packages/deepposekit/models/engine.py in __init__(self, train_generator, subpixel, **kwargs)
     35             if self.train_model is NotImplemented:
     36                 self.__init_input__(config["image_shape"])
---> 37                 self.__init_model__()
     38                 self.__init_train_model__()
     39             if self.train_generator is not None:

/scratch/sjn-p3/anaconda/anaconda3/lib/python3.6/site-packages/deepposekit/models/StackedDenseNet.py in __init_model__(self)
    167         if n_transitions <= self.train_generator.downsample_factor:
    168             raise ValueError(
--> 169                 "`n_transitions` <= `downsample_factor`. Increase `n_transitions` or decrease `downsample_factor`."
    170                 " If `n_transitions` is -1 (the default), check that your image resolutions can be repeatedly downsampled (are divisible by 2 repeatedly)."
    171             )

ValueError: `n_transitions` <= `downsample_factor`. Increase `n_transitions` or decrease `downsample_factor`. If `n_transitions` is -1 (the default), check that your image resolutions can be repeatedly downsampled (are divisible by 2 repeatedly).


Shape mismatch error when training with `DLCDataGenerator`

Hi Jake, your DLC train notebook crashes when I use my own moth dataset. Here is my saved Jupyter notebook which also has the complete error log: https://colab.research.google.com/drive/1yr5YybbAtnSCdkOC4Gbw9GKhrIGATEGS?authuser=1

Could you please guide how to fix this error?

(/scratch3/3d_pose/DeepPoseKitEnv) [jalal@goku examples]$ pwd
/scratch3/3d_pose/animalpose/dpk/DeepPoseKit/examples


(/scratch3/3d_pose/DeepPoseKitEnv) [jalal@goku examples]$ python dlc_train.py 
1.15.0
{'Task': 'moth-filtered', 'scorer': 'Mona', 'date': 'Dec6', 'project_path': '/projectnb/ivcgroup/jalal/moth-filtered-Mona-2019-12-06', 'video_sets': {'/projectnb/ivcgroup/jalal/moth-filtered-Mona-2019-12-06/videos/moth.avi': {'crop': '0, 800, 0, 600'}}, 'bodyparts': ['head', 'rightWingTip', 'leftWingTip', 'abdomenTip'], 'start': 0, 'stop': 1, 'numframes2pick': 100, 'skeleton': [['bodypart1', 'bodypart2'], ['objectA', 'bodypart3']], 'skeleton_color': 'black', 'pcutoff': 0.1, 'dotsize': 12, 'alphavalue': 0.7, 'colormap': 'jet', 'TrainingFraction': [0.95], 'iteration': 0, 'resnet': None, 'snapshotindex': -1, 'batch_size': 8, 'cropping': False, 'x1': 0, 'x2': 640, 'y1': 277, 'y2': 624, 'corner2move2': [50, 50], 'move2corner': True, 'default_net_type': 'resnet_50', 'default_augmenter': 'default'}
WARNING:tensorflow:From /scratch3/3d_pose/DeepPoseKitEnv/lib/python3.6/site-packages/tensorflow_core/python/ops/resource_variable_ops.py:1630: calling BaseResourceVariable.__init__ (from tensorflow.python.ops.resource_variable_ops) with constraint is deprecated and will be removed in a future version.
Instructions for updating:
If using Keras pass *_constraint arguments to layers.
2019-12-10 15:04:24.550212: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcuda.so.1
2019-12-10 15:04:24.595099: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1618] Found device 0 with properties: 
name: GeForce GTX 1080 Ti major: 6 minor: 1 memoryClockRate(GHz): 1.6705
pciBusID: 0000:05:00.0
2019-12-10 15:04:24.596212: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1618] Found device 1 with properties: 
name: GeForce GTX 1080 Ti major: 6 minor: 1 memoryClockRate(GHz): 1.6705
pciBusID: 0000:06:00.0
2019-12-10 15:04:24.596536: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcudart.so.10.0
2019-12-10 15:04:24.597751: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcublas.so.10.0
2019-12-10 15:04:24.598866: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcufft.so.10.0
2019-12-10 15:04:24.599135: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcurand.so.10.0
2019-12-10 15:04:24.600569: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcusolver.so.10.0
2019-12-10 15:04:24.601678: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcusparse.so.10.0
2019-12-10 15:04:24.604910: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcudnn.so.7
2019-12-10 15:04:24.610145: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1746] Adding visible gpu devices: 0, 1
2019-12-10 15:04:24.610503: I tensorflow/core/platform/cpu_feature_guard.cc:142] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA
2019-12-10 15:04:24.616205: I tensorflow/core/platform/profile_utils/cpu_utils.cc:94] CPU Frequency: 3597855000 Hz
2019-12-10 15:04:24.616695: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x559cf7c5d7b0 initialized for platform Host (this does not guarantee that XLA will be used). Devices:
2019-12-10 15:04:24.616720: I tensorflow/compiler/xla/service/service.cc:176]   StreamExecutor device (0): Host, Default Version
2019-12-10 15:04:24.855663: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x559cf7cf0e30 initialized for platform CUDA (this does not guarantee that XLA will be used). Devices:
2019-12-10 15:04:24.855736: I tensorflow/compiler/xla/service/service.cc:176]   StreamExecutor device (0): GeForce GTX 1080 Ti, Compute Capability 6.1
2019-12-10 15:04:24.855764: I tensorflow/compiler/xla/service/service.cc:176]   StreamExecutor device (1): GeForce GTX 1080 Ti, Compute Capability 6.1
2019-12-10 15:04:24.864118: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1618] Found device 0 with properties: 
name: GeForce GTX 1080 Ti major: 6 minor: 1 memoryClockRate(GHz): 1.6705
pciBusID: 0000:05:00.0
2019-12-10 15:04:24.866477: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1618] Found device 1 with properties: 
name: GeForce GTX 1080 Ti major: 6 minor: 1 memoryClockRate(GHz): 1.6705
pciBusID: 0000:06:00.0
2019-12-10 15:04:24.866581: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcudart.so.10.0
2019-12-10 15:04:24.866635: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcublas.so.10.0
2019-12-10 15:04:24.866683: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcufft.so.10.0
2019-12-10 15:04:24.866730: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcurand.so.10.0
2019-12-10 15:04:24.866777: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcusolver.so.10.0
2019-12-10 15:04:24.866825: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcusparse.so.10.0
2019-12-10 15:04:24.866872: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcudnn.so.7
2019-12-10 15:04:24.875663: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1746] Adding visible gpu devices: 0, 1
2019-12-10 15:04:24.875759: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcudart.so.10.0
2019-12-10 15:04:24.883670: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1159] Device interconnect StreamExecutor with strength 1 edge matrix:
2019-12-10 15:04:24.883718: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1165]      0 1 
2019-12-10 15:04:24.883749: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1178] 0:   N Y 
2019-12-10 15:04:24.883773: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1178] 1:   Y N 
2019-12-10 15:04:24.889842: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1304] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 9972 MB memory) -> physical GPU (device: 0, name: GeForce GTX 1080 Ti, pci bus id: 0000:05:00.0, compute capability: 6.1)
2019-12-10 15:04:24.892445: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1304] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:1 with 10479 MB memory) -> physical GPU (device: 1, name: GeForce GTX 1080 Ti, pci bus id: 0000:06:00.0, compute capability: 6.1)
WARNING:tensorflow:From /scratch3/3d_pose/DeepPoseKitEnv/lib/python3.6/site-packages/deepposekit/models/backend/utils.py:35: where (from tensorflow.python.ops.array_ops) is deprecated and will be removed in a future version.
Instructions for updating:
Use tf.where in 2.0, which has the same broadcast rule as np.where
2019-12-10 15:04:44.034373: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcudnn.so.7
2019-12-10 15:04:45.322586: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcublas.so.10.0
2019-12-10 15:04:48.539242: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcufft.so.10.0
500/500 [==============================] - 13s 26ms/sample
37.74724634267033
/scratch3/3d_pose/DeepPoseKitEnv/lib/python3.6/site-packages/deepposekit/models/engine.py:145: UserWarning: 
Automatically compiling with default settings: model.compile('adam', 'mse')
Call model.compile() manually to use non-default settings.

  """\nAutomatically compiling with default settings: model.compile('adam', 'mse')\n"""
Epoch 1/100
Traceback (most recent call last):
  File "dlc_train.py", line 204, in <module>
    steps_per_epoch=200,
  File "/scratch3/3d_pose/DeepPoseKitEnv/lib/python3.6/site-packages/deepposekit/models/engine.py", line 174, in fit
    **kwargs
  File "/scratch3/3d_pose/DeepPoseKitEnv/lib/python3.6/site-packages/tensorflow_core/python/keras/engine/training.py", line 1296, in fit_generator
    steps_name='steps_per_epoch')
  File "/scratch3/3d_pose/DeepPoseKitEnv/lib/python3.6/site-packages/tensorflow_core/python/keras/engine/training_generator.py", line 265, in model_iteration
    batch_outs = batch_function(*batch_data)
  File "/scratch3/3d_pose/DeepPoseKitEnv/lib/python3.6/site-packages/tensorflow_core/python/keras/engine/training.py", line 991, in train_on_batch
    extract_tensors_from_dataset=True)
  File "/scratch3/3d_pose/DeepPoseKitEnv/lib/python3.6/site-packages/tensorflow_core/python/keras/engine/training.py", line 2537, in _standardize_user_data
    y, self._feed_loss_fns, feed_output_shapes)
  File "/scratch3/3d_pose/DeepPoseKitEnv/lib/python3.6/site-packages/tensorflow_core/python/keras/engine/training_utils.py", line 741, in check_loss_and_target_compatibility
    ' while using as loss `' + loss_name + '`. '
ValueError: A target array with shape (5, 75, 100, 10) was passed for an output of shape (None, 74, 100, 10) while using as loss `mean_squared_error`. This loss expects targets to have the same shape as the output.
terminate called without an active exception
Aborted
(/scratch3/3d_pose/DeepPoseKitEnv) [jalal@goku examples]$ 

Here is a list of all packages I have installed:

(/scratch3/3d_pose/DeepPoseKitEnv) [jalal@goku examples]$ pip list
Package                Version            
---------------------- -------------------
absl-py                0.8.1              
astor                  0.8.0              
attrs                  19.3.0             
backcall               0.1.0              
bleach                 3.1.0              
certifi                2019.11.28         
chardet                3.0.4              
Click                  7.0                
cycler                 0.10.0             
decorator              4.4.1              
deeplabcut             2.1.4              
deepposekit            0.3.4              
defusedxml             0.6.0              
easydict               1.9                
entrypoints            0.3                
gast                   0.2.2              
google-pasta           0.1.8              
grpcio                 1.25.0             
h5py                   2.10.0             
idna                   2.8                
imageio                2.6.1              
imageio-ffmpeg         0.3.0              
imgaug                 0.3.0              
importlib-metadata     1.2.0              
intel-openmp           2020.0.133         
ipykernel              5.1.3              
ipython                7.10.1             
ipython-genutils       0.2.0              
ipywidgets             7.5.1              
jedi                   0.15.1             
Jinja2                 2.10.3             
joblib                 0.14.0             
jsonschema             3.2.0              
jupyter                1.0.0              
jupyter-client         5.3.4              
jupyter-console        6.0.0              
jupyter-core           4.6.1              
Keras-Applications     1.0.8              
Keras-Preprocessing    1.1.0              
kiwisolver             1.1.0              
Markdown               3.1.1              
MarkupSafe             1.1.1              
matplotlib             3.0.3              
mistune                0.8.4              
mock                   3.0.5              
more-itertools         8.0.2              
moviepy                1.0.1              
msgpack                0.6.2              
msgpack-numpy          0.4.4.3            
nbconvert              5.6.1              
nbformat               4.4.0              
networkx               2.4                
notebook               6.0.2              
numexpr                2.7.0              
numpy                  1.17.4             
opencv-python          3.4.5.20           
opencv-python-headless 4.1.2.30           
opt-einsum             3.1.0              
pandas                 0.25.3             
pandocfilters          1.4.2              
parso                  0.5.1              
patsy                  0.5.1              
pexpect                4.7.0              
pickleshare            0.7.5              
Pillow                 6.2.1              
pip                    19.3.1             
proglog                0.1.9              
prometheus-client      0.7.1              
prompt-toolkit         3.0.2              
protobuf               3.11.1             
psutil                 5.6.7              
ptyprocess             0.6.0              
Pygments               2.5.2              
pyparsing              2.4.5              
Pypubsub               4.0.3              
pyrsistent             0.15.6             
python-dateutil        2.8.1              
pytz                   2019.3             
PyWavelets             1.1.1              
PyYAML                 5.2                
pyzmq                  18.1.1             
qtconsole              4.6.0              
requests               2.22.0             
ruamel.yaml            0.16.5             
ruamel.yaml.clib       0.2.0              
scikit-image           0.16.2             
scikit-learn           0.22               
scipy                  1.3.3              
Send2Trash             1.5.0              
setuptools             42.0.2.post20191203
Shapely                1.6.4.post2        
six                    1.13.0             
statsmodels            0.10.1             
tables                 3.4.3              
tabulate               0.8.6              
tensorboard            1.15.0             
tensorflow-estimator   1.15.1             
tensorflow-gpu         1.15.0             
tensorpack             0.9.8              
termcolor              1.1.0              
terminado              0.8.3              
testpath               0.4.4              
tornado                6.0.3              
tqdm                   4.40.1             
traitlets              4.3.3              
urllib3                1.25.7             
wcwidth                0.1.7              
webencodings           0.5.1              
Werkzeug               0.16.0             
wheel                  0.33.6             
widgetsnbextension     3.5.1              
wrapt                  1.11.2             
wxPython               4.0.3              
zipp                   0.6.0              

Here's the Python code:

(/scratch3/3d_pose/DeepPoseKitEnv) [jalal@goku examples]$ cat dlc_train.py 
import sys
import tensorflow as tf
print(tf.__version__)
import numpy as np
import matplotlib.pyplot as plt
import glob

from deepposekit.io import TrainingGenerator, DLCDataGenerator
from deepposekit.augment import FlipAxis
import imgaug.augmenters as iaa
import imgaug as ia

from deepposekit.models import (StackedDenseNet,
                                DeepLabCut,
                                StackedHourglass,
                                LEAP)
from tensorflow.keras.callbacks import ReduceLROnPlateau, EarlyStopping

from deepposekit.callbacks import Logger, ModelCheckpoint
from deepposekit.models import load_model

import time
from os.path import expanduser

try:
    import google.colab
    IN_COLAB = True
except:
    IN_COLAB = False

data_generator = DLCDataGenerator(
    project_path='/scratch3/3d_pose/animalpose/experiments/moth-filtered-Mona-2019-12-06_95p_DONE/'
)

print(data_generator.dlcconfig)

data_generator.graph = np.array([-1, 0, 0, 0])

data_generator.swap_index = np.array([-1, 2, 1, -1])


image, keypoints = data_generator[0]

plt.figure(figsize=(5,5))
image = image[0] if image.shape[-1] is 3 else image[0, ..., 0]
cmap = None if image.shape[-1] is 3 else 'gray'
plt.imshow(image, cmap=cmap, interpolation='none')
for idx, jdx in enumerate(data_generator.graph):
    if jdx > -1:
        plt.plot(
            [keypoints[0, idx, 0], keypoints[0, jdx, 0]],
            [keypoints[0, idx, 1], keypoints[0, jdx, 1]],
            'r-'
        )

plt.scatter(keypoints[0, :, 0], keypoints[0, :, 1], c=np.arange(data_generator.keypoints_shape[0]), s=50, cmap=plt.cm.hsv, zorder=3)
plt.xlim(0, data_generator.image_shape[1])
plt.ylim(0, data_generator.image_shape[0])

plt.show()


augmenter = []

augmenter.append(FlipAxis(data_generator, axis=0))  # flip image up-down
augmenter.append(FlipAxis(data_generator, axis=1))  # flip image left-right 

sometimes = []
sometimes.append(iaa.Affine(scale={"x": (0.9, 1.1), "y": (0.9, 1.1)},
                            translate_percent={'x': (-0.5, 0.5), 'y': (-0.5, 0.5)},
                            shear=(-8, 8),
                            order=ia.ALL,
                            cval=ia.ALL)
                 )
sometimes.append(iaa.Affine(scale=(0.5, 1.5),
                            order=ia.ALL,
                            cval=ia.ALL)
                 )
augmenter.append(iaa.Sometimes(0.5, sometimes))
augmenter.append(iaa.Sometimes(0.5, iaa.Affine(rotate=(-180, 180),
                            order=ia.ALL,
                            cval=ia.ALL))
                 )
augmenter = iaa.Sequential(augmenter)







image, keypoints = data_generator[0]
image, keypoints = augmenter(images=image, keypoints=keypoints)
plt.figure(figsize=(5,5))
image = image[0] if image.shape[-1] is 3 else image[0, ..., 0]
cmap = None if image.shape[-1] is 3 else 'gray'
plt.imshow(image, cmap=cmap, interpolation='none')
for idx, jdx in enumerate(data_generator.graph):
    if jdx > -1:
        plt.plot(
            [keypoints[0, idx, 0], keypoints[0, jdx, 0]],
            [keypoints[0, idx, 1], keypoints[0, jdx, 1]],
            'r-'
        )

plt.scatter(keypoints[0, :, 0], keypoints[0, :, 1], c=np.arange(data_generator.keypoints_shape[0]), s=50, cmap=plt.cm.hsv, zorder=3)
plt.xlim(0, data_generator.image_shape[1])
plt.ylim(0, data_generator.image_shape[0])

plt.show()


train_generator = TrainingGenerator(generator=data_generator,
                                    downsample_factor=3,
                                    augmenter=augmenter,
                                    sigma=5,
                                    validation_split=0.1,
                                    use_graph=True,
                                    random_seed=1,
                                    graph_scale=1)
train_generator.get_config()


n_keypoints = data_generator.keypoints_shape[0]
batch = train_generator(batch_size=1, validation=False)[0]
inputs = batch[0]
outputs = batch[1]

fig, ((ax1, ax2), (ax3, ax4)) = plt.subplots(2, 2, figsize=(10,10))
ax1.set_title('image')
ax1.imshow(inputs[0,...,0], cmap='gray', vmin=0, vmax=255)

ax2.set_title('posture graph')
ax2.imshow(outputs[0,...,n_keypoints:-1].max(-1))

ax3.set_title('keypoints confidence')
ax3.imshow(outputs[0,...,:n_keypoints].max(-1))

ax4.set_title('posture graph and keypoints confidence')
ax4.imshow(outputs[0,...,-1], vmin=0)
plt.show()

train_generator.on_epoch_end()


from deepposekit.models import DeepLabCut, StackedDenseNet, LEAP

#model = StackedDenseNet(train_generator, n_stacks=1, growth_rate=32, pretrained=True)
#model = DeepLabCut(train_generator, backbone="resnet50")
#model = DeepLabCut(train_generator, backbone="mobilenetv2", alpha=1.0) # Increase alpha to improve accuracy
model = DeepLabCut(train_generator, backbone="densenet121")
#model = LEAP(train_generator)
model.get_config()


data_size = (500,) + data_generator.image_shape
x = np.random.randint(0, 255, data_size, dtype="uint8")
y = model.predict(x[:100], batch_size=50) # make sure the model is in GPU memory
t0 = time.time()
y = model.predict(x, batch_size=50, verbose=1)
t1 = time.time()
print(x.shape[0] / (t1 - t0))


logger = Logger(validation_batch_size=10
    # filepath saves the logger data to a .h5 file
    # filepath=HOME + "/deeplabcut_log_dlcdensenet.h5", validation_batch_size=10
)



reduce_lr = ReduceLROnPlateau(monitor="val_loss", factor=0.2, verbose=1, patience=20)


model_checkpoint = ModelCheckpoint(
    "../../deeplabcut_best_model_dlcdensenet_moth.h5",
    monitor="val_loss",
    # monitor="loss" # use if validation_split=0
    verbose=1,
    save_best_only=True,
    optimizer=True, # Set this to True if you wish to resume training from a saved model
)

early_stop = EarlyStopping(
    monitor="val_loss",
    # monitor="loss" # use if validation_split=0
    min_delta=0.001,
    patience=100,
    verbose=1
)



callbacks = [early_stop, reduce_lr, model_checkpoint, logger]


model.fit(
    batch_size=5,
    validation_batch_size=10,
    callbacks=callbacks,
    #epochs=1000, # Increase the number of epochs to train the model longer
    epochs=100,
    n_workers=8,
    steps_per_epoch=200,
)


model = load_model(
    "../../deeplabcut_best_model_dlcdensenet_moth.h5",
    augmenter=augmenter,
    generator=data_generator,
)


model.fit(
    batch_size=5,
    validation_batch_size=10,
    callbacks=callbacks,
    #epochs=1000, # Increase the number of epochs to train the model longer
    epochs=100,
    n_workers=8,
    steps_per_epoch=200,

Feature request: support training and annotating datasets with image data outside hdf5

This seems like a great package!

From what I can tell, it seems that the TrainingGenerator and DataGenerator classes only support loading data from an hdf5 file. However, I expect this would not work with datasets which do not fit into RAM.

Would it be possible to have some way to load the image files from paths stored in the hdf5 file, rather than from the hdf5 file directly?

Thank you!

Predict on images that are different size than training data

From the steps in the 'DeepPoseKit Step 3 - Train a model' I have trained a model for locust pose mapping. However, the data used in the annotation set is 160x160. When following the steps in the 'DeepPoseKit Step 4b - Predict on new data' notebook, I get the following issue:

reader = VideoReader(HOME + '/Data/crop.mp4', batch_size=50, gray=True) predictions = model.predict(reader, verbose=1) reader.close()

`---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
in
1 reader = VideoReader(HOME + '/Data/crop.mp4', batch_size=50, gray=True)
----> 2 predictions = model.predict(reader, verbose=1)
3 reader.close()

~\Anaconda3\lib\site-packages\tensorflow_core\python\keras\engine\training.py in predict(self, x, batch_size, verbose, steps, callbacks, max_queue_size, workers, use_multiprocessing)
907 max_queue_size=max_queue_size,
908 workers=workers,
--> 909 use_multiprocessing=use_multiprocessing)
910
911 def reset_metrics(self):

~\Anaconda3\lib\site-packages\tensorflow_core\python\keras\engine\training_generator.py in predict(self, model, x, batch_size, verbose, steps, callbacks, max_queue_size, workers, use_multiprocessing)
646 max_queue_size=max_queue_size,
647 workers=workers,
--> 648 use_multiprocessing=use_multiprocessing)
649
650

~\Anaconda3\lib\site-packages\tensorflow_core\python\keras\engine\training_generator.py in model_iteration(model, data, steps_per_epoch, epochs, verbose, callbacks, validation_data, validation_steps, validation_freq, class_weight, max_queue_size, workers, use_multiprocessing, shuffle, initial_epoch, mode, batch_size, steps_name, **kwargs)
263
264 is_deferred = not model._is_compiled
--> 265 batch_outs = batch_function(*batch_data)
266 if not isinstance(batch_outs, list):
267 batch_outs = [batch_outs]

~\Anaconda3\lib\site-packages\tensorflow_core\python\keras\engine\training_generator.py in predict_on_batch(x, y, sample_weights)
533 # 1, 2, or 3-tuples from generator
534 def predict_on_batch(x, y=None, sample_weights=None): # pylint: disable=unused-argument
--> 535 return model.predict_on_batch(x)
536
537 f = predict_on_batch

~\Anaconda3\lib\site-packages\tensorflow_core\python\keras\engine\training.py in predict_on_batch(self, x)
1142 # Validate and standardize user data.
1143 inputs, _, _ = self._standardize_user_data(
-> 1144 x, extract_tensors_from_dataset=True)
1145 # If self._distribution_strategy is True, then we are in a replica context
1146 # at this point.

~\Anaconda3\lib\site-packages\tensorflow_core\python\keras\engine\training.py in _standardize_user_data(self, x, y, sample_weight, class_weight, batch_size, check_steps, steps_name, steps, validation_split, shuffle, extract_tensors_from_dataset)
2470 feed_input_shapes,
2471 check_batch_axis=False, # Don't enforce the batch size.
-> 2472 exception_prefix='input')
2473
2474 # Get typespecs for the input data and sanitize it if necessary.

~\Anaconda3\lib\site-packages\tensorflow_core\python\keras\engine\training_utils.py in standardize_input_data(data, names, shapes, check_batch_axis, exception_prefix)
572 ': expected ' + names[i] + ' to have shape ' +
573 str(shape) + ' but got array with shape ' +
--> 574 str(data_shape))
575 return data
576

ValueError: Error when checking input: expected input_1 to have shape (160, 160, 1) but got array with shape (512, 512, 1)`

I assume that this is because the model was trained on 160x160 pixel images, while I would like to predict on 512x512 images. I have tried to resize the densenet model with Keras using the following methods:

from kerassurgeon.operations import delete_layer, insert_layer my_input_tensor = Input(input_shape=(512, 512, 1)) from tfkerassurgeon import delete_layer, insert_layer model = delete_layer(model.layers[0]) model = insert_layer(model.layers[0], my_input_tensor)
along with keras.add, model.layers, and model.inputs to no avail.

Is there an easy way to resize the model for inference/prediction? Or will I have to re-train the model on 512x512 images?

Thanks!

Not all parts of skeleton appear in labelling screen

The labelling tool works great for the most part but depending on the image resolution not all skeleton parts can be displayed. When changing the text scale the items remain in the same position, i.e. the distance between them remains the same.

Screenshot from 2019-10-08 17-29-17

How to exactly use Step1...ipynb notebook to annotate our own dataset?

So I am trying to redo step1 but for my own dummy dataset.

Here is what I get after "Apply k-means to reduce correlation"
https://pastebin.com/jcKcARTE
Screenshot from 2019-10-27 15-22-44
and above image is the result of running the cell under K-means.

In which case, would this plot actually work or better to say, why is it not working in my case?
I have the vide that I fed to code here: https://drive.google.com/file/d/1YIUvcHZIpaP1vRF4klTLefIjrxKr0jWk/view?usp=sharing

Screenshot from 2019-10-27 15-26-36

Here are the keypoints I have defined
Screenshot from 2019-10-27 15-27-12

This is what I get (mainly because kmean results was not right to start with?)
Screenshot from 2019-10-27 15-34-22

Issue with zooming, using separate image for keypoint annotation

When trying to use the annotator GUI to mark the keypoints and zooming the frame, I could not find a way to scroll the image to have the target object within the visible section of the window. Are there some shortcuts for scrolling (I could not find any in the documentation).
Alternatively, I can crop the original frame to the area where the target object is visible. In the deepposekit-data/datasets/locust, I notice such an image of a single object (skeleton_image.png). But I have not yet been able to figure out how to use that with the annotator.
It will be helpful to show an example of using this for annotation.

Error when fitting the model: ValueError: need at least one array to concatenate

Hi.

When fitting the model (StackedDenseNet) using the following code:

model.fit(batch_size=3,
validation_batch_size=10,
callbacks=callbacks,
epochs=1000,
n_workers=8,
steps_per_epoch=500)

I get the error message below. I have tried to attached the annotated data set, but it won't let me so I'll email it. Everything else seems to work.

Cheers

David

Epoch 1/1000
500/500 [==============================] - 1194s 2s/step - loss: 22.9040 - output_0_loss: 11.7045 - output_1_loss: 11.1995

ValueError Traceback (most recent call last)
in ()
4 epochs=1000,
5 n_workers=8,
----> 6 steps_per_epoch=500)

7 frames
/usr/local/lib/python3.6/dist-packages/deepposekit/models/engine.py in fit(self, batch_size, validation_batch_size, callbacks, epochs, use_multiprocessing, n_workers, steps_per_epoch, **kwargs)
143 validation_data=validation_generator,
144 validation_steps=len(validation_generator),
--> 145 **kwargs)
146
147 def evaluate(self, batch_size):

/usr/local/lib/python3.6/dist-packages/keras/legacy/interfaces.py in wrapper(*args, **kwargs)
89 warnings.warn('Update your ' + object_name + ' call to the ' +
90 'Keras 2 API: ' + signature, stacklevel=2)
---> 91 return func(*args, **kwargs)
92 wrapper._original_function = func
93 return wrapper

/usr/local/lib/python3.6/dist-packages/keras/engine/training.py in fit_generator(self, generator, steps_per_epoch, epochs, verbose, callbacks, validation_data, validation_steps, validation_freq, class_weight, max_queue_size, workers, use_multiprocessing, shuffle, initial_epoch)
1656 use_multiprocessing=use_multiprocessing,
1657 shuffle=shuffle,
-> 1658 initial_epoch=initial_epoch)
1659
1660 @interfaces.legacy_generator_methods_support

/usr/local/lib/python3.6/dist-packages/keras/engine/training_generator.py in fit_generator(model, generator, steps_per_epoch, epochs, verbose, callbacks, validation_data, validation_steps, validation_freq, class_weight, max_queue_size, workers, use_multiprocessing, shuffle, initial_epoch)
253 break
254
--> 255 callbacks.on_epoch_end(epoch, epoch_logs)
256 epoch += 1
257 if callbacks.model.stop_training:

/usr/local/lib/python3.6/dist-packages/keras/callbacks.py in on_epoch_end(self, epoch, logs)
150 logs = logs or {}
151 for callback in self.callbacks:
--> 152 callback.on_epoch_end(epoch, logs)
153
154 def on_train_batch_begin(self, batch, logs=None):

/usr/local/lib/python3.6/dist-packages/deepposekit/callbacks.py in on_epoch_end(self, epoch, logs)
89
90 def on_epoch_end(self, epoch, logs={}):
---> 91 evaluation_dict = self.evaluation_model.evaluate(self.batch_size)
92 y_pred = evaluation_dict['y_pred']
93 y_error = evaluation_dict['y_error']

/usr/local/lib/python3.6/dist-packages/deepposekit/models/engine.py in evaluate(self, batch_size)
162 keypoints.append([y_pred, y_error])
163
--> 164 metrics = np.hstack(metrics)
165 keypoints = np.hstack(keypoints)
166

/usr/local/lib/python3.6/dist-packages/numpy/core/shape_base.py in hstack(tup)
338 return _nx.concatenate(arrs, 0)
339 else:
--> 340 return _nx.concatenate(arrs, 1)
341
342

ValueError: need at least one array to concatenate

Make ModelCheckpoint backwards compatible with TF <1.14

I attempt to create a ModelCheckpoint callback with the following code:

model_checkpoint = ModelCheckpoint(
HOME + "/locust/best_model_SHG.h5",
monitor="loss",
#monitor="loss" # use if validation_split=0
verbose=1,
save_best_only=True,
)

Upon running it, the code fails with the following error:

Traceback (most recent call last):
File "R:/Locust/bc175/Warren Research Technician/deepposekit/Training.py", line 147, in
save_best_only=True,
File "R:\Locust\bc175\Warren Research Technician\deepposekit\deepposekit\callbacks.py", line 257, in init
**kwargs
TypeError: init() got an unexpected keyword argument 'save_freq'

When I remove that code, training works fine, so it's definitely what's causing the issue.

Thanks,
Ben

FlipAxis only flipping up-down?

Hi!
I'm trying to use the FlipAxis augmenter to flip images left-right but even setting the axis=1, I still get images flipped up-down. I simply did:

augmenter = FlipAxis(generator, axis=1)
flip_image, flip_keypoints = augmenter(images=image, keypoints=keypoints)

I noticed that if I change the parent class of FlipAxis from iaa.Flipud to iaa.Fliplr, then I only get images flipping left-right, regardless of axis specified. I didn't investigate any further than that and I'm not really familiar with the imgaug library. Any thoughts?

Thanks!

Feature request: Downsample inputs for faster analysis

Hi,

Many people collect videos at much higher spatial resolution than is necessary to perform accurate tracking (myself included). It would be great to have optional MaxPooling2D layer(s) at the input of DPK, which would downsample the input and cause the inference to be (way) faster. The output coordinates would need to be scaled up, etc. I think many would really benefit from the increased speed. What do you think?

Thanks,
Rick

Shift of skeleton position if height not equal width in image resolution

If I use the video 'spider.mp4' (480 * 640 Px) the skeleton is predicted nicely but with a shift to the actual spider (c.f. video 'spider_posture.mp4')

If I use the video 'spider_copped.mp4' (384 * 384 Px) instead where height=width the skeleton fits the actual spider (c.f. video 'spider_cropped_posture.mp4'; skeleton prediction messes up when only parts of spider are on the video - but this is not my point here.)

You find the data here:
https://github.com/urs-waldmann/spider-data-for-DPK
You find the modified notebooks for 'copped' videos here:
https://github.com/urs-waldmann/DeepPoseKit/tree/spider
You find the modified notebooks for 'original' videos here:
https://github.com/urs-waldmann/DeepPoseKit/tree/issue_img_res

Poor performance with StackedDenseNet

I'm finding that DeepPoseKit underperforms DeepLabCut (both used within the DPK package) when there are long range spatial contingencies in the data. See the image below, where the left and right paw in the top view are swapped (this appears to happen less frequently with DLC). The bottom view is useful here for resolving ambiguities in the top view; I think deeper networks (DLC) may have an easier time with these long range contingencies due to greater receptive field size at the outputs. Perhaps there are tweaks I can make to DPK that solve the problem though.

image

Here is my augmentation (notice no FlipAxis):

augmenter = []
sometimes = []

sometimes.append(iaa.Affine(scale={"x": (0.98, 1.02), "y": (0.98, 1.02)},
                            translate_percent={'x': (-0.02, 0.02), 'y': (-0.02, 0.02)},
                            shear=(-8, 8),
                            order=ia.ALL,
                            cval=ia.ALL,
                            mode=ia.ALL)
                 )
sometimes.append(iaa.Affine(scale=(0.9, 1.1),
                            mode=ia.ALL,
                            order=ia.ALL,
                            cval=ia.ALL)
                 )
augmenter.append(iaa.Sometimes(0.75, sometimes))
augmenter.append(iaa.Affine(rotate=(-5, 5),
                            mode=ia.ALL,
                            order=ia.ALL,
                            cval=ia.ALL)
                 )
augmenter = iaa.Sequential(augmenter)

And here is the model configuration:

{'name': 'StackedDenseNet',
 'n_stacks': 2,
 'n_transitions': 6,
 'growth_rate': 32,
 'bottleneck_factor': 1,
 'compression_factor': 0.5,
 'pretrained': True,
 'subpixel': True}

Thank you in advance for the help,
Rick

ValueError: LEAP is only compatible with a downsample_factor of 0

How should I fix this error?
ValueError: LEAP is only compatible with a downsample_factor of 0

#model = StackedDenseNet(train_generator, n_stacks=2, growth_rate=32, pretrained=True)

#model = DeepLabCut(train_generator, backbone="resnet50")
#model = DeepLabCut(train_generator, backbone="mobilenetv2", alpha=0.35) # Increase alpha to improve accuracy
#model = DeepLabCut(train_generator, backbone="densenet121")

model = LEAP(train_generator)
#model = StackedHourglass(train_generator)

model.get_config()

Error:

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-21-5c951e884ef9> in <module>()
      5 #model = DeepLabCut(train_generator, backbone="densenet121")
      6 
----> 7 model = LEAP(train_generator)
      8 #model = StackedHourglass(train_generator)
      9 

/scratch/sjn-p3/anaconda/anaconda3/lib/python3.6/site-packages/deepposekit/models/LEAP.py in __init__(self, train_generator, filters, upsampling, activation, batchnorm, use_bias, pooling, interpolation, subpixel, initializer, **kwargs)
    112         self.subpixel = subpixel
    113         self.initializer = initializer
--> 114         super(LEAP, self).__init__(train_generator, subpixel, **kwargs)
    115 
    116     def __init_model__(self):

/scratch/sjn-p3/anaconda/anaconda3/lib/python3.6/site-packages/deepposekit/models/engine.py in __init__(self, train_generator, subpixel, **kwargs)
     35             if self.train_model is NotImplemented:
     36                 self.__init_input__(config["image_shape"])
---> 37                 self.__init_model__()
     38                 self.__init_train_model__()
     39             if self.train_generator is not None:

/scratch/sjn-p3/anaconda/anaconda3/lib/python3.6/site-packages/deepposekit/models/LEAP.py in __init_model__(self)
    116     def __init_model__(self):
    117         if self.train_generator.downsample_factor is not 0:
--> 118             raise ValueError("LEAP is only compatible with a downsample_factor of 0")
    119         normalized = ImageNormalization()(self.inputs)
    120 

ValueError: LEAP is only compatible with a downsample_factor of 0





Strange behavior from draw_graph function in keypoints.py

Hi!
I've been trying to train a model on a human foot keypoint dataset using deepposekit. I was visualizing the skeleton and keypoint confidence graphs produced by the TrainingGenerator and noticed that certain parts of the skeleton aren't visible - in particular, the part from the big toe to the heel. The keypoints are in the order [left big toe, left little toe, left heel, right big toe, right little toe, right heel] so I've defined my graph to be [2, 2, -1, 5, 5, -1]. The result of this is that line 89 in utils/keypoints.py:

edge_confidence = edge_confidence[..., 1:]

cuts off the edge confidence from the big toe to the heel that was just computed. In my particular case I was able to fix the issue by replacing the line with edge_confidence = edge_confidence[..., :-1] but this obviously won't work for every graph. I'm wondering if this is a bug or if perhaps I've defined my graph in some unexpected way.

I also noticed that draw_graph doesn't deal with unlabelled keypoints and will draw lines from labelled to unlabelled keypoints (which are located at [-99999, -99999]). Is this correct?

Thanks!

Annotating improvement suggestions

Hi, while annotating some images I came up with some suggestions.

  1. Some annotations from the model were not so good, so that fixing took longer than when I would have just done it all from scratch. So a button where I could delete just this annotation would have been nice.
  2. Scrolling through the skeleton and then
  3. being able to select one part of the skeleton with the mouse would decrease the needed annotation time.

Thanks
Cheers, Philip

How to continue training a model?

Hi.

I am training a model using CoLab. I reached 40 Epochs until CoLab disconnected, and I would like to use the last best model (which was saved) to continue training. I have looked but can't find advice for how to do this, but it would be really useful, especially for those of us using CoLab rather than a machine with a GPU.

Is this possible? If so, what would I need to load?

Thanks

David

FlipAxis error

Hi,

I am running the code for the first time. When running the demo code in examples/deeplabcut_data_example.ipynb I get the following error:
FlipAxis(data_generator, axis=0)
TypeError: Can't instantiate abstract class FlipAxis with abstract methods _augment_images

This error also appears when call the same command in the demo code in step3_train_model.ipynb

Should I be using something else? tahnks

Not all joints are shown

In some frames, not all joints are shown. How can I make it work better? For the below examples, it should show 4 keypoints.

Screenshot from 2019-10-28 14-11-04
Screenshot from 2019-10-28 14-09-56
Screenshot from 2019-10-28 14-09-37

Rescaling images and keypoints after annotation is done

Hi,

I am trying to resize the images I used during annotation. I am using images of the size 360x640 but when I ran the training I stumbled on the "multiple of 2" problem. So now I decided to resize my already annotated images and also adapt the keypoints locations using the resize ratio. I am doing something like this :

lst = list(data_generator)
new_lst = []

for e in lst:
    le = list(e)
    le[0] = cv2.resize(np.squeeze(le[0]), (512, 256))
    le[0] = np.expand_dims(le[0], axis=0)
    le[0] = np.expand_dims(le[0], axis=3)
    le[1][:,0] = le[1][:,0] * 512 / 640
    le[1][:,1] = le[1][:,1] * 256 / 360
    
    te = tuple(le)
    new_lst.append(te)
    
new_tuple = tuple(new_lst)

But because the data_generator object is of typle DataGenerator I can't simple put :
data_generator = new_tuple although it looks very much like a tuple.

Do you have any suggestions on how I can rescale my images and keypoints after I already finished the annotation part?

Thanks!

Tensorflow installation issues

Hi, I have still Ubuntu 18.04, use jupyter notebook and all with your provided data.

logger = Logger(validation_batch_size=10
# filepath saves the logger data to a .h5 file
# filepath=HOME + "/deepposekit-data/datasets/fly/log_densenet.h5"
)

The line works, but removing the # to save the data gives me this error:
File "", line 3
filepath=HOME + "/deepposekit-data/datasets/fly/log_densenet.h5"
^
SyntaxError: invalid syntax

Then I got two more errors but I don't know if they are related to the first, but their the same error. With fit the model

model.fit(
batch_size=16,
validation_batch_size=10,
callbacks=callbacks,
#epochs=1000, # Increase the number of epochs to train the model longer
epochs=200,
n_workers=8,
steps_per_epoch=None,
)

and load the model
model.fit(
batch_size=5,
validation_batch_size=10,
callbacks=callbacks,
epochs=30,
n_workers=8,
steps_per_epoch=None,
)
where the error is

AbortedError Traceback (most recent call last)
in
6 epochs=200,
7 n_workers=8,
----> 8 steps_per_epoch=None,
9 )

~/anaconda3/envs/whipspider/lib/python3.7/site-packages/deepposekit/models/engine.py in fit(self, batch_size, validation_batch_size, callbacks, epochs, use_multiprocessing, n_workers, steps_per_epoch, **kwargs)
172 callbacks=activated_callbacks,
173 validation_data=validation_generator,
--> 174 **kwargs
175 )
176

~/anaconda3/envs/whipspider/lib/python3.7/site-packages/tensorflow/python/keras/engine/training.py in fit_generator(self, generator, steps_per_epoch, epochs, verbose, callbacks, validation_data, validation_steps, validation_freq, class_weight, max_queue_size, workers, use_multiprocessing, shuffle, initial_epoch)
1431 shuffle=shuffle,
1432 initial_epoch=initial_epoch,
-> 1433 steps_name='steps_per_epoch')
1434
1435 def evaluate_generator(self,

~/anaconda3/envs/whipspider/lib/python3.7/site-packages/tensorflow/python/keras/engine/training_generator.py in model_iteration(model, data, steps_per_epoch, epochs, verbose, callbacks, validation_data, validation_steps, validation_freq, class_weight, max_queue_size, workers, use_multiprocessing, shuffle, initial_epoch, mode, batch_size, steps_name, **kwargs)
262
263 is_deferred = not model._is_compiled
--> 264 batch_outs = batch_function(*batch_data)
265 if not isinstance(batch_outs, list):
266 batch_outs = [batch_outs]

~/anaconda3/envs/whipspider/lib/python3.7/site-packages/tensorflow/python/keras/engine/training.py in train_on_batch(self, x, y, sample_weight, class_weight, reset_metrics)
1173 self._update_sample_weight_modes(sample_weights=sample_weights)
1174 self._make_train_function()
-> 1175 outputs = self.train_function(ins) # pylint: disable=not-callable
1176
1177 if reset_metrics:

~/anaconda3/envs/whipspider/lib/python3.7/site-packages/tensorflow/python/keras/backend.py in call(self, inputs)
3290
3291 fetched = self._callable_fn(*array_vals,
-> 3292 run_metadata=self.run_metadata)
3293 self._call_fetch_callbacks(fetched[-len(self._fetches):])
3294 output_structure = nest.pack_sequence_as(

~/anaconda3/envs/whipspider/lib/python3.7/site-packages/tensorflow/python/client/session.py in call(self, *args, **kwargs)
1456 ret = tf_session.TF_SessionRunCallable(self._session._session,
1457 self._handle, args,
-> 1458 run_metadata_ptr)
1459 if run_metadata:
1460 proto_data = tf_session.TF_GetBuffer(run_metadata_ptr)

AbortedError: Operation received an exception:Status: 5, message: could not create a view primitive descriptor, in file tensorflow/core/kernels/mkl_slice_op.cc:433
[[{{node Adam_1/gradients/concatenate_50_1/concat_grad/Slice_2}}]]

Provide more details for using annotation GUI

I am rather lost trying to figure how to assiciate the keypoints to the names saved in skeleton.csv file? could you please create a video that tells this in more detail or show a more detailed manual?

Screenshot from 2019-10-22 21-06-14

Update GUI to allow for annotating keypoints that are not visible

So when annotating, sometimes keypoints are either not visible due to the animal's posture, or in some cases literally missing (locusts can easily lose a limb).

It would be good to have a clear way of flagging these in the training data. For now, I'm leaving them at the starting co-ordinate (which looks to be (1,1) or thereabouts), but I don't know how this affects the training process.

Would it be possible to have a way of actually setting them to NaN or something like that? Or does leaving them as the default point serve the same effect during training?

DLCDataGenerator doesn't find data

When I use the path to PNG images of my own dataset,
Screenshot from 2019-10-22 21-43-12

I get the following error:

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-6-a556e7005d05> in <module>()
      1 data_generator = DLCDataGenerator(
----> 2     project_path='/scratch3/3d_pose/animalpose/DeepPoseKit/datasets/moth/images/'
      3 )
      4 
      5 data_generator.dlcconfig

/scratch/sjn-p3/anaconda/anaconda3/lib/python3.6/site-packages/deepposekit/io/DLCDataGenerator.py in __init__(self, project_path, **kwargs)
     41         self.annotations_path = glob.glob(self.project_path + "/**/**/*.h5")
     42         annotations = [pd.read_hdf(datapath) for datapath in self.annotations_path]
---> 43         self.annotations = pd.concat(annotations)
     44 
     45         with open(project_path + "/config.yaml", "r") as config_file:

/home/grad3/jalal/.local/lib/python3.6/site-packages/pandas/core/reshape/concat.py in concat(objs, axis, join, join_axes, ignore_index, keys, levels, names, verify_integrity, copy)
    210                        keys=keys, levels=levels, names=names,
    211                        verify_integrity=verify_integrity,
--> 212                        copy=copy)
    213     return op.get_result()
    214 

/home/grad3/jalal/.local/lib/python3.6/site-packages/pandas/core/reshape/concat.py in __init__(self, objs, axis, join, join_axes, keys, levels, names, ignore_index, verify_integrity, copy)
    243 
    244         if len(objs) == 0:
--> 245             raise ValueError('No objects to concatenate')
    246 
    247         if keys is None:

ValueError: No objects to concatenate

Issue with Step 4: Defining model: "local variable 'idx' referenced before assignment"

Hi Jake,

I am running DeepPoseKit in Colab (with GPU) using Windows 10, and everything goes smoothly up until the "Define a model" step in the model training notebook.

When I run:

model = StackedDenseNet(data_generator=train_generator, n_stacks=2)
model.get_config()

I get the error message below.

I have not changed any of the code other than add code to mount google drive so I can add my annotated .h5 file.

from google.colab import drive
drive.mount('/content/drive',force_remount=True)

annotations = sorted(glob.glob('/content/drive/My Drive/*.h5'))

I have tried the most release release, and still have the same issue.

Let me know if there is anything I can try on my end!

Cheers

David


UnboundLocalError Traceback (most recent call last)
in ()
----> 1 model = StackedDenseNet(data_generator=train_generator, n_stacks=2)
2 # model = DeepLabCut(train_generator)
3 # model = LEAP(train_generator)
4 # model = StackedHourglass(train_generator)
5 model.get_config()

3 frames
/usr/local/lib/python3.6/dist-packages/deepposekit/models/StackedDenseNet.py in init(self, data_generator, n_stacks, n_transitions, n_layers, growth_rate, bottleneck_factor, compression_factor, batchnorm, use_bias, activation, pooling, interpolation, subpixel, initializer, separable, squeeze_excite, **kwargs)
141 self.squeeze_excite = squeeze_excite
142 self.n_transitions = n_transitions
--> 143 super(StackedDenseNet, self).init(data_generator, subpixel, **kwargs)
144
145 def init_model(self):

/usr/local/lib/python3.6/dist-packages/deepposekit/models/engine.py in init(self, data_generator, subpixel, **kwargs)
32 self.subpixel = subpixel
33 if self.train_model is NotImplemented and 'skip_init' not in kwargs:
---> 34 self.init_model()
35 self.init_train_model()
36 if self.data_generator is not None:

/usr/local/lib/python3.6/dist-packages/deepposekit/models/StackedDenseNet.py in init_model(self)
186 activation=self.activation, pooling=self.pooling, interpolation=self.interpolation, batchnorm=self.batchnorm,
187 use_bias=self.use_bias, separable=self.separable, squeeze_excite=self.squeeze_excite,
--> 188 stack_idx=0, multiplier=1)([normalized])
189 outputs = [output0]
190 multiplier = self.n_transitions - self.data_generator.downsample_factor

/usr/local/lib/python3.6/dist-packages/deepposekit/models/layers/densenet.py in call(self, inputs)
321 if self.multiplier > 1:
322 self.multiplier -= 1
--> 323 transition_diff = len(down_list) + -1 * (idx + 1)
324 for idx in range(transition_diff + 1):
325 pool_size = int(2**(transition_diff - idx))

UnboundLocalError: local variable 'idx' referenced before assignment

Model config isn't properly saved

I am trying to run one of the example datasets on a fresh anaconda-environment installation for DeepPoseKit.

import tensorflow as tf
from deepposekit.io import VideoReader
from deepposekit.io import DataGenerator, TrainingGenerator
from deepposekit.models import StackedDenseNet
from deepposekit.models import load_model

data_generator = DataGenerator('/Users/arminbahl/deepposekit-data/datasets/fly/annotation_data_release.h5')
train_generator = TrainingGenerator(data_generator)
model = StackedDenseNet(train_generator)
model.fit(batch_size=4, n_workers=1)
model.save('/Users/arminbahl/deepposekit-data/datasets/fly/example_annotation_model.h5')

print(tf.__version__)
print(data_generator.get_config())
print(train_generator.get_config())
print(model.get_config())

model = load_model('/Users/arminbahl/deepposekit-data/datasets/fly/example_annotation_model.h5')
reader = VideoReader('/Users/arminbahl/deepposekit-data/datasets/fly/video.avi')
predictions = model.predict(reader)

The training runs fine and the model is saved.

However, when loading the model, I get an error

model = load_model('/Users/arminbahl/deepposekit-data/datasets/fly/example_annotation_model.h5')
  File "/Users/arminbahl/opt/anaconda3/envs/deepposekit/lib/python3.7/site-packages/deepposekit/models/loading.py", line 124, in load_model
    model.__init_input__(model_config["image_shape"])
KeyError: 'image_shape'

Any idea what might be wrong here?

Thanks for helping!

I use a dedicated conda environment:

conda create --name deepposekit --channel conda-forge python=3.7
conda activate deepposekit
conda install --yes -c conda-forge shapely scikit-image scikit-learn
pip install tensorflow deepposekit

I couldn't import Deepposekit

Hey. I've installed all dependencies and cloned complete things. when i open the project in jupyter-lab i couldn't import deepposekit. Please help me out

PyYAML dependency

It appears like this code requires installation of the PyYAML package, but this is not properly listed in requirements.

After installing deep pose kit following instructions, importing the package results in the error:
ModuleNotFoundError: No module named 'yaml'

manually doing
pip install pyyaml

fixes this

Expected behavior for NaN annotations

Thanks for the great package! What is the expected behavior of DataGenerator for annotations set to NaN in the annotations h5 file? I use my own labeling GUI and set to NaN all features that are not present within a frame. However, the DataGenerator spits out very large negative numbers (-999999) rather than nan for the annotations set to nan in the annotation h5 file. Is this correct, and will the keras generator spit out all-zero target maps for these features?

Thank you,
Rick

No validation set detected with validation_split:0

Hi Jake,

I have now over 3h video footage from different animals doing different behaviors and I got the message No validation set detected with validation_split:0 so I changed it to 0.1.

Fit the model works with these settings:
model.fit(
batch_size=12, #less than n_train from data generator
validation_batch_size=1, # less than n_val from data generator
callbacks=callbacks,
#epochs=1000, # Increase the number of epochs to train the model longer
epochs=200,
n_workers=1,
steps_per_epoch=500,
)

and the output from the training generator looks like this:
{'n_train': 19,
'n_validation': 2,
'validation_split': 0.1,
'downsample_factor': 3,
'output_shape': (48, 48),
'n_output_channels': 88,
'shuffle': True,
'sigma': 5,
'output_sigma': 0.625,
'use_graph': True,
'graph_scale': 1,
'random_seed': 1,
'augmenter': True,
'datapath': '/home/einat/deepposekit-data/datasets/whipspider/annotation_data_release.h5',
'dataset': 'images',
'generator': 'DataGenerator',
'n_samples': 21,
'image_shape': (384, 384, 1),
'keypoints_shape': (43, 2)}

Output from fit the model
Epoch 1/200
13/500 [..............................] - ETA: 2:36:46 - loss: 178.4359 - output_0_loss: 71.6774 - output_1_loss: 56.4588 - output_2_loss: 50.2997

Epoch 1/200
405/500 [=======================>......] - ETA: 29:31 - loss: 52.7862 - output_0_loss: 19.2698 - output_1_loss: 17.0771 - output_2_loss: 16.4393

Does this looks good?

Cheers, Philip

ImportError: cannot import name 'Sequence'

When trying to import deepposekit, I get the following error:

Traceback (most recent call last):
File "", line 1, in
File "C:\Users\benco\Anaconda3\envs\deepposekit\lib\site-packages\deepposekit_init_.py", line 20, in
from deepposekit.io import TrainingGenerator, DataGenerator
File "C:\Users\benco\Anaconda3\envs\deepposekit\lib\site-packages\deepposekit\io_init_.py", line 25, in
from deepposekit.io.video import *
File "C:\Users\benco\Anaconda3\envs\deepposekit\lib\site-packages\deepposekit\io\video.py", line 16, in
from tensorflow.python.keras.utils import Sequence
ImportError: cannot import name 'Sequence'

As far as I can tell, TensorFlow 2.1.0 is installed fine. It's certainly able to find my GPU.

Thanks,
Ben

`load_model` takes 5 minutes to run

TR;DL
I'm seeing this problem on Windows, can someone confirm that this is "typical" time or Ubuntu/Linux is faster/slower?

deepposekit.models.load_model("best_model_densenet.h5")

takes 5 minutes to execute on Windows + Conda + tensorflow-gpu 2.0.0 + cudatoolkit 10.0.130 + cudnn 7.6.4. Most of the time spet in this call:

train_model = saving.load_model(filepath, custom_objects=custom_objects)

Which is a part of TensorFlow:

from tensorflow.python.keras.engine import saving

I'm only using DeepPoseKit-Data\datasets\fly\best_model_densenet.h5
model file without any modifications.
Full log of a single load_model("best_model_densenet.h5") call provided below. The "DEBUG" lines are mine, just time measurement statements.

2019-11-19 14:39:56.344360: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cudart64_100.dll
DEBUG: load_model() IMPORTED in 7.264695 sec
2019-11-19 14:40:03.324369: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library nvcuda.dll
2019-11-19 14:40:03.464370: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1618] Found device 0 with properties:
name: GeForce RTX 2080 Ti major: 7 minor: 5 memoryClockRate(GHz): 1.545
pciBusID: 0000:05:00.0
2019-11-19 14:40:03.474370: I tensorflow/stream_executor/platform/default/dlopen_checker_stub.cc:25] GPU libraries are statically linked, skip dlopen check.
2019-11-19 14:40:03.494370: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1746] Adding visible gpu devices: 0
2019-11-19 14:40:03.504370: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1618] Found device 0 with properties:
name: GeForce RTX 2080 Ti major: 7 minor: 5 memoryClockRate(GHz): 1.545
pciBusID: 0000:05:00.0
2019-11-19 14:40:03.514370: I tensorflow/stream_executor/platform/default/dlopen_checker_stub.cc:25] GPU libraries are statically linked, skip dlopen check.
2019-11-19 14:40:03.534370: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1746] Adding visible gpu devices: 0
2019-11-19 14:40:05.114372: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1159] Device interconnect StreamExecutor with strength 1 edge matrix:
2019-11-19 14:40:05.124372: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1165]      0
2019-11-19 14:40:05.134372: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1178] 0:   N
2019-11-19 14:40:05.144372: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1304] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 wit
h 9604 MB memory) -> physical GPU (device: 0, name: GeForce RTX 2080 Ti, pci bus id: 0000:05:00.0, compute capability: 7.5)
DEBUG: saving.load_model(): CALLED in 264.017428 sec
DEBUG: model prepared in 9.466326 sec
DEBUG: load_model() CALLED in 273.486011 sec

When 2 models are served at the same time, they seem to interfere and produce wrong results

I set up a simple flask + gunicorn server to deploy the 2 models that I trained and it seems to work fine.

But something very strange happens. When I serve only 1 model, outputs are correct and consistent.
But when I serve the 2 models at the same time, outputs become somehow corrupted and inconsistent.

I run 2 separate gunicorn processes, one for each model serving, with a different port.

I have tried using only CPU inference, and also tried GPU for one and CPU for the other.
I also tried tensorflow 2.0 and tensorflow 1.15 but it happened with both versions.

Any idea what could be the cause? Is there something in this model that could interfere with other instances somehow?

Thank you!

how should we move to the next keypoint in the annotation process?

currently, when I open the annotation GUI, it starts with head, but doesn't move to other keypoints.

Screenshot from 2019-10-27 17-16-59

How can I move to the next keypoint or how can we make the selection for one keypoint finalized?

Screenshot from 2019-10-27 17-19-57

p.s. Does wingR or WingL need to be a parent of head? I am CS major not animal sciences so I wonder how do you define parents in your field.

I am also seeing this:

QObject::moveToThread: Current thread (0x4b1ebf0) is not the object's thread (0x4bbf1f0).
Cannot move to target thread (0x4b1ebf0)

When I change the skeleton.csv to the following:

Screenshot from 2019-10-27 17-50-07

I get to see this, still not able to finalize the head keypoint to move to the next keypoint in the image.

Screenshot from 2019-10-27 17-49-07

Out of memory error when predicting with GPU

I have a model which trains and predicts fine using CPU-only TensorFlow (2.0.0). However, when I try to run it in a different conda environment with tensorflow-gpu (also 2.0.0), this is the output:

(tf-gpu) Z:\My Documents>python tensorflow/project/Training_v5.py 2019-11-22 08:37:53.351449: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cudart64_100.dll C:\Users\bc175\AppData\Local\conda\conda\envs\tf-gpu\lib\site-packages\h5py\_hl\dataset.py:313: H5pyDeprecationWarning: dataset.value has been deprecated. Use dataset[()] instead. "Use dataset[()] instead.", H5pyDeprecationWarning) {'n_train': 663, 'n_validation': 73, 'validation_split': 0.1, 'downsample_factor': 2, 'output_shape': (50, 50), 'n_output_channels': 68, 'shuffle': True, 'sigma': 5, 'output_sigma': 1.25, 'use_graph': True, 'graph_scale': 1, 'random_seed': 1, 'augmenter': True, 'datapath': 'R:/Locust/bc175/Warren Research Technician/deepposekit/flat/annotation_flat_v3.h5', 'dataset': 'images', 'generator': 'DataGenerator', 'n_samples': 736, 'image_shape': (200, 200, 1), 'keypoints_shape': (33, 2)} 2019-11-22 08:38:06.557412: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library nvcuda.dll 2019-11-22 08:38:06.639050: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1618] Found device 0 with properties: name: GeForce GTX 1060 3GB major: 6 minor: 1 memoryClockRate(GHz): 1.7085 pciBusID: 0000:01:00.0 2019-11-22 08:38:06.648011: I tensorflow/stream_executor/platform/default/dlopen_checker_stub.cc:25] GPU libraries are statically linked, skip dlopen check. 2019-11-22 08:38:06.657471: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1746] Adding visible gpu devices: 0 2019-11-22 08:38:06.662034: I tensorflow/core/platform/cpu_feature_guard.cc:142] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX AVX2 2019-11-22 08:38:06.672387: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1618] Found device 0 with properties: name: GeForce GTX 1060 3GB major: 6 minor: 1 memoryClockRate(GHz): 1.7085 pciBusID: 0000:01:00.0 2019-11-22 08:38:06.679775: I tensorflow/stream_executor/platform/default/dlopen_checker_stub.cc:25] GPU libraries are statically linked, skip dlopen check. 2019-11-22 08:38:06.687691: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1746] Adding visible gpu devices: 0 2019-11-22 08:38:07.269510: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1159] Device interconnect StreamExecutor with strength 1 edge matrix: 2019-11-22 08:38:07.274566: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1165] 0 2019-11-22 08:38:07.277998: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1178] 0: N 2019-11-22 08:38:07.284995: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1304] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 2107 MB memory) -> physical GPU (device: 0, name: GeForce GTX 1060 3GB, pci bus id: 0000:01:00.0, compute capability: 6.1) {'name': 'StackedHourglass', 'n_stacks': 2, 'n_transitions': 3, 'bottleneck_factor': 2, 'filters': 256, 'subpixel': True, 'n_train': 663, 'n_validation': 73, 'validation_split': 0.1, 'downsample_factor': 2, 'output_shape': (50, 50), 'n_output_channels': 68, 'shuffle': True, 'sigma': 5, 'output_sigma': 1.25, 'use_graph': True, 'graph_scale': 1, 'random_seed': 1, 'augmenter': True, 'datapath': 'R:/Locust/bc175/Warren Research Technician/deepposekit/flat/annotation_flat_v3.h5', 'dataset': 'images', 'generator': 'DataGenerator', 'n_samples': 736, 'image_shape': (200, 200, 1), 'keypoints_shape': (33, 2)} Epoch 1/2000 2019-11-22 08:44:03.979571: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cudnn64_7.dll 2019-11-22 08:44:04.856741: W tensorflow/stream_executor/cuda/redzone_allocator.cc:312] Internal: Invoking ptxas not supported on Windows Relying on driver to perform ptx compilation. This message will be only logged once. 2019-11-22 08:44:05.036431: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cublas64_100.dll

Above is all the normal output. Below appears to be where the error comes from:

2019-11-22 08:44:15.288237: W tensorflow/core/common_runtime/bfc_allocator.cc:419] Allocator (GPU_0_bfc) ran out of memory trying to allocate 234.38MiB (rounded to 245760000). Current allocation summary follows. 2019-11-22 08:44:15.297222: I tensorflow/core/common_runtime/bfc_allocator.cc:869] Bin (256): Total Chunks: 16, Chunks in use: 15. 4.0KiB allocated for chunks. 3.8KiB in use in bin. 64B client-requested in use in bin. 2019-11-22 08:44:15.306538: I tensorflow/core/common_runtime/bfc_allocator.cc:869] Bin (512): Total Chunks: 296, Chunks in use: 296. 148.0KiB allocated for chunks. 148.0KiB in use in bin. 144.7KiB client-requested in use in bin. 2019-11-22 08:44:15.315796: I tensorflow/core/common_runtime/bfc_allocator.cc:869] Bin (1024): Total Chunks: 547, Chunks in use: 547. 549.0KiB allocated for chunks. 549.0KiB in use in bin. 547.0KiB client-requested in use in bin. 2019-11-22 08:44:15.325491: I tensorflow/core/common_runtime/bfc_allocator.cc:869] Bin (2048): Total Chunks: 0, Chunks in use: 0. 0B allocated for chunks. 0B in use in bin. 0B client-requested in use in bin. 2019-11-22 08:44:15.334153: I tensorflow/core/common_runtime/bfc_allocator.cc:869] Bin (4096): Total Chunks: 0, Chunks in use: 0. 0B allocated for chunks. 0B in use in bin. 0B client-requested in use in bin. 2019-11-22 08:44:15.342867: I tensorflow/core/common_runtime/bfc_allocator.cc:869] Bin (8192): Total Chunks: 0, Chunks in use: 0. 0B allocated for chunks. 0B in use in bin. 0B client-requested in use in bin. 2019-11-22 08:44:15.351168: I tensorflow/core/common_runtime/bfc_allocator.cc:869] Bin (16384): Total Chunks: 0, Chunks in use: 0. 0B allocated for chunks. 0B in use in bin. 0B client-requested in use in bin. 2019-11-22 08:44:15.361080: I tensorflow/core/common_runtime/bfc_allocator.cc:869] Bin (32768): Total Chunks: 2, Chunks in use: 2. 98.0KiB allocated for chunks. 98.0KiB in use in bin. 98.0KiB client-requested in use in bin. 2019-11-22 08:44:15.370432: I tensorflow/core/common_runtime/bfc_allocator.cc:869] Bin (65536): Total Chunks: 10, Chunks in use: 10. 806.5KiB allocated for chunks. 806.5KiB in use in bin. 661.0KiB client-requested in use in bin. 2019-11-22 08:44:15.380524: I tensorflow/core/common_runtime/bfc_allocator.cc:869] Bin (131072): Total Chunks: 102, Chunks in use: 102. 13.06MiB allocated for chunks. 13.06MiB in use in bin. 12.75MiB client-requested in use in bin. 2019-11-22 08:44:15.390888: I tensorflow/core/common_runtime/bfc_allocator.cc:869] Bin (262144): Total Chunks: 9, Chunks in use: 9. 2.31MiB allocated for chunks. 2.31MiB in use in bin. 2.25MiB client-requested in use in bin. 2019-11-22 08:44:15.400214: I tensorflow/core/common_runtime/bfc_allocator.cc:869] Bin (524288): Total Chunks: 53, Chunks in use: 52. 30.61MiB allocated for chunks. 30.07MiB in use in bin. 29.25MiB client-requested in use in bin. 2019-11-22 08:44:15.410526: I tensorflow/core/common_runtime/bfc_allocator.cc:869] Bin (1048576): Total Chunks: 1, Chunks in use: 0. 1.27MiB allocated for chunks. 0B in use in bin. 0B client-requested in use in bin. 2019-11-22 08:44:15.420570: I tensorflow/core/common_runtime/bfc_allocator.cc:869] Bin (2097152): Total Chunks: 0, Chunks in use: 0. 0B allocated for chunks. 0B in use in bin. 0B client-requested in use in bin. 2019-11-22 08:44:15.429672: I tensorflow/core/common_runtime/bfc_allocator.cc:869] Bin (4194304): Total Chunks: 3, Chunks in use: 2. 21.97MiB allocated for chunks. 14.65MiB in use in bin. 14.65MiB client-requested in use in bin. 2019-11-22 08:44:15.441092: I tensorflow/core/common_runtime/bfc_allocator.cc:869] Bin (8388608): Total Chunks: 0, Chunks in use: 0. 0B allocated for chunks. 0B in use in bin. 0B client-requested in use in bin. 2019-11-22 08:44:15.451590: I tensorflow/core/common_runtime/bfc_allocator.cc:869] Bin (16777216): Total Chunks: 0, Chunks in use: 0. 0B allocated for chunks. 0B in use in bin. 0B client-requested in use in bin. 2019-11-22 08:44:15.460364: I tensorflow/core/common_runtime/bfc_allocator.cc:869] Bin (33554432): Total Chunks: 0, Chunks in use: 0. 0B allocated for chunks. 0B in use in bin. 0B client-requested in use in bin. 2019-11-22 08:44:15.470150: I tensorflow/core/common_runtime/bfc_allocator.cc:869] Bin (67108864): Total Chunks: 0, Chunks in use: 0. 0B allocated for chunks. 0B in use in bin. 0B client-requested in use in bin. 2019-11-22 08:44:15.479661: I tensorflow/core/common_runtime/bfc_allocator.cc:869] Bin (134217728): Total Chunks: 5, Chunks in use: 4. 1.07GiB allocated for chunks. 937.50MiB in use in bin. 937.50MiB client-requested in use in bin. 2019-11-22 08:44:15.489973: I tensorflow/core/common_runtime/bfc_allocator.cc:869] Bin (268435456): Total Chunks: 2, Chunks in use: 2. 937.50MiB allocated for chunks. 937.50MiB in use in bin. 937.50MiB client-requested in use in bin. 2019-11-22 08:44:15.500336: I tensorflow/core/common_runtime/bfc_allocator.cc:885] Bin for 234.38MiB was 128.00MiB, Chunk State: 2019-11-22 08:44:15.505805: I tensorflow/core/common_runtime/bfc_allocator.cc:891] Size: 161.44MiB | Requested Size: 0B | in_use: 0 | bin_num: 19, prev: Size: 234.38MiB | Requested Size: 234.38MiB | in_use: 1 | bin_num: -1 2019-11-22 08:44:15.516312: I tensorflow/core/common_runtime/bfc_allocator.cc:898] Next region of size 2209598464 2019-11-22 08:44:15.521449: I tensorflow/core/common_runtime/bfc_allocator.cc:905] InUse at 0000000B03600000 next 1 of size 1280 2019-11-22 08:44:15.528409: I tensorflow/core/common_runtime/bfc_allocator.cc:905] InUse at 0000000B03600500 next 5 of size 1280 2019-11-22 08:44:15.534291: I tensorflow/core/common_runtime/bfc_allocator.cc:905] InUse at 0000000B03600A00 next 4 of size 1024 2019-11-22 08:44:15.539102: I tensorflow/core/common_runtime/bfc_allocator.cc:905] InUse at 0000000B03600E00 next 7 of size 1024 2019-11-22 08:44:15.544718: I tensorflow/core/common_runtime/bfc_allocator.cc:905] InUse at 0000000B03601200 next 2 of size 512 2019-11-22 08:44:15.550555: I tensorflow/core/common_runtime/bfc_allocator.cc:905] InUse at 0000000B03601400 next 8 of size 512 2019-11-22 08:44:15.556552: I tensorflow/core/common_runtime/bfc_allocator.cc:905] InUse at 0000000B03601600 next 9 of size 512 2019-11-22 08:44:15.562202: I tensorflow/core/common_runtime/bfc_allocator.cc:905] InUse at 0000000B03601800 next 11 of size 512


This goes on for a fair bit, so I've cut most of them out


`2019-11-22 08:44:21.235488: I tensorflow/core/common_runtime/bfc_allocator.cc:905] InUse at 0000000B07CCB100 next 1014 of size 491520000
2019-11-22 08:44:21.242137: I tensorflow/core/common_runtime/bfc_allocator.cc:905] InUse at 0000000B2518B100 next 1015 of size 491520000
2019-11-22 08:44:21.248308: I tensorflow/core/common_runtime/bfc_allocator.cc:905] InUse at 0000000B4264B100 next 1029 of size 245760000
2019-11-22 08:44:21.254596: I tensorflow/core/common_runtime/bfc_allocator.cc:905] InUse at 0000000B510AB100 next 1030 of size 245760000
2019-11-22 08:44:21.262012: I tensorflow/core/common_runtime/bfc_allocator.cc:905] InUse at 0000000B5FB0B100 next 1043 of size 245760000
2019-11-22 08:44:21.268683: I tensorflow/core/common_runtime/bfc_allocator.cc:905] InUse at 0000000B6E56B100 next 1044 of size 245760000
2019-11-22 08:44:21.274896: I tensorflow/core/common_runtime/bfc_allocator.cc:905] Free at 0000000B7CFCB100 next 18446744073709551615 of size 169286400
2019-11-22 08:44:21.282446: I tensorflow/core/common_runtime/bfc_allocator.cc:914] Summary of in-use Chunks by size:
2019-11-22 08:44:21.288317: I tensorflow/core/common_runtime/bfc_allocator.cc:917] 15 Chunks of size 256 totalling 3.8KiB
2019-11-22 08:44:21.293332: I tensorflow/core/common_runtime/bfc_allocator.cc:917] 296 Chunks of size 512 totalling 148.0KiB
2019-11-22 08:44:21.299070: I tensorflow/core/common_runtime/bfc_allocator.cc:917] 542 Chunks of size 1024 totalling 542.0KiB
2019-11-22 08:44:21.303852: I tensorflow/core/common_runtime/bfc_allocator.cc:917] 2 Chunks of size 1280 totalling 2.5KiB
2019-11-22 08:44:21.309380: I tensorflow/core/common_runtime/bfc_allocator.cc:917] 3 Chunks of size 1536 totalling 4.5KiB
2019-11-22 08:44:21.315147: I tensorflow/core/common_runtime/bfc_allocator.cc:917] 2 Chunks of size 50176 totalling 98.0KiB
2019-11-22 08:44:21.320306: I tensorflow/core/common_runtime/bfc_allocator.cc:917] 7 Chunks of size 69632 totalling 476.0KiB
2019-11-22 08:44:21.326092: I tensorflow/core/common_runtime/bfc_allocator.cc:917] 1 Chunks of size 84480 totalling 82.5KiB
2019-11-22 08:44:21.332237: I tensorflow/core/common_runtime/bfc_allocator.cc:917] 2 Chunks of size 126976 totalling 248.0KiB
2019-11-22 08:44:21.336916: I tensorflow/core/common_runtime/bfc_allocator.cc:917] 98 Chunks of size 131072 totalling 12.25MiB
2019-11-22 08:44:21.342753: I tensorflow/core/common_runtime/bfc_allocator.cc:917] 3 Chunks of size 196608 totalling 576.0KiB
2019-11-22 08:44:21.347654: I tensorflow/core/common_runtime/bfc_allocator.cc:917] 1 Chunks of size 258048 totalling 252.0KiB
2019-11-22 08:44:21.353470: I tensorflow/core/common_runtime/bfc_allocator.cc:917] 8 Chunks of size 262144 totalling 2.00MiB
2019-11-22 08:44:21.358586: I tensorflow/core/common_runtime/bfc_allocator.cc:917] 1 Chunks of size 327680 totalling 320.0KiB
2019-11-22 08:44:21.363791: I tensorflow/core/common_runtime/bfc_allocator.cc:917] 42 Chunks of size 589824 totalling 23.63MiB
2019-11-22 08:44:21.369619: I tensorflow/core/common_runtime/bfc_allocator.cc:917] 1 Chunks of size 591360 totalling 577.5KiB
2019-11-22 08:44:21.374665: I tensorflow/core/common_runtime/bfc_allocator.cc:917] 1 Chunks of size 591872 totalling 578.0KiB
2019-11-22 08:44:21.380761: I tensorflow/core/common_runtime/bfc_allocator.cc:917] 1 Chunks of size 594944 totalling 581.0KiB
2019-11-22 08:44:21.386268: I tensorflow/core/common_runtime/bfc_allocator.cc:917] 1 Chunks of size 598016 totalling 584.0KiB
2019-11-22 08:44:21.392045: I tensorflow/core/common_runtime/bfc_allocator.cc:917] 1 Chunks of size 600064 totalling 586.0KiB
2019-11-22 08:44:21.397775: I tensorflow/core/common_runtime/bfc_allocator.cc:917] 1 Chunks of size 610304 totalling 596.0KiB
2019-11-22 08:44:21.402543: I tensorflow/core/common_runtime/bfc_allocator.cc:917] 1 Chunks of size 611840 totalling 597.5KiB
2019-11-22 08:44:21.409106: I tensorflow/core/common_runtime/bfc_allocator.cc:917] 1 Chunks of size 720896 totalling 704.0KiB
2019-11-22 08:44:21.415070: I tensorflow/core/common_runtime/bfc_allocator.cc:917] 2 Chunks of size 917504 totalling 1.75MiB
2019-11-22 08:44:21.420489: I tensorflow/core/common_runtime/bfc_allocator.cc:917] 2 Chunks of size 7680000 totalling 14.65MiB
2019-11-22 08:44:21.426903: I tensorflow/core/common_runtime/bfc_allocator.cc:917] 4 Chunks of size 245760000 totalling 937.50MiB
2019-11-22 08:44:21.432880: I tensorflow/core/common_runtime/bfc_allocator.cc:917] 2 Chunks of size 491520000 totalling 937.50MiB
2019-11-22 08:44:21.438181: I tensorflow/core/common_runtime/bfc_allocator.cc:921] Sum Total of in-use chunks: 1.89GiB
2019-11-22 08:44:21.443098: I tensorflow/core/common_runtime/bfc_allocator.cc:923] total_region_allocated_bytes_: 2209598464 memory_limit_: 2209598668 available bytes: 204 curr_region_allocation_bytes_: 4419197440
2019-11-22 08:44:21.452939: I tensorflow/core/common_runtime/bfc_allocator.cc:929] Stats:
Limit: 2209598668
InUse: 2030728448
MaxInUse: 2030728448
NumAllocs: 4833
MaxAllocSize: 508297216

2019-11-22 08:44:21.465913: W tensorflow/core/common_runtime/bfc_allocator.cc:424] *********************************************************************************************_______
2019-11-22 08:44:21.474321: W tensorflow/core/framework/op_kernel.cc:1622] OP_REQUIRES failed at conv_ops.cc:947 : Resource exhausted: OOM when allocating tensor with shape[48,128,100,100] and type float on /job:localhost/replica:0/task:0/device:GPU:0 by allocator GPU_0_bfc
Traceback (most recent call last):
File "tensorflow/project/Training_v5.py", line 152, in
shuffle=True
File "C:\Users\bc175\AppData\Local\conda\conda\envs\tf-gpu\lib\site-packages\deepposekit\models\engine.py", line 174, in fit
**kwargs
File "C:\Users\bc175\AppData\Local\conda\conda\envs\tf-gpu\lib\site-packages\tensorflow_core\python\keras\engine\training.py", line 1297, in fit_generator
steps_name='steps_per_epoch')
File "C:\Users\bc175\AppData\Local\conda\conda\envs\tf-gpu\lib\site-packages\tensorflow_core\python\keras\engine\training_generator.py", line 265, in model_iteration
batch_outs = batch_function(*batch_data)
File "C:\Users\bc175\AppData\Local\conda\conda\envs\tf-gpu\lib\site-packages\tensorflow_core\python\keras\engine\training.py", line 973, in train_on_batch
class_weight=class_weight, reset_metrics=reset_metrics)
File "C:\Users\bc175\AppData\Local\conda\conda\envs\tf-gpu\lib\site-packages\tensorflow_core\python\keras\engine\training_v2_utils.py", line 264, in train_on_batch
output_loss_metrics=model._output_loss_metrics)
File "C:\Users\bc175\AppData\Local\conda\conda\envs\tf-gpu\lib\site-packages\tensorflow_core\python\keras\engine\training_eager.py", line 311, in train_on_batch
output_loss_metrics=output_loss_metrics))
File "C:\Users\bc175\AppData\Local\conda\conda\envs\tf-gpu\lib\site-packages\tensorflow_core\python\keras\engine\training_eager.py", line 252, in _process_single_batch
training=training))
File "C:\Users\bc175\AppData\Local\conda\conda\envs\tf-gpu\lib\site-packages\tensorflow_core\python\keras\engine\training_eager.py", line 127, in _model_loss
outs = model(inputs, **kwargs)
File "C:\Users\bc175\AppData\Local\conda\conda\envs\tf-gpu\lib\site-packages\tensorflow_core\python\keras\engine\base_layer.py", line 891, in call
outputs = self.call(cast_inputs, *args, **kwargs)
File "C:\Users\bc175\AppData\Local\conda\conda\envs\tf-gpu\lib\site-packages\tensorflow_core\python\keras\engine\network.py", line 708, in call
convert_kwargs_to_constants=base_layer_utils.call_context().saving)
File "C:\Users\bc175\AppData\Local\conda\conda\envs\tf-gpu\lib\site-packages\tensorflow_core\python\keras\engine\network.py", line 860, in _run_internal_graph
output_tensors = layer(computed_tensors, **kwargs)
File "C:\Users\bc175\AppData\Local\conda\conda\envs\tf-gpu\lib\site-packages\tensorflow_core\python\keras\engine\base_layer.py", line 891, in call
outputs = self.call(cast_inputs, *args, **kwargs)
File "C:\Users\bc175\AppData\Local\conda\conda\envs\tf-gpu\lib\site-packages\tensorflow_core\python\keras\layers\convolutional.py", line 197, in call
outputs = self._convolution_op(inputs, self.kernel)
File "C:\Users\bc175\AppData\Local\conda\conda\envs\tf-gpu\lib\site-packages\tensorflow_core\python\ops\nn_ops.py", line 1134, in call
return self.conv_op(inp, filter)
File "C:\Users\bc175\AppData\Local\conda\conda\envs\tf-gpu\lib\site-packages\tensorflow_core\python\ops\nn_ops.py", line 639, in call
return self.call(inp, filter)
File "C:\Users\bc175\AppData\Local\conda\conda\envs\tf-gpu\lib\site-packages\tensorflow_core\python\ops\nn_ops.py", line 238, in call
name=self.name)
File "C:\Users\bc175\AppData\Local\conda\conda\envs\tf-gpu\lib\site-packages\tensorflow_core\python\ops\nn_ops.py", line 2010, in conv2d
name=name)
File "C:\Users\bc175\AppData\Local\conda\conda\envs\tf-gpu\lib\site-packages\tensorflow_core\python\ops\gen_nn_ops.py", line 1031, in conv2d
data_format=data_format, dilations=dilations, name=name, ctx=_ctx)
File "C:\Users\bc175\AppData\Local\conda\conda\envs\tf-gpu\lib\site-packages\tensorflow_core\python\ops\gen_nn_ops.py", line 1130, in conv2d_eager_fallback
ctx=_ctx, name=name)
File "C:\Users\bc175\AppData\Local\conda\conda\envs\tf-gpu\lib\site-packages\tensorflow_core\python\eager\execute.py", line 67, in quick_execute
six.raise_from(core._status_to_exception(e.code, message), None)
File "", line 3, in raise_from
tensorflow.python.framework.errors_impl.ResourceExhaustedError: OOM when allocating tensor with shape[48,128,100,100] and type float on /job:localhost/replica:0/task:0/device:GPU:0 by allocator GPU_0_bfc [Op:Conv2D]`

From looking through this, it seems as though the issue might be that my GPU, whilst supported fine by tensorflow, only has 3GB of dedicated memory? If so, is there any workaround for that limitation?

Support for annotating images with variable dimensions

I've localized a video with a custom yolov4 model, which produces a boundary box around the subject that I use to crop the frame with. This method of localization seems incompatible with the current example notebooks in DeepPoseKit; creating an annotation set seems to expect fixed-size images by using a stacked numpy array while the boundary box changes shape constantly based on the subject's pose and distance.

Must provide as many biases as the channel dimension of the input tensor

I have trained the model on my own data with same size 192 x 192. The whole training was completed without any errors. I saved my best fit model. But when I try to load the model for predicting, I get the following error.

InvalidArgumentError: Must provide as many biases as the channel dimension of the input tensor: [3] vs. 9 in [1,9,192,192]
[[node StackedDenseNet/StackedDenseNet/image_net_preprocess_1/BiasAdd (defined at /usr/local/lib/python3.6/dist-packages/deepposekit/models/layers/deeplabcut.py:86) ]] [Op:__inference_predict_function_341865]

Errors may have originated from an input operation.
Input Source operations connected to node StackedDenseNet/StackedDenseNet/image_net_preprocess_1/BiasAdd:
StackedDenseNet/StackedDenseNet/image_net_preprocess_1/truediv (defined at /usr/local/lib/python3.6/dist-packages/deepposekit/models/layers/deeplabcut.py:62)
StackedDenseNet/StackedDenseNet/image_net_preprocess_1/Const (defined at /usr/local/lib/python3.6/dist-packages/deepposekit/models/layers/deeplabcut.py:78)

Function call stack:
predict_function

deepposekit.import_deeplabcut_labeled_data()

Thanks so much to you and your team for building this good piece of software!

It would be good to be able to import deeplabcut labeled data, so more users can try this software without having to label data again. In deeplabcut there are no skeletons, so maybe the user would provide the h5 deeplabcut labeled data, the frames and the csv of the skeleton. I would like to help to develop code around this but would like to hear your feedback first. I have a bunch of data that would love to try asap with deepposekit.

Pura vida,

Add pretrained models (humans)

For co2 efficiency, can you please release some pertained models? (of what you have of course...)
I'm assuming you already have a human pose estimator, so it would just be a waste to every person to train a new one.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.