Visitar URL original
Harden path-handling after pathlib migration by deruyter92 · Pull Request #3421 · DeepLabCut/DeepLabCut · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Ensure TF branch normalizes to str ( excluded from pathlib migration)
  • Loading branch information
deruyter92 committed Jul 21, 2026
commit 5daaade27b7cde3e5e8bc9984d8a41c603be49ea
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from .utils import (
Batch,
DataItem,
_normalize_image_path,
crop_image,
data_to_input,
mirror_joints_map,
Expand Down Expand Up @@ -60,8 +61,7 @@ def load_dataset(self):

item = DataItem()
item.image_id = i
im_path = sample[0][0]
item.im_path = str(Path(*im_path) if isinstance(im_path, list) else Path(im_path))
item.im_path: str = _normalize_image_path(sample[0][0])
item.im_size = sample[1][0]
if len(sample) >= 3:
joints = sample[2][0][0]
Expand Down
12 changes: 3 additions & 9 deletions deeplabcut/pose_estimation_tensorflow/datasets/pose_imgaug.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

from .factory import PoseDatasetFactory
from .pose_base import BasePoseDataset
from .utils import Batch, DataItem
from .utils import Batch, DataItem, _normalize_image_path


@PoseDatasetFactory.register("default")
Expand Down Expand Up @@ -92,10 +92,7 @@ def load_dataset(self):

item = DataItem()
item.image_id = i
im_path = sample[0][0]
if isinstance(im_path, np.ndarray):
im_path = [str(x) for x in im_path.flatten()]
item.im_path = str(Path(*im_path) if isinstance(im_path, list) else Path(im_path))
item.im_path: str = _normalize_image_path(sample[0][0])
item.im_size = sample[1][0]
if len(sample) >= 3:
joints = sample[2][0][0]
Expand Down Expand Up @@ -125,10 +122,7 @@ def load_dataset(self):
sample = pickledata[i] # mlab[0, i]
item = DataItem()
item.image_id = i
im_path = sample["image"]
if isinstance(im_path, np.ndarray):
im_path = [str(x) for x in im_path.flatten()]
item.im_path = str(Path(*im_path)) # [0][0]
item.im_path: str = _normalize_image_path(sample["image"]) # [0][0]
item.im_size = sample["size"] # sample[1][0]
if len(sample) >= 3:
item.num_animals = len(sample["joints"])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from deeplabcut.pose_estimation_tensorflow.datasets import augmentation
from deeplabcut.pose_estimation_tensorflow.datasets.factory import PoseDatasetFactory
from deeplabcut.pose_estimation_tensorflow.datasets.pose_base import BasePoseDataset
from deeplabcut.pose_estimation_tensorflow.datasets.utils import Batch, DataItem
from deeplabcut.pose_estimation_tensorflow.datasets.utils import Batch, DataItem, _normalize_image_path
from deeplabcut.utils import auxfun_multianimal, auxiliaryfunctions
from deeplabcut.utils.auxfun_videos import VideoReader, imread

Expand Down Expand Up @@ -100,8 +100,7 @@ def load_dataset(self):
sample = pickledata[i] # mlab[0, i]
item = DataItem()
item.image_id = i
im_path = sample["image"]
item.im_path = str(Path(*im_path) if isinstance(im_path, list) else Path(im_path))
item.im_path: str = _normalize_image_path(sample["image"])
item.im_size = sample["size"]
if "joints" in sample.keys():
Joints = sample["joints"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@

from .factory import PoseDatasetFactory
from .pose_base import BasePoseDataset
from .utils import Batch, data_to_input
from .utils import Batch, _normalize_image_path, data_to_input


def img_to_bgr(im_path):
Expand Down Expand Up @@ -113,9 +113,7 @@ def load_dataset(self):
item = DataItem()
item.image_id = i
base = str(self.cfg["project_path"])
im_path = sample[0][0]
im_path = Path(*im_path) if isinstance(im_path, list) else Path(im_path)
item.im_path = str(Path(base) / im_path)
item.im_path = str(Path(base) / _normalize_image_path(sample[0][0]))
item.im_size = sample[1][0]
if len(sample) >= 3:
joints = sample[2][0][0]
Expand Down
10 changes: 10 additions & 0 deletions deeplabcut/pose_estimation_tensorflow/datasets/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
# Licensed under GNU Lesser General Public License v3.0
#
from enum import Enum
from pathlib import Path

import numpy as np

Expand All @@ -28,6 +29,15 @@ class DataItem:
pass


# NOTE @deruyter92 2026-07-21: the TensorFlow branch is deprecated soon, and excluded from the migration to pathlib
def _normalize_image_path(im_path: np.ndarray | list | tuple | Path | str) -> str:
"""Convert a raw image path from .mat or pickle format to a string."""
if isinstance(im_path, np.ndarray):
im_path = [str(x) for x in im_path.flatten()]
im_path = Path(*im_path) if isinstance(im_path, (list, tuple)) else Path(im_path)
return str(im_path)


def data_to_input(data):
return np.expand_dims(data, axis=0).astype(float)

Expand Down
Loading