1- import cv2
21import datetime
32import os
3+ import pickle
4+ import warnings
45from pathlib import Path
6+ from platform import python_version
7+
8+ import cv2
9+ import yaml
510import numpy as np
611import pandas as pd
7- import pickle
8- import warnings
912from hdmf .build .warnings import DtypeConversionWarning
13+ from packaging .version import Version # Installed with setuptools
1014from pynwb import NWBFile , NWBHDF5IO
1115from ndx_pose import PoseEstimationSeries , PoseEstimation
12- import yaml
1316from ruamel .yaml import YAML
1417
1518# If available determine version
1619try :
17- from deeplabcut import __version__
18- deeplabcut_version = __version__
20+ if Version (python_version ()) >= Version ("3.8" ):
21+ from importlib .metadata import version as get_package_version # Only available in Python>=3.8
22+
23+ deeplabcut_version = get_package_version ("deeplabcut" )
24+ else :
25+ from pkg_resources import get_distribution # Installed with setuptools
26+
27+ deeplabcut_version = get_distribution ("deeplabcut" ).version
1928except ModuleNotFoundError :
2029 deeplabcut_version = None
2130
31+
2232def read_config (configname ):
2333 """
2434 Reads structured config file defining a project.
@@ -176,8 +186,16 @@ def _get_pes_args(config_file, h5file, individual_name, infer_timestamps=True):
176186 return scorer , df , video , paf_graph , timestamps , cfg
177187
178188
179- def _write_pes_to_nwbfile (nwbfile , animal , df_animal , scorer , video , paf_graph , timestamps ,
180- exclude_nans ):
189+ def _write_pes_to_nwbfile (
190+ nwbfile ,
191+ animal ,
192+ df_animal ,
193+ scorer ,
194+ video , # Expects this to be a tuple; first index is string path, second is the image shape as "0, width, 0, height"
195+ paf_graph ,
196+ timestamps ,
197+ exclude_nans ,
198+ ):
181199 pose_estimation_series = []
182200 for kpt , xyp in df_animal .groupby (level = "bodyparts" , axis = 1 , sort = False ):
183201 data = xyp .to_numpy ()
@@ -200,7 +218,7 @@ def _write_pes_to_nwbfile(nwbfile, animal, df_animal, scorer, video, paf_graph,
200218 confidence_definition = "Softmax output of the deep neural network." ,
201219 )
202220 pose_estimation_series .append (pes )
203-
221+
204222 pe = PoseEstimation (
205223 pose_estimation_series = pose_estimation_series ,
206224 description = "2D keypoint coordinates estimated using DeepLabCut." ,
0 commit comments