Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
d6ee416
refactored weight init for better modularity
n-poulsen Sep 18, 2024
59511e3
refactored model downloading
n-poulsen Oct 1, 2024
a0fdeaf
update examples
n-poulsen Oct 1, 2024
58bf846
removed unused code
n-poulsen Oct 1, 2024
23b66f5
various bug fixes
n-poulsen Oct 1, 2024
2764b38
do not create pose_cfg for pytorch models
n-poulsen Oct 1, 2024
881f174
bug fix: keypoint matching
n-poulsen Oct 1, 2024
718d61b
bug fix: keypoint matching
n-poulsen Oct 1, 2024
f1422e1
fixed dlc scorer for zeroshot video
n-poulsen Oct 2, 2024
8f8510f
bug fix - super animal scorer
n-poulsen Oct 2, 2024
44613ab
fix max individuals when updating config
n-poulsen Oct 2, 2024
3a7b161
better check for annotation files
n-poulsen Oct 2, 2024
2a4c6a3
small improvements
n-poulsen Oct 2, 2024
02a279d
update SA detector augmentation
n-poulsen Oct 2, 2024
5c0656f
added SuperBird configs
n-poulsen Oct 2, 2024
7df067f
bug fix: config creation, set method
n-poulsen Oct 2, 2024
8fc6950
bug fixes: memory replay training
n-poulsen Oct 2, 2024
431e913
bug fix: evaluating with memory replay
n-poulsen Oct 2, 2024
04fa197
fix video analysis with memory replay
n-poulsen Oct 2, 2024
42d1081
added SuperBird colormap
n-poulsen Oct 2, 2024
c42f474
added SuperBird to pseudo-label
n-poulsen Oct 2, 2024
819d0e2
raise error when training with memory replay without detector
n-poulsen Oct 2, 2024
da13693
bug fix: raising error when no conversion table
n-poulsen Oct 2, 2024
d939e3c
fix pose config creation - joints for test config
n-poulsen Oct 3, 2024
b0b2208
bug fix
n-poulsen Oct 3, 2024
657b704
add default BU augmentation when Fine-Tuning SA model without detector
n-poulsen Oct 3, 2024
2e6c120
bug fix
n-poulsen Oct 3, 2024
3f87fee
clean video inference. add individuals to metadata.
n-poulsen Oct 3, 2024
e0c8302
bug fix: test pose cfg creation
n-poulsen Oct 3, 2024
a0bff4e
fix make labeled video with memory replay
n-poulsen Oct 3, 2024
fe00587
clean weight init
n-poulsen Oct 3, 2024
d54e7e1
bug fix
n-poulsen Oct 3, 2024
1177ef8
doc improvements and fixes to project configs
n-poulsen Oct 3, 2024
978845b
doc improvements
n-poulsen Oct 3, 2024
e588712
remove extra FIXME
n-poulsen Oct 3, 2024
0221957
doc fixes
n-poulsen Oct 3, 2024
0d008df
fix setup.py
n-poulsen Oct 3, 2024
16e4154
updated SuperAnimal COLAB
n-poulsen Oct 3, 2024
8b18244
updated docs
n-poulsen Oct 3, 2024
f62f1bd
update DLCLibrary version
n-poulsen Oct 3, 2024
26ae7db
fix modelzoo GUI
n-poulsen Oct 3, 2024
714d383
bug fix: tensorflow superanimal video creation
n-poulsen Oct 3, 2024
1b44363
fix cannot pickle memoryview, only use multianimalproject key when an…
n-poulsen Oct 7, 2024
fcab1ce
add cropping argument to SuperAnimal inference
n-poulsen Oct 7, 2024
ad3f7f8
add make_pytorch_test_config to config __init__
n-poulsen Oct 7, 2024
e94ce12
clean superbird config
n-poulsen Oct 7, 2024
480a2ac
do not pin detector dataloader memory
n-poulsen Oct 8, 2024
f18a02f
update SuperAnimal resnet_50 config
n-poulsen Oct 9, 2024
bdab2cd
add mobilenet fasterrcnn superanimal config
n-poulsen Oct 9, 2024
61e9ef6
bug fix: make_labeled_video SA finetune with mem replay, single anima…
n-poulsen Oct 9, 2024
d83503f
fix SuperAnimal memory replay evaluation
n-poulsen Oct 9, 2024
9e04427
update code for new models
n-poulsen Oct 10, 2024
4655b62
build_weight_init with str/path instead of loaded config
n-poulsen Oct 10, 2024
6b0883d
update dlclibrary to use get_available_datasets
n-poulsen Oct 15, 2024
0c6b4e4
updated config when loading SuperAnimal config
n-poulsen Oct 18, 2024
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
clean video inference. add individuals to metadata.
  • Loading branch information
