Skip to content
Merged
Changes from all commits
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
26 changes: 25 additions & 1 deletion deeplabcut/refine_training_dataset/outlier_frames.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ def extract_outlier_frames(
shuffle=1,
trainingsetindex=0,
outlieralgorithm="jump",
frames2use=None,
comparisonbodyparts="all",
epsilon=20,
p_bound=0.01,
Expand Down Expand Up @@ -237,6 +238,10 @@ def extract_outlier_frames(
* ``'jump'`` identifies larger jumps than 'epsilon' in any body part
* ``'uncertain'`` looks for frames with confidence below p_bound
* ``'manual'`` launches a GUI from which the user can choose the frames
* ``'list'`` looks for user to provide a list of frame numbers to use, 'frames2use'. In this case, ``'extractionalgorithm'`` is forced to be ``'uniform.'``

frames2use: list[str], optional, default=None
If ``'outlieralgorithm'`` is ``'list'``, provide the list of frames here.

comparisonbodyparts: list[str] or str, optional, default="all"
This selects the body parts for which the comparisons with the outliers are
Expand Down Expand Up @@ -420,8 +425,20 @@ def extract_outlier_frames(

_ = launch_napari()
return
elif outlieralgorithm == "list":
if frames2use is not None:
try:
frames2use = np.array(frames2use).astype('int')
except ValueError() as e:
print('Could not cast frames2use into np array, please check that frames2use is a simply a list of integers!')
raise
Indices.extend(frames2use)
else:
raise ValueError('Expected list of frames2use for outlieralgorithm "list"!')
else:
raise ValueError(f'outlieralgorithm {outlieralgorithm} not recognized!')

# Run always except when the outlieralgorithm == manual.
# Run always except when the outlieralgorithm == manual.
if not outlieralgorithm == "manual":
Indices = np.sort(list(set(Indices))) # remove repetitions.
print(
Expand Down Expand Up @@ -644,14 +661,21 @@ def ExtractFramesbasedonPreselection(
else:
coords = None

print("Cropping coords:", coords)
print("Duration of video [s]: ", duration, ", recorded @ ", fps, "fps!")
print("Overall # of frames: ", nframes, "with (cropped) frame dimensions: ")
if extractionalgorithm == "uniform":
if opencv:
if coords is not None:
vid.set_bbox(*coords)
frames2pick = frameselectiontools.UniformFramescv2(
vid, numframes2extract, start, stop, Index
)
else:
if coords is not None:
clip = clip.crop(
y1=coords[2], y2=coords[3], x1=coords[0], x2=coords[1],
)
frames2pick = frameselectiontools.UniformFrames(
clip, numframes2extract, start, stop, Index
)
Expand Down