Skip to content

Commit

Permalink
apply Black 2024 style in fbcode (4/16)
Browse files Browse the repository at this point in the history
Summary:
Formats the covered files with pyfmt.

paintitblack

Reviewed By: aleivag

Differential Revision: D54447727

fbshipit-source-id: 8844b1caa08de94d04ac4df3c768dbf8c865fd2f
  • Loading branch information
amyreese authored and facebook-github-bot committed Mar 3, 2024
1 parent eb04d1b commit 1fadaef
Show file tree
Hide file tree
Showing 16 changed files with 148 additions and 110 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
from .transmuter_mobile_cpu import EFFICIENT_BLOCK_TRANSMUTER_MOBILE_CPU


EFFICIENT_BLOCK_TRANSMUTER_REGISTRY[
"mobile_cpu"
] = EFFICIENT_BLOCK_TRANSMUTER_MOBILE_CPU
EFFICIENT_BLOCK_TRANSMUTER_REGISTRY["mobile_cpu"] = (
EFFICIENT_BLOCK_TRANSMUTER_MOBILE_CPU
)
14 changes: 7 additions & 7 deletions pytorchvideo/data/domsev.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,9 +197,9 @@ def __init__(
labels_file_path, LabelData, "video_id", list_per_key=True
)
# Maps an image frame ID to the singular frame label
self._labels_per_frame: Dict[
str, int
] = DomsevFrameDataset._assign_labels_to_frames(frames_dict, video_labels)
self._labels_per_frame: Dict[str, int] = (
DomsevFrameDataset._assign_labels_to_frames(frames_dict, video_labels)
)

self._user_transform = transform
self._transform = self._transform_frame
Expand Down Expand Up @@ -380,10 +380,10 @@ def __init__(
dataset_type,
)

