@@ -64,20 +64,17 @@ disk.
6464``` python
6565from pathlib import Path
6666
67- from deeplabcut.pose_estimation_pytorch.config import (
68- make_pytorch_pose_config,
69- write_config,
70- )
67+ import deeplabcut.pose_estimation_pytorch as dlc_torch
7168
7269project_cfg = { " Task" : " mice" , ... } # the configuration for your DLC project
7370pose_config_path = Path(" /path/to/my/config/pytorch_cfg.yaml" )
74- model_cfg = make_pytorch_pose_config(
71+ model_cfg = dlc_torch.config. make_pytorch_pose_config(
7572 project_config = project_cfg,
7673 pose_config_path = pose_config_path,
7774 net_type = " hrnet_w32" ,
7875 top_down = True ,
76+ save = True ,
7977)
80- write_config(pose_config_path, model_cfg)
8178```
8279
8380#### Adding Models
@@ -238,9 +235,9 @@ dataset creation and test/train splitting. The `DLCLoader` class is used to load
238235labeled data for a specific shuffle.
239236
240237``` python3
241- from deeplabcut.pose_estimation_pytorch.data import DLCLoader
238+ import deeplabcut.pose_estimation_pytorch as dlc_torch
242239
243- loader = DLCLoader(
240+ loader = dlc_torch. DLCLoader(
244241 config = " /path/to/my/project/config.yaml" ,
245242 trainset_index = 0 ,
246243 shuffle = 1 ,
@@ -265,23 +262,20 @@ images and keypoints to a tensor dataset for training and evaluation. You can ge
265262an instance of training/test dataset with your ` DLCLoader ` :
266263
267264``` python3
268- from deeplabcut.pose_estimation_pytorch.data import (
269- build_transforms,
270- DLCLoader,
271- )
265+ import deeplabcut.pose_estimation_pytorch as dlc_torch
272266
273- loader = DLCLoader(
267+ loader = dlc_torch. DLCLoader(
274268 config = " /path/to/my/project/config.yaml" ,
275269 trainset_index = 0 ,
276270 shuffle = 1 ,
277271)
278272train_dataset = loader.create_dataset(
279- transform = build_transforms(loader.model_cfg[" data" ][" train" ]),
273+ transform = dlc_torch. build_transforms(loader.model_cfg[" data" ][" train" ]),
280274 mode = " train" ,
281275 task = loader.pose_task,
282276)
283277valid_dataset = loader.create_dataset(
284- transform = build_transforms(loader.model_cfg[" data" ][" train" ]),
278+ transform = dlc_torch. build_transforms(loader.model_cfg[" data" ][" train" ]),
285279 mode = " test" ,
286280 task = loader.pose_task,
287281)
@@ -320,58 +314,48 @@ configuration file (as described in [#model_configuration_files]).
320314``` python3
321315from pathlib import Path
322316
323- from deeplabcut.pose_estimation_pytorch.config import (
324- make_pytorch_pose_config,
325- write_config,
326- )
327- from deeplabcut.pose_estimation_pytorch.data import (
328- build_transforms,
329- COCOLoader,
330- )
331- from deeplabcut.pose_estimation_pytorch.task import Task
317+ import deeplabcut.pose_estimation_pytorch as dlc_torch
332318
333319# Specify project paths
334320project_root = Path(" /path/to/my/COCOProject" )
335321train_json_filename = " train.json"
336322test_json_filename = " test.json"
337323
338324# Parse information about the project
339- train_dict = COCOLoader.load_json(project_root, filename = train_json_filename)
340- max_num_individuals, bodyparts = COCOLoader.get_project_parameters(train_dict)
325+ train_dict = dlc_torch. COCOLoader.load_json(project_root, filename = train_json_filename)
326+ max_num_individuals, bodyparts = dlc_torch. COCOLoader.get_project_parameters(train_dict)
341327
342328# Generate a configuration file for your PyTorch model
343329# In this case, it's for a Top-Down HRNet_w32
344330experiment_path = project_root / " experiments" / " hrnet_w32"
345331model_cfg_path = experiment_path / " train" / " pytorch_cfg.yaml"
346- model_cfg = make_pytorch_pose_config(
347- project_config = {
348- " project_path" : str (project_root.resolve()),
349- " multianimalproject" : max_num_individuals > 1 ,
350- " bodyparts" : bodyparts,
351- " multianimalbodyparts" : bodyparts,
352- " uniquebodyparts" : [],
353- " individuals" : [f " idv { i} " for i in range (max_num_individuals)],
354- },
332+ model_cfg = dlc_torch.config.make_pytorch_pose_config(
333+ project_config = dlc_torch.config.make_basic_project_config(
334+ dataset_path = str (project_root.resolve()),
335+ bodyparts = bodyparts,
336+ max_individuals = max_num_individuals,
337+ multi_animal = True ,
338+ ),
355339 pose_config_path = experiment_path,
356340 net_type = " hrnet_w32" ,
357341 top_down = True ,
342+ save = True ,
358343)
359- write_config(config_path = model_cfg_path, config = model_cfg)
360344
361345# Create the loader for the COCO dataset
362- loader = COCOLoader(
346+ loader = dlc_torch. COCOLoader(
363347 project_root = project_root,
364348 model_config_path = " /path/to/my/project/experiments/pytorch_config.yaml" ,
365349 train_json_filename = train_json_filename,
366350 test_json_filename = test_json_filename,
367351)
368352train_dataset = loader.create_dataset(
369- transform = build_transforms(loader.model_cfg[" data" ][" train" ]),
353+ transform = dlc_torch. build_transforms(loader.model_cfg[" data" ][" train" ]),
370354 mode = " train" ,
371355 task = loader.pose_task,
372356)
373357valid_dataset = loader.create_dataset(
374- transform = build_transforms(loader.model_cfg[" data" ][" train" ]),
358+ transform = dlc_torch. build_transforms(loader.model_cfg[" data" ][" train" ]),
375359 mode = " test" ,
376360 task = loader.pose_task,
377361)
@@ -389,16 +373,15 @@ pretrained weights, and either train them or run inference with them.
389373``` python
390374from pathlib import Path
391375
376+ import deeplabcut.pose_estimation_pytorch as dlc_torch
392377from deeplabcut.pose_estimation_pytorch.apis.train import train
393- from deeplabcut.pose_estimation_pytorch.data import COCOLoader
394- from deeplabcut.pose_estimation_pytorch.task import Task
395378
396379# Specify project paths
397380project_root = Path(" /path/to/my/COCOProject" )
398381train_json_filename = " train.json"
399382test_json_filename = " test.json"
400383
401- loader = COCOLoader(
384+ loader = dlc_torch. COCOLoader(
402385 project_root = project_root,
403386 model_config_path = " /path/to/my/project/experiments/pytorch_config.yaml" ,
404387 train_json_filename = train_json_filename,
@@ -407,7 +390,7 @@ loader = COCOLoader(
407390train(
408391 loader = loader,
409392 run_config = loader.model_cfg,
410- task = Task(loader.model_cfg[" method" ]),
393+ task = dlc_torch. Task(loader.model_cfg[" method" ]),
411394 device = " cuda:2" ,
412395 logger_config = dict (
413396 type = " WandbLogger" ,
@@ -421,7 +404,7 @@ train(
421404### Running Video Analysis outside a DeepLabCut Project
422405
423406DeepLabCut provides high-level APIs (via the GUI or the python package) to analyze your
424- data. The usage of this API assumes the existance of a DLC project (with ` config.yaml `
407+ data. The usage of this API assumes the existence of a DLC project (with ` config.yaml `
425408file, etc.).
426409
427410Sometimes it might be more convenient to just run a model on your data via a low-level
@@ -431,10 +414,7 @@ example below:
431414``` python
432415from pathlib import Path
433416
434- from deeplabcut.pose_estimation_pytorch import Task
435- from deeplabcut.pose_estimation_pytorch.apis.analyze_videos import video_inference
436- from deeplabcut.pose_estimation_pytorch.config import read_config_as_dict
437- from deeplabcut.pose_estimation_pytorch.apis.utils import get_inference_runners
417+ import deeplabcut.pose_estimation_pytorch as dlc_torch
438418
439419train_dir = Path(" /Users/Jaylen/my-dlc-models/train" )
440420pytorch_config_path = train_dir / " pytorch_config.yaml"
@@ -450,21 +430,26 @@ batch_size = 16
450430detector_batch_size = 8
451431
452432# read model configuration
453- model_cfg = read_config_as_dict(pytorch_config_path)
454-
455- pose_task = Task(model_cfg[" method" ])
456- pose_runner, detector_runner = get_inference_runners(
433+ model_cfg = dlc_torch.config.read_config_as_dict(pytorch_config_path)
434+ pose_task = dlc_torch.Task(model_cfg[" method" ])
435+ pose_runner = dlc_torch.get_pose_inference_runner(
457436 model_config = model_cfg,
458437 snapshot_path = snapshot_path,
459438 max_individuals = max_num_animals,
460439 batch_size = batch_size,
461- detector_batch_size = detector_batch_size,
462- detector_path = detector_snapshot_path,
463440)
464441
465- predictions = video_inference(
442+ detector_runner = None
443+ if pose_task == dlc_torch.Task.TOP_DOWN :
444+ detector_runner = dlc_torch.get_detector_inference_runner(
445+ model_config = model_cfg,
446+ snapshot_path = detector_snapshot_path,
447+ max_individuals = max_num_animals,
448+ batch_size = detector_batch_size,
449+ )
450+
451+ predictions = dlc_torch.video_inference(
466452 video = video_path,
467- task = pose_task,
468453 pose_runner = pose_runner,
469454 detector_runner = detector_runner,
470455)
@@ -486,13 +471,11 @@ You can easily do so by writing a bit of custom code, as shown in the example be
486471from pathlib import Path
487472
488473import numpy as np
489- from deeplabcut.pose_estimation_pytorch import get_inference_runners
490- from deeplabcut.pose_estimation_pytorch.apis import VideoIterator
491- from deeplabcut.pose_estimation_pytorch.config import read_config_as_dict
474+ import deeplabcut.pose_estimation_pytorch as dlc_torch
492475from tqdm import tqdm
493476
494477# create an iterator for your video
495- video = VideoIterator(" /Users/Jayson/my-cool-video.mp4" )
478+ video = dlc_torch. VideoIterator(" /Users/Jayson/my-cool-video.mp4" )
496479
497480# dummy bboxes - you can load yours from a file or in another way
498481# the bboxes should be in `xywh` format, i.e. (x_top_left, y_top_left, width, height)
@@ -512,8 +495,8 @@ video.set_context(bounding_boxes)
512495max_individuals = np.max([len (context[" bboxes" ]) for context in bounding_boxes])
513496
514497# run inference!
515- model_cfg = read_config_as_dict(" /Users/Jayson/pytorch_config.yaml" )
516- pose_runner, _ = get_inference_runners (
498+ model_cfg = dlc_torch.config. read_config_as_dict(" /Users/Jayson/pytorch_config.yaml" )
499+ pose_runner = dlc_torch.get_pose_inference_runner (
517500 model_config = model_cfg,
518501 snapshot_path = Path(" /Users/Jayson/model-snapshot.pt" ),
519502 max_individuals = max_individuals,
0 commit comments