Skip to content

Commit 1f6d7d9

Browse files
committed
lint
1 parent 8882898 commit 1f6d7d9

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

benchmarks/benchmark_transforms.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,15 @@
1010
"""
1111

1212
import argparse
13-
import torch
1413
import random
1514
import warnings
16-
from typing import Dict, Any
17-
import torchvision.transforms.v2.functional as F
18-
import torchvision.transforms.functional as Fv1
15+
from typing import Any, Dict
16+
1917
import numpy as np
20-
from utils import bench, report_stats, print_comparison_table, print_benchmark_info
18+
import torch
19+
import torchvision.transforms.functional as Fv1
20+
import torchvision.transforms.v2.functional as F
21+
from utils import bench, print_benchmark_info, print_comparison_table, report_stats
2122

2223
# Filter out the specific TF32 warning
2324
warnings.filterwarnings(
@@ -64,8 +65,9 @@ def torchvision_pipeline(images: torch.Tensor, target_size: int) -> torch.Tensor
6465
images = F.normalize(images, mean=NORM_MEAN, std=NORM_STD)
6566
return images
6667

68+
6769
def torchvision_v1_pipeline(images: torch.Tensor, target_size: int) -> torch.Tensor:
68-
images = images.float() / 255. # rough equivalent of to_tensor()
70+
images = images.float() / 255.0 # rough equivalent of to_tensor()
6971
images = Fv1.resize(
7072
images, size=(target_size, target_size), interpolation=Fv1.InterpolationMode.BILINEAR, antialias=True
7173
)
@@ -243,7 +245,10 @@ def main():
243245
)
244246
all_backends = ["tv", "tv-v1", "tv-compiled", "opencv", "pil", "albumentations", "kornia"]
245247
parser.add_argument(
246-
"--backends", type=str, default="all", help="Backends to benchmark (comma-separated list or 'all'). First backend is used as reference for comparison."
248+
"--backends",
249+
type=str,
250+
default="all",
251+
help="Backends to benchmark (comma-separated list or 'all'). First backend is used as reference for comparison.",
247252
)
248253
parser.add_argument("-v", "--verbose", action="store_true", help="Enable verbose output")
249254
parser.add_argument("--device", type=str, default="cpu", help="Device to use: cpu or cuda (default: cpu)")

benchmarks/utils.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22
Utility functions for benchmarking transforms.
33
"""
44

5+
from time import perf_counter_ns
6+
from typing import Any, Callable, Dict, List
7+
58
import torch
69
import torchvision
7-
from time import perf_counter_ns
8-
from typing import Callable, List, Dict, Any
910
from tabulate import tabulate
1011

1112
try:
@@ -133,7 +134,7 @@ def print_benchmark_info(args):
133134
["PyTorch", torch.__version__],
134135
["TorchVision", torchvision.__version__],
135136
["OpenCV", cv2.__version__ if HAS_OPENCV else "Not available"],
136-
["PIL/Pillow", getattr(Image, '__version__', "Version unavailable")],
137+
["PIL/Pillow", getattr(Image, "__version__", "Version unavailable")],
137138
["Albumentations", A.__version__ if HAS_ALBUMENTATIONS else "Not available"],
138139
["Kornia", K.__version__ if HAS_KORNIA else "Not available"],
139140
]

0 commit comments

Comments
 (0)