Visitar URL original
Improve `deeplabcut.pose_estimation_pytorch` imports by n-poulsen · Pull Request #2833 · DeepLabCut/DeepLabCut · GitHub
Skip to content
Merged
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
Merge branch 'pytorch_dlc' into niels/dlc3_diagram
  • Loading branch information
Niels Poulsen
Niels Poulsen committed Dec 20, 2024
commit f0200fcc7edc74d66122d0b3dba4be71c32c0e7e
23 changes: 11 additions & 12 deletions deeplabcut/pose_estimation_pytorch/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,11 @@ train(
### Running Video Analysis outside a DeepLabCut Project

DeepLabCut provides high-level APIs (via the GUI or the python package) to analyze your
<<<<<<< HEAD
data. The usage of this API assumes the existence of a DLC project (with `config.yaml`
=======
data. The usage of this API assumes the existance of a DLC project (with `config.yaml`
>>>>>>> pytorch_dlc
file, etc.).

Sometimes it might be more convenient to just run a model on your data via a low-level
Expand All @@ -432,9 +436,6 @@ example below:
from pathlib import Path

import deeplabcut.pose_estimation_pytorch as pep
from deeplabcut.pose_estimation_pytorch.apis.analyze_videos import video_inference
from deeplabcut.pose_estimation_pytorch.config import read_config_as_dict
from deeplabcut.pose_estimation_pytorch.task import Task

train_dir = Path("/Users/Jaylen/my-dlc-models/train")
pytorch_config_path = train_dir / "pytorch_config.yaml"
Expand All @@ -450,8 +451,8 @@ batch_size = 16
detector_batch_size = 8

# read model configuration
model_cfg = read_config_as_dict(pytorch_config_path)
pose_task = Task(model_cfg["method"])
model_cfg = pep.config.read_config_as_dict(pytorch_config_path)
pose_task = pep.Task(model_cfg["method"])
pose_runner = pep.get_pose_inference_runner(
model_config=model_cfg,
snapshot_path=snapshot_path,
Expand All @@ -468,7 +469,7 @@ if pose_task == pep.Task.TOP_DOWN:
batch_size=detector_batch_size,
)

predictions = video_inference(
predictions = pep.video_inference(
video=video_path,
pose_runner=pose_runner,
detector_runner=detector_runner,
Expand All @@ -491,13 +492,11 @@ You can easily do so by writing a bit of custom code, as shown in the example be
from pathlib import Path

import numpy as np
from deeplabcut.pose_estimation_pytorch import get_inference_runners
from deeplabcut.pose_estimation_pytorch.apis import VideoIterator
from deeplabcut.pose_estimation_pytorch.config import read_config_as_dict
import deeplabcut.pose_estimation_pytorch as pep
from tqdm import tqdm

# create an iterator for your video
video = VideoIterator("/Users/Jayson/my-cool-video.mp4")
video = pep.VideoIterator("/Users/Jayson/my-cool-video.mp4")

# dummy bboxes - you can load yours from a file or in another way
# the bboxes should be in `xywh` format, i.e. (x_top_left, y_top_left, width, height)
Expand All @@ -517,8 +516,8 @@ video.set_context(bounding_boxes)
max_individuals = np.max([len(context["bboxes"]) for context in bounding_boxes])

# run inference!
model_cfg = read_config_as_dict("/Users/Jayson/pytorch_config.yaml")
pose_runner, _ = get_inference_runners(
model_cfg = pep.config.read_config_as_dict("/Users/Jayson/pytorch_config.yaml")
pose_runner = pep.get_pose_inference_runner(
model_config=model_cfg,
snapshot_path=Path("/Users/Jayson/model-snapshot.pt"),
max_individuals=max_individuals,
Expand Down
You are viewing a condensed version of this merge commit. You can view the full changes here.