self._labels_per_video: Dict[
str, List[LabelData]
] = load_dataclass_dict_from_csv(
labels_file_path, LabelData, "video_id", list_per_key=True
self._labels_per_video: Dict[str, List[LabelData]] = (
load_dataclass_dict_from_csv(
labels_file_path, LabelData, "video_id", list_per_key=True
)
)

# Sample datapoints
Expand Down
2 changes: 0 additions & 2 deletions pytorchvideo/layers/squeeze_excitation.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ def __init__(
reduction_ratio: Optional[int] = 16,
reduced_planes: Optional[int] = None,
):

"""
Args:
in_planes (int): input channel dimension.
Expand Down Expand Up @@ -74,7 +73,6 @@ def create_audio_2d_squeeze_excitation_block(
# Activation configs.
activation: Callable = nn.ReLU,
) -> nn.Module:

"""
2-D Residual block with squeeze excitation (SE2D) for 2d. Performs a summation between an
identity shortcut in branch1 and a main block in branch2. When the input and
Expand Down
36 changes: 21 additions & 15 deletions pytorchvideo/models/resnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -425,15 +425,17 @@ def create_res_block(
norm_model = norm(num_features=dim_out, eps=norm_eps, momentum=norm_momentum)

return ResBlock(
branch1_conv=conv_skip(
dim_in,
dim_out,
kernel_size=(1, 1, 1),
stride=branch1_conv_stride,
bias=False,
)
if (dim_in != dim_out or np.prod(branch1_conv_stride) != 1) or use_shortcut
else None,
branch1_conv=(
conv_skip(
dim_in,
dim_out,
kernel_size=(1, 1, 1),
stride=branch1_conv_stride,
bias=False,
)
if (dim_in != dim_out or np.prod(branch1_conv_stride) != 1) or use_shortcut
else None
),
branch1_norm=norm_model,
branch2=bottleneck(
dim_in=dim_in,
Expand Down Expand Up @@ -795,12 +797,16 @@ def create_resnet(
conv_b_stride=stage_conv_b_stride,
conv_b_padding=(
stage_conv_b_kernel_size[idx][0] // 2,
stage_conv_b_dilation[idx][1]
if stage_conv_b_dilation[idx][1] > 1
else stage_conv_b_kernel_size[idx][1] // 2,
stage_conv_b_dilation[idx][2]
if stage_conv_b_dilation[idx][2] > 1
else stage_conv_b_kernel_size[idx][2] // 2,
(
stage_conv_b_dilation[idx][1]
if stage_conv_b_dilation[idx][1] > 1
else stage_conv_b_kernel_size[idx][1] // 2
),
(
stage_conv_b_dilation[idx][2]
if stage_conv_b_dilation[idx][2] > 1
else stage_conv_b_kernel_size[idx][2] // 2
),
),
conv_b_num_groups=stage_conv_b_num_groups[idx],
conv_b_dilation=stage_conv_b_dilation[idx],
Expand Down
16 changes: 10 additions & 6 deletions pytorchvideo/models/slowfast.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,12 +297,16 @@ def create_slowfast(
conv_b_stride=stage_conv_b_stride,
conv_b_padding=(
stage_conv_b_kernel_sizes[pathway_idx][idx][0] // 2,
stage_conv_b_dilations[pathway_idx][idx][1]
if stage_conv_b_dilations[pathway_idx][idx][1] > 1
else stage_conv_b_kernel_sizes[pathway_idx][idx][1] // 2,
stage_conv_b_dilations[pathway_idx][idx][2]
if stage_conv_b_dilations[pathway_idx][idx][2] > 1
else stage_conv_b_kernel_sizes[pathway_idx][idx][2] // 2,
(
stage_conv_b_dilations[pathway_idx][idx][1]
if stage_conv_b_dilations[pathway_idx][idx][1] > 1
else stage_conv_b_kernel_sizes[pathway_idx][idx][1] // 2
),
(
stage_conv_b_dilations[pathway_idx][idx][2]
if stage_conv_b_dilations[pathway_idx][idx][2] > 1
else stage_conv_b_kernel_sizes[pathway_idx][idx][2] // 2
),
),
conv_b_num_groups=stage_conv_b_num_groups[pathway_idx][idx],
conv_b_dilation=stage_conv_b_dilations[pathway_idx][idx],
Expand Down
20 changes: 11 additions & 9 deletions pytorchvideo/models/x3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,15 +294,17 @@ def create_x3d_res_block(
norm_model = norm(num_features=dim_out)

return ResBlock(
branch1_conv=nn.Conv3d(
dim_in,
dim_out,
kernel_size=(1, 1, 1),
stride=conv_stride,
bias=False,
)
if (dim_in != dim_out or np.prod(conv_stride) > 1) and use_shortcut
else None,
branch1_conv=(
nn.Conv3d(
dim_in,
dim_out,
kernel_size=(1, 1, 1),
stride=conv_stride,
bias=False,
)
if (dim_in != dim_out or np.prod(conv_stride) > 1) and use_shortcut
else None
),
branch1_norm=norm_model if dim_in != dim_out and use_shortcut else None,
branch2=bottleneck(
dim_in=dim_in,
Expand Down
6 changes: 3 additions & 3 deletions pytorchvideo/transforms/transforms_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,9 +222,9 @@ def create_video_transform(
"scale"
]
if "aspect_ratio" not in random_resized_crop_paras:
random_resized_crop_paras[
"aspect_ratio"
] = _RANDOM_RESIZED_CROP_DEFAULT_PARAS["aspect_ratio"]
random_resized_crop_paras["aspect_ratio"] = (
_RANDOM_RESIZED_CROP_DEFAULT_PARAS["aspect_ratio"]
)

transform = Compose(
(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ def create_classification_model_from_ssl_checkpoint(
mlp: Optional[nn.Module] = None,
detach_backbone: bool = False,
) -> nn.Module:

"""
A utlity function for extracting the bacbone from the PyTorch Lightning's
SSL checkpoints. Used for supervided finetuning the SSL pre-trained models
Expand Down
8 changes: 6 additions & 2 deletions tests/test_accelerator_models_efficient_x3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ def test_create_x3d(self):
X3D-M: ("M", 16, 224)
X3D-L: ("L", 16, 312)
"""
for (expansion, input_clip_length, input_crop_size,) in [
for (
expansion,
input_clip_length,
input_crop_size,
) in [
("XS", 4, 160),
]:
model = create_x3d(expansion=expansion)
Expand Down Expand Up @@ -51,7 +55,7 @@ def test_load_hubconf(self):
os.path.dirname(os.path.realpath(__file__)),
"..",
)
for (input_clip_length, input_crop_size, model_name) in [
for input_clip_length, input_crop_size, model_name in [
(4, 160, "efficient_x3d_xs"),
(13, 160, "efficient_x3d_s"),
]:
Expand Down
5 changes: 4 additions & 1 deletion tests/test_data_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,10 @@ def _export_video_array(
):
with temp_encoded_video(
num_frames=num_frames, fps=fps, height=height, width=width
) as (video_file_name, data,), tempfile.TemporaryDirectory(
) as (
video_file_name,
data,
), tempfile.TemporaryDirectory(
prefix="video_stop_gap_test"
) as tempdir:
exported_video_path = os.path.join(tempdir, "video.mp4")
Expand Down
2 changes: 1 addition & 1 deletion tests/test_models_audio_visual_slowfast.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def test_create_avslowfast_with_callable(self):
"""
Test builder `create_audio_visual_slowfast` with callable inputs.
"""
for (norm, activation) in itertools.product(
for norm, activation in itertools.product(
(nn.BatchNorm3d, None), (nn.ReLU, nn.Sigmoid, None)
):
input_channel = 3
Expand Down
8 changes: 4 additions & 4 deletions tests/test_models_head.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def test_build_head_with_callable(self):
"""
Test builder `create_res_basic_head`.
"""
for (pool, activation) in itertools.product(
for pool, activation in itertools.product(
(nn.AvgPool3d, nn.MaxPool3d, nn.AdaptiveAvgPool3d, None),
(nn.ReLU, nn.Softmax, nn.Sigmoid, None),
):
Expand Down Expand Up @@ -266,7 +266,7 @@ def test_build_complex_head(self):
)

# Test forwarding.
for (input_tensor, bboxes) in TestRoIHeadHelper._get_inputs(
for input_tensor, bboxes in TestRoIHeadHelper._get_inputs(
input_dim=input_dim
):
if input_tensor.shape[1] != input_dim:
Expand Down Expand Up @@ -298,7 +298,7 @@ def test_build_head_with_callable(self):
resolution, spatial_scale=spatial_scale, sampling_ratio=sampling_ratio
)

for (pool, activation) in itertools.product(
for pool, activation in itertools.product(
(nn.AvgPool3d, nn.MaxPool3d, nn.AdaptiveAvgPool3d, None),
(nn.ReLU, nn.Softmax, nn.Sigmoid, None),
):
Expand Down Expand Up @@ -345,7 +345,7 @@ def test_build_head_with_callable(self):
) # explicitly use strict mode.

# Test forwarding.
for (input_tensor, bboxes) in TestRoIHeadHelper._get_inputs(input_dim=16):
for input_tensor, bboxes in TestRoIHeadHelper._get_inputs(input_dim=16):
with torch.no_grad():
if (
input_tensor.shape[1] != 16
Expand Down
Loading

0 comments on commit 1fadaef

Please sign in to comment.