Skip to content

Commit

Permalink
Add model and dataset analytics to PyTorchVideo
Browse files Browse the repository at this point in the history
Summary: For all PTV models, datasets and transforms, adding some analytics to aggregate user metrics

Reviewed By: tullie

Differential Revision: D28388721

fbshipit-source-id: 9bc45b5a7bda0e3f9d79ad71c79f9eb44d4f3a8f
  • Loading branch information
Florian Pinel authored and facebook-github-bot committed May 17, 2021
1 parent 6539ed6 commit 124e132
Show file tree
Hide file tree
Showing 15 changed files with 162 additions and 4 deletions.
3 changes: 3 additions & 0 deletions pytorchvideo/data/charades.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ def __init__(
frames_per_clip (Optional[int]): The number of frames per clip to sample.
"""

torch._C._log_api_usage_once("PYTORCHVIDEO.dataset.Charades.__init__")

self._transform = transform
self._clip_sampler = clip_sampler
(
Expand Down
3 changes: 3 additions & 0 deletions pytorchvideo/data/epic_kitchen/epic_kitchen_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,9 @@ def __init__(
multiple threads.
"""

torch._C._log_api_usage_once("PYTORCHVIDEO.dataset.EpicKitchenDataset.__init__")

assert video_info_file_path
assert actions_file_path
assert video_data_manifest_file_path
Expand Down
4 changes: 4 additions & 0 deletions pytorchvideo/data/hmdb51.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import pathlib
from typing import Any, Callable, List, Optional, Tuple, Type, Union

import torch
import torch.utils.data
from iopath.common.file_io import g_pathmgr

Expand Down Expand Up @@ -211,6 +212,9 @@ def Hmdb51(
decoder (str): Defines which backend should be used to decode videos.
"""

torch._C._log_api_usage_once("PYTORCHVIDEO.dataset.Hmdb51")

labeled_video_paths = Hmdb51LabeledVideoPaths.from_dir(
data_path, split_id=split_id, split_type=split_type
)
Expand Down
2 changes: 2 additions & 0 deletions pytorchvideo/data/json_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ def video_only_dataset(
frame videos.
"""

torch._C._log_api_usage_once("PYTORCHVIDEO.dataset.json_dataset.video_only_dataset")

if g_pathmgr.isfile(data_path):
try:
with g_pathmgr.open(data_path, "r") as f:
Expand Down
64 changes: 62 additions & 2 deletions pytorchvideo/data/kinetics.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,70 @@
# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.

from .labeled_video_dataset import labeled_video_dataset
from typing import Any, Callable, Dict, Optional, Type

import torch
from pytorchvideo.data.clip_sampling import ClipSampler

from .labeled_video_dataset import labeled_video_dataset, LabeledVideoDataset


"""
Action recognition video dataset for Kinetics-{400,600,700}
<https://deepmind.com/research/open-source/open-source-datasets/kinetics/>
"""
Kinetics = labeled_video_dataset


def Kinetics(
data_path: str,
clip_sampler: ClipSampler,
video_sampler: Type[torch.utils.data.Sampler] = torch.utils.data.RandomSampler,
transform: Optional[Callable[[Dict[str, Any]], Dict[str, Any]]] = None,
video_path_prefix: str = "",
decode_audio: bool = True,
decoder: str = "pyav",
) -> LabeledVideoDataset:
"""
A helper function to create ``LabeledVideoDataset`` object for the Kinetics dataset.
Args:
data_path (str): Path to the data. The path type defines how the data
should be read:
* For a file path, the file is read and each line is parsed into a
video path and label.
* For a directory, the directory structure defines the classes
(i.e. each subdirectory is a class).
clip_sampler (ClipSampler): Defines how clips should be sampled from each
video. See the clip sampling documentation for more information.
video_sampler (Type[torch.utils.data.Sampler]): Sampler for the internal
video container. This defines the order videos are decoded and,
if necessary, the distributed split.
transform (Callable): This callable is evaluated on the clip output before
the clip is returned. It can be used for user defined preprocessing and
augmentations to the clips. See the ``LabeledVideoDataset`` class for clip
output format.
video_path_prefix (str): Path to root directory with the videos that are
loaded in ``LabeledVideoDataset``. All the video paths before loading
are prefixed with this path.
decode_audio (bool): If True, also decode audio from video.
decoder (str): Defines what type of decoder used to decode a video.
"""

torch._C._log_api_usage_once("PYTORCHVIDEO.dataset.Kinetics")

return labeled_video_dataset(
data_path,
clip_sampler,
video_sampler,
transform,
video_path_prefix,
decode_audio,
decoder,
)
3 changes: 3 additions & 0 deletions pytorchvideo/data/ssv2.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ def __init__(
rand_sample_frames (bool): If True, randomly sampling frames for each clip.
"""

torch._C._log_api_usage_once("PYTORCHVIDEO.dataset.SSv2.__init__")

self._transform = transform
self._clip_sampler = clip_sampler
self._path_to_videos, self._labels = _read_video_paths_and_labels(
Expand Down
64 changes: 62 additions & 2 deletions pytorchvideo/data/ucf101.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,70 @@
# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.

from .labeled_video_dataset import labeled_video_dataset
from typing import Any, Callable, Dict, Optional, Type

import torch
from pytorchvideo.data.clip_sampling import ClipSampler

from .labeled_video_dataset import labeled_video_dataset, LabeledVideoDataset


"""
Action recognition video dataset for UCF101
<https://www.crcv.ucf.edu/data/UCF101.php>
"""
Ucf101 = labeled_video_dataset


def Ucf101(
data_path: str,
clip_sampler: ClipSampler,
video_sampler: Type[torch.utils.data.Sampler] = torch.utils.data.RandomSampler,
transform: Optional[Callable[[Dict[str, Any]], Dict[str, Any]]] = None,
video_path_prefix: str = "",
decode_audio: bool = True,
decoder: str = "pyav",
) -> LabeledVideoDataset:
"""
A helper function to create ``LabeledVideoDataset`` object for the Ucf101 dataset.
Args:
data_path (str): Path to the data. The path type defines how the data
should be read:
* For a file path, the file is read and each line is parsed into a
video path and label.
* For a directory, the directory structure defines the classes
(i.e. each subdirectory is a class).
clip_sampler (ClipSampler): Defines how clips should be sampled from each
video. See the clip sampling documentation for more information.
video_sampler (Type[torch.utils.data.Sampler]): Sampler for the internal
video container. This defines the order videos are decoded and,
if necessary, the distributed split.
transform (Callable): This callable is evaluated on the clip output before
the clip is returned. It can be used for user defined preprocessing and
augmentations to the clips. See the ``LabeledVideoDataset`` class for clip
output format.
video_path_prefix (str): Path to root directory with the videos that are
loaded in ``LabeledVideoDataset``. All the video paths before loading
are prefixed with this path.
decode_audio (bool): If True, also decode audio from video.
decoder (str): Defines what type of decoder used to decode a video.
"""

torch._C._log_api_usage_once("PYTORCHVIDEO.dataset.Ucf101")

return labeled_video_dataset(
data_path,
clip_sampler,
video_sampler,
transform,
video_path_prefix,
decode_audio,
decoder,
)
3 changes: 3 additions & 0 deletions pytorchvideo/models/byol.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ def __init__(
synchronized batchnorm.
"""
super().__init__()

torch._C._log_api_usage_once("PYTORCHVIDEO.model.BYOL.__init__")

self.mmt = mmt
self.feature_dim = feature_dim
if projector is not None:
Expand Down
4 changes: 4 additions & 0 deletions pytorchvideo/models/csn.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from typing import Callable, Tuple

import torch
import torch.nn as nn
from pytorchvideo.models.head import create_res_basic_head
from pytorchvideo.models.resnet import Net, create_bottleneck_block, create_res_stage
Expand Down Expand Up @@ -110,6 +111,9 @@ def create_csn(
Returns:
(nn.Module): the csn model.
"""

torch._C._log_api_usage_once("PYTORCHVIDEO.model.create_csn")

# Number of blocks for different stages given the model depth.
_MODEL_STAGE_DEPTH = {50: (3, 4, 6, 3), 101: (3, 4, 23, 3), 152: (3, 8, 36, 3)}

Expand Down
1 change: 1 addition & 0 deletions pytorchvideo/models/head.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ def create_res_basic_head(
output_with_global_average (bool): if True, perform global averaging on temporal
and spatial dimensions and reshape output to batch_size x out_features.
"""

if activation is None:
activation_model = None
elif activation == nn.Softmax:
Expand Down
4 changes: 4 additions & 0 deletions pytorchvideo/models/r2plus1d.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from functools import partial
from typing import Callable, Tuple

import torch
import torch.nn as nn
from pytorchvideo.layers.convolutions import create_conv_2plus1d
from pytorchvideo.models.head import create_res_basic_head
Expand Down Expand Up @@ -235,6 +236,9 @@ def create_r2plus1d(
Returns:
(nn.Module): basic resnet.
"""

torch._C._log_api_usage_once("PYTORCHVIDEO.model.create_r2plus1d")

# Number of blocks for different stages given the model depth.
_MODEL_STAGE_DEPTH = {50: (3, 4, 6, 3), 101: (3, 4, 23, 3), 152: (3, 8, 36, 3)}

Expand Down
3 changes: 3 additions & 0 deletions pytorchvideo/models/resnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -705,6 +705,9 @@ def create_resnet(
Returns:
(nn.Module): basic resnet.
"""

torch._C._log_api_usage_once("PYTORCHVIDEO.model.create_resnet")

# Number of blocks for different stages given the model depth.
_MODEL_STAGE_DEPTH = {50: (3, 4, 6, 3), 101: (3, 4, 23, 3), 152: (3, 8, 36, 3)}

Expand Down
3 changes: 3 additions & 0 deletions pytorchvideo/models/simclr.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ def __init__(
temperature: float = 0.07,
) -> None:
super().__init__()

torch._C._log_api_usage_once("PYTORCHVIDEO.model.SimCLR.__init__")

set_attributes(self, locals())

def forward(self, x1: torch.Tensor, x2: torch.Tensor) -> torch.Tensor:
Expand Down
2 changes: 2 additions & 0 deletions pytorchvideo/models/slowfast.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,8 @@ def create_slowfast(
(nn.Module): SlowFast model.
"""

torch._C._log_api_usage_once("PYTORCHVIDEO.model.create_slowfast")

# Number of blocks for different stages given the model depth.
_num_pathway = len(input_channels)
_MODEL_STAGE_DEPTH = {
Expand Down
3 changes: 3 additions & 0 deletions pytorchvideo/models/x3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -642,6 +642,9 @@ def create_x3d(
Returns:
(nn.Module): the X3D network.
"""

torch._C._log_api_usage_once("PYTORCHVIDEO.model.create_x3d")

blocks = []
# Create stem for X3D.
stem_dim_out = round_width(stem_dim_in, width_factor)
Expand Down

0 comments on commit 124e132

Please sign in to comment.