n-poulsen committed Oct 3, 2024
commit 3f87fee9a50adece4dccb45c9cb144a00764ddb1
2 changes: 1 addition & 1 deletion deeplabcut/pose_estimation_pytorch/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ pose_runner, detector_runner = get_inference_runners(
)

predictions = video_inference(
video_path=video_path,
video=video_path,
task=pose_task,
pose_runner=pose_runner,
detector_runner=detector_runner,
Expand Down
39 changes: 25 additions & 14 deletions deeplabcut/pose_estimation_pytorch/apis/analyze_videos.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,31 +91,42 @@ def __next__(self) -> np.ndarray | tuple[str, dict[str, Any]]:


def video_inference(
video_path: str | Path,
video: str | Path | VideoIterator,
task: Task,
pose_runner: InferenceRunner,
detector_runner: InferenceRunner | None = None,
with_identity: bool = False,
return_video_metadata: bool = False,
cropping: list[int] | None = None,
) -> list[dict[str, np.ndarray]]:
"""Runs inference on a video"""
video = VideoIterator(str(video_path), cropping=cropping)
"""Runs inference on a video

Args:
video: The video to analyze
task: The pose task to run (bottom-up or top-down)
pose_runner: The pose runner to run inference with
detector_runner: When ``task==Task.TOP_DOWN``, the detector runner to obtain
bounding boxes for the video.
with_identity: Whether identity predictions should be made with the model.
cropping: Optionally, video inference can be run on a cropped version of the
video. To do so, pass a list containing 4 elements to specify which area
of the video should be analyzed: ``[xmin, xmax, ymin, ymax]``.

Returns:
Predictions for each frame in the video.
"""
if not isinstance(video, VideoIterator):
video = VideoIterator(str(video), cropping=cropping)

n_frames = video.get_n_frames()
vid_w, vid_h = video.dimensions
print(f"Starting to analyze {video_path}")
print(f"Starting to analyze {video.video_path}")
print(
f"Video metadata: \n"
f" Overall # of frames: {n_frames}\n"
f" Duration of video [s]: {n_frames / max(1, video.fps):.2f}\n"
f" fps: {video.fps}\n"
f" resolution: w={vid_w}, h={vid_h}\n"
)
video_metadata = {
"n_frames": n_frames,
"fps": video.fps,
"resolution": (vid_w, vid_h),
}

if task == Task.TOP_DOWN:
# Get bounding boxes for context
Expand Down Expand Up @@ -147,9 +158,6 @@ def video_inference(
f"video (tips on how to do that: {tip_url}{header})"
)

if return_video_metadata:
return predictions, video_metadata

return predictions


Expand Down Expand Up @@ -337,7 +345,7 @@ def analyze_videos(
else:
runtime = [time.time()]
predictions = video_inference(
video_path=video,
video=video,
pose_runner=pose_runner,
task=pose_task,
detector_runner=detector_runner,
Expand Down Expand Up @@ -558,6 +566,9 @@ def _generate_metadata(
"training set fraction": train_fraction,
"cropping": cropping is not None,
"cropping_parameters": cropping_parameters,
"individuals": pytorch_config["metadata"]["individuals"],
"bodyparts": pytorch_config["metadata"]["bodyparts"],
"unique_bodyparts": pytorch_config["metadata"]["unique_bodyparts"],
}
return {"data": metadata}

Expand Down
13 changes: 8 additions & 5 deletions deeplabcut/pose_estimation_pytorch/modelzoo/inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from deeplabcut.pose_estimation_pytorch.apis.analyze_videos import (
create_df_from_prediction,
video_inference,
VideoIterator,
)
from deeplabcut.pose_estimation_pytorch.apis.utils import get_inference_runners
from deeplabcut.pose_estimation_pytorch.modelzoo.utils import (
Expand Down Expand Up @@ -127,17 +128,19 @@ def _video_inference_superanimal(
# str(output_h5).replace(".h5", "_after_adapt.json")
output_json = output_json.with_stem(output_h5.stem + output_suffix)

predictions, video_metadata = video_inference(
video_path,
video = VideoIterator(video_path)
predictions = video_inference(
video,
task=pose_task,
pose_runner=pose_runner,
detector_runner=detector_runner,
return_video_metadata=True,
)

pred_bodyparts = np.stack([p["bodyparts"][..., :3] for p in predictions])
pred_unique_bodyparts = None

bbox = (0, video_metadata["resolution"][0], 0, video_metadata["resolution"][1])
vid_w, vid_h = video.dimensions
bbox = (0, vid_w, 0, vid_h)
print(f"Saving results to {dest_folder}")

df = create_df_from_prediction(
Expand All @@ -164,7 +167,7 @@ def _video_inference_superanimal(
video_path,
output_h5,
pcutoff=pcutoff,
fps=video_metadata["fps"],
fps=video.fps,
bbox=bbox,
cmap=colormap,
output_path=str(output_video),
Expand Down