Skip to content

Commit 054af78

Browse files
Merge pull request #8 from TravisWheelerLab/update-pose-labelers
import coloarmarp
2 parents 6f77856 + 4a6ff0a commit 054af78

File tree

7 files changed

+331
-177
lines changed

7 files changed

+331
-177
lines changed

diplomat/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
A tool providing multi-animal tracking capabilities on top of other Deep learning based tracking software.
33
"""
44

5-
__version__ = "0.1.1"
5+
__version__ = "0.1.2"
66
# Can be used by functions to determine if diplomat was invoked through it's CLI interface.
77
CLI_RUN = False
88

diplomat/frontends/deeplabcut/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from typing import Optional
22
from diplomat.frontends import DIPLOMATFrontend, DIPLOMATCommands
3-
3+
from diplomat.utils import colormaps
44

55
class DEEPLABCUTFrontend(DIPLOMATFrontend):
66
"""

diplomat/predictors/fpe/frame_passes/fix_frame.py

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,21 @@ def get_max_location(
4848
frame: ForwardBackwardFrame,
4949
down_scaling: float
5050
) -> Tuple[Optional[float], Optional[float], Optional[float]]:
51+
"""
52+
Determines the maximum location within a frame after downscaling.
53+
54+
This method identifies the maximum probability location within a given frame and adjusts its coordinates
55+
based on the provided downscaling factor. It returns the adjusted x and y coordinates along with the
56+
maximum probability value.
57+
58+
Parameters:
59+
- frame: ForwardBackwardFrame, the frame to analyze.
60+
- down_scaling: float, the factor by which the frame's coordinates are downscaled.
61+
62+
Returns:
63+
- Tuple[Optional[float], Optional[float], Optional[float]]: The adjusted x and y coordinates of the maximum
64+
location and its probability. Returns None for each value if the probability data is not available.
65+
"""
5166
y, x, prob, x_off, y_off = frame.src_data.unpack()
5267

5368
if(prob is None):
@@ -347,6 +362,24 @@ def compute_single_score(
347362
max_dist: float,
348363
progress_bar: Optional[ProgressBar] = None
349364
) -> Tuple[float, float]:
365+
"""
366+
Computes a single score for a given set of frames, considering the number of outputs, down scaling factor,
367+
an optional skeleton, and the maximum distance. This function aggregates the scores across all body part groupings,
368+
taking into account the minimum distance between body parts and their confidence levels. It returns a tuple
369+
containing two scores, which represent different aspects of the frame's quality or suitability for further processing.
370+
371+
Parameters:
372+
- frames: List[ForwardBackwardFrame], a list of frames to be scored.
373+
- num_outputs: int, the number of outputs or body parts to consider in each frame.
374+
- down_scaling: float, the factor by which the frame dimensions have been scaled down.
375+
- skeleton: Optional[StorageGraph], an optional graph representing the skeleton to be considered in scoring.
376+
- max_dist: float, the maximum distance to consider when scoring body part pairs.
377+
- progress_bar: Optional[ProgressBar], an optional progress bar to display processing progress.
378+
379+
Returns:
380+
- Tuple[float, float]: A tuple containing two scores calculated based on the minimum distances and confidence levels
381+
of body part pairs across the given frames.
382+
"""
350383
num_bp = len(frames) // num_outputs
351384

352385
score = 0
@@ -360,6 +393,7 @@ def compute_single_score(
360393

361394
# For body part groupings...
362395
for i in range(num_outputs - 1):
396+
#get the maximum probability location for the body part
363397
f1_loc = cls.get_max_location(
364398
frames[bp_group_off * num_outputs + i],
365399
down_scaling
@@ -377,7 +411,8 @@ def compute_single_score(
377411
if (f2_loc[0] is None):
378412
score = -np.inf
379413
continue
380-
414+
415+
#mininum distance between the two body parts
381416
min_dist = min(cls.dist(f1_loc, f2_loc), min_dist)
382417
total_conf += f1_loc[2] * f2_loc[2]
383418
count += 1
@@ -386,18 +421,23 @@ def compute_single_score(
386421
min_dist = 0
387422
if(min_dist == 0 or count == 0):
388423
# BAD! We found a frame that failed to cluster properly...
424+
425+
#looks like this is the difference between score and score2?
389426
score = -np.inf
390427

391428
# Minimum distance, weighted by average skeleton-pair confidence...
392429
if(count > 0):
393430
score += min_dist * (total_conf / count)
394431
score2 += min_dist * (total_conf / count)
432+
395433

396434
# If skeleton is implemented...
397435
if (skeleton is not None):
398436
skel = skeleton
399437

400438
for bp in range(len(frames)):
439+
440+
#what is this ?
401441
bp_group_off, bp_off = divmod(bp, num_outputs)
402442

403443
num_pairs = num_outputs * len(skel[bp_group_off])
@@ -448,6 +488,7 @@ def compute_list_of_scores(
448488
progress_bar.reset(len(frames))
449489

450490
for i, frame in enumerate(frames):
491+
#this will be a tuple of scores per frame
451492
final_scores[i] = cls.compute_single_score(frame, num_outputs, down_scaling, skeleton, max_dist)
452493

453494
if(progress_bar is not None):
@@ -463,6 +504,23 @@ def compute_scores(
463504
reset_bar: bool = False,
464505
thread_count: int = 0
465506
) -> Tuple[np.ndarray, np.ndarray]:
507+
"""
508+
Computes the scores for each frame in the ForwardBackwardData object.
509+
510+
This method calculates two scores for each frame based on the frame data provided. The scores are computed
511+
by evaluating the frame against a set of criteria defined in the compute_single_score method. The scores
512+
are intended to be used for determining the quality of the frame data and for further processing steps
513+
such as segmentation.
514+
515+
Parameters:
516+
- fb_data: ForwardBackwardData, the data containing frames to be scored.
517+
- prog_bar: ProgressBar, a progress bar object for visual feedback during the scoring process.
518+
- reset_bar: bool, a flag indicating whether to reset the progress bar before starting the scoring process.
519+
- thread_count: int, the number of threads to use for parallel processing of the scoring.
520+
521+
Returns:
522+
- Tuple[np.ndarray, np.ndarray], two arrays containing the computed scores for each frame.
523+
"""
466524
if("is_clustered" not in fb_data.metadata):
467525
raise PassOrderError(
468526
"Clustering must be done before frame fixing!"

0 commit comments

Comments
 (0)