Skip to content

upgrade linters #7680

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
12 changes: 6 additions & 6 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.0.1
rev: v4.4.0
hooks:
- id: check-docstring-first
- id: check-toml
Expand All @@ -13,20 +13,20 @@ repos:
- id: end-of-file-fixer

- repo: https://github.com/omnilib/ufmt
rev: v1.3.3
rev: v2.0.1
hooks:
- id: ufmt
additional_dependencies:
- black == 22.3.0
- usort == 1.0.2
- black == 22.12.0
- usort == 1.0.5

- repo: https://github.com/PyCQA/flake8
rev: 5.0.4
rev: 6.0.0
hooks:
- id: flake8
args: [--config=setup.cfg]

- repo: https://github.com/PyCQA/pydocstyle
rev: 6.1.1
rev: 6.3.0
hooks:
- id: pydocstyle
3 changes: 0 additions & 3 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,6 @@ def patched_make_field(self, types, domain, items, **kw):
# `kw` catches `env=None` needed for newer sphinx while maintaining
# backwards compatibility when passed along further down!

# type: (list, unicode, tuple) -> nodes.field # noqa: F821
def handle_item(fieldarg, content):
par = nodes.paragraph()
par += addnodes.literal_strong("", fieldarg) # Patch: this line added
Expand Down Expand Up @@ -321,7 +320,6 @@ def inject_weight_metadata(app, what, name, obj, options, lines):
"""

if obj.__name__.endswith(("_Weights", "_QuantizedWeights")):

if len(obj) == 0:
lines[:] = ["There are no available pre-trained weights."]
return
Expand Down Expand Up @@ -468,6 +466,5 @@ def generate_weights_table(module, table_name, metrics, dataset, include_pattern


def setup(app):

app.connect("autodoc-process-docstring", inject_minigalleries)
app.connect("autodoc-process-docstring", inject_weight_metadata)
1 change: 0 additions & 1 deletion references/depth/stereo/cascade_evaluation.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,6 @@ def evaluate(model, loader, args, writer=None, step=None):

for n_cascades in args.n_cascades:
for n_iters in args.n_iterations:

config = f"{n_cascades}c_{n_iters}i"
config_image_folder = os.path.join(base_image_folder, config)
os.makedirs(config_image_folder, exist_ok=True)
Expand Down
1 change: 0 additions & 1 deletion references/depth/stereo/presets.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ def __init__(
erase_px_range: Tuple[int, int] = (50, 100),
erase_num_repeats: int = 1,
) -> None:

if scaling_type not in ["linear", "exponential"]:
raise ValueError(f"Unknown scaling type: {scaling_type}. Available types: linear, exponential")

Expand Down
8 changes: 0 additions & 8 deletions references/depth/stereo/transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ def rand_float_range(size: Sequence[int], low: float, high: float) -> Tensor:


class InterpolationStrategy:

_valid_modes: List[str] = ["mixed", "bicubic", "bilinear"]

def __init__(self, mode: str = "mixed") -> None:
Expand Down Expand Up @@ -156,7 +155,6 @@ def forward(
disparities: Tuple[T_FLOW, T_FLOW],
masks: Tuple[T_MASK, T_MASK],
) -> Tuple[T_STEREO_TENSOR, Tuple[T_FLOW, T_FLOW], Tuple[T_MASK, T_MASK]]:

img_left = F.normalize(images[0], mean=self.mean, std=self.std)
img_right = F.normalize(images[1], mean=self.mean, std=self.std)

Expand Down Expand Up @@ -209,7 +207,6 @@ def forward(
disparities: Tuple[T_FLOW, T_FLOW],
masks: Tuple[T_MASK, T_MASK],
) -> Tuple[T_STEREO_TENSOR, Tuple[T_FLOW, T_FLOW], Tuple[T_MASK, T_MASK]]:

if torch.rand(1) < self.p:
# asymmetric: different transform for img1 and img2
img_left = super().forward(images[0])
Expand All @@ -236,7 +233,6 @@ def forward(
disparities: Tuple[T_FLOW, T_FLOW],
masks: Tuple[T_MASK, T_MASK],
) -> Tuple[T_STEREO_TENSOR, Tuple[T_FLOW, T_FLOW], Tuple[T_MASK, T_MASK]]:

gamma = rand_float_range((1,), low=self.gamma_range[0], high=self.gamma_range[1]).item()

if torch.rand(1) < self.p:
Expand Down Expand Up @@ -285,7 +281,6 @@ def forward(
disparities: T_STEREO_TENSOR,
masks: T_STEREO_TENSOR,
) -> Tuple[T_STEREO_TENSOR, Tuple[T_FLOW, T_FLOW], Tuple[T_MASK, T_MASK]]:

if torch.rand(1) < self.p:
return images, disparities, masks

Expand Down Expand Up @@ -342,7 +337,6 @@ def forward(
disparities: T_STEREO_TENSOR,
masks: T_STEREO_TENSOR,
) -> Tuple[T_STEREO_TENSOR, Tuple[T_FLOW, T_FLOW], Tuple[T_MASK, T_MASK]]:

left_image, right_image = images

if torch.rand(1) < self.p:
Expand Down Expand Up @@ -421,7 +415,6 @@ def forward(
disparities: Tuple[T_FLOW, T_FLOW],
masks: Tuple[T_MASK, T_MASK],
) -> Tuple[T_STEREO_TENSOR, Tuple[T_FLOW, T_FLOW], Tuple[T_MASK, T_MASK]]:

img_left, img_right = images
dsp_left, dsp_right = disparities
mask_left, mask_right = masks
Expand Down Expand Up @@ -522,7 +515,6 @@ def forward(
disparities: Tuple[T_FLOW, T_FLOW],
masks: Tuple[T_MASK, T_MASK],
) -> Tuple[T_STEREO_TENSOR, Tuple[T_FLOW, T_FLOW], Tuple[T_MASK, T_MASK]]:

img_left, img_right = images
dsp_left, dsp_right = disparities
mask_left, mask_right = masks
Expand Down
4 changes: 1 addition & 3 deletions references/detection/transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,7 @@ def __init__(
self.p = p

@torch.jit.unused
def _get_fill_value(self, is_pil):
# type: (bool) -> int
def _get_fill_value(self, is_pil: bool) -> int:
# We fake the type to make it work on JIT
return tuple(int(x) for x in self.fill) if is_pil else 0

Expand Down Expand Up @@ -447,7 +446,6 @@ def _copy_paste(
blending: bool = True,
resize_interpolation: F.InterpolationMode = F.InterpolationMode.BILINEAR,
) -> Tuple[torch.Tensor, Dict[str, Tensor]]:

# Random paste targets selection:
num_masks = len(paste_target["masks"])

Expand Down
1 change: 0 additions & 1 deletion references/optical_flow/train.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,6 @@ def preprocessing(img1, img2, flow, valid_flow_mask):
def train_one_epoch(model, optimizer, scheduler, train_loader, logger, args):
device = torch.device(args.device)
for data_blob in logger.log_every(train_loader):

optimizer.zero_grad()

image1, image2, flow_gt, valid_flow_mask = (x.to(device) for x in data_blob)
Expand Down
2 changes: 0 additions & 2 deletions references/optical_flow/transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
class ValidateModelInput(torch.nn.Module):
# Pass-through transform that checks the shape and dtypes to make sure the model gets what it expects
def forward(self, img1, img2, flow, valid_flow_mask):

if not all(isinstance(arg, torch.Tensor) for arg in (img1, img2, flow, valid_flow_mask) if arg is not None):
raise TypeError("This method expects all input arguments to be of type torch.Tensor.")
if not all(arg.dtype == torch.float32 for arg in (img1, img2, flow) if arg is not None):
Expand Down Expand Up @@ -90,7 +89,6 @@ def __init__(self, brightness=0, contrast=0, saturation=0, hue=0, p=0.2):
self.p = p

def forward(self, img1, img2, flow, valid_flow_mask):

if torch.rand(1) < self.p:
# asymmetric: different transform for img1 and img2
img1 = super().forward(img1)
Expand Down
1 change: 0 additions & 1 deletion references/optical_flow/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,6 @@ def log_every(self, iterable, print_freq=5, header=None):


def compute_metrics(flow_pred, flow_gt, valid_flow_mask=None):

epe = ((flow_pred - flow_gt) ** 2).sum(dim=1).sqrt()
flow_norm = (flow_gt**2).sum(dim=1).sqrt()

Expand Down
2 changes: 0 additions & 2 deletions test/test_datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,6 @@ class CityScapesTestCase(datasets_utils.ImageDatasetTestCase):
FEATURE_TYPES = (PIL.Image.Image, (dict, PIL.Image.Image))

def inject_fake_data(self, tmpdir, config):

tmpdir = pathlib.Path(tmpdir)

mode_to_splits = {
Expand Down Expand Up @@ -1948,7 +1947,6 @@ def inject_fake_data(self, tmpdir, config):

num_examples = 2 if config["split"] == "train" else 3
for split_dir in ("training", "testing"):

datasets_utils.create_image_folder(
root / split_dir,
name="image_2",
Expand Down
1 change: 0 additions & 1 deletion test/test_extended_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,6 @@ def test_naming_conventions(model_fn):
)
@run_if_test_with_extended
def test_schema_meta_validation(model_fn):

if model_fn.__name__ == "maskrcnn_resnet50_fpn_v2":
pytest.skip(reason="FIXME https://github.com/pytorch/vision/issues/7349")

Expand Down
10 changes: 0 additions & 10 deletions test/test_functional_tensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ def test_scale_channel():


class TestRotate:

ALL_DTYPES = [None, torch.float32, torch.float64, torch.float16]
scripted_rotate = torch.jit.script(F.rotate)
IMG_W = 26
Expand Down Expand Up @@ -153,7 +152,6 @@ def test_rotate_interpolation_type(self):


class TestAffine:

ALL_DTYPES = [None, torch.float32, torch.float64, torch.float16]
scripted_affine = torch.jit.script(F.affine)

Expand Down Expand Up @@ -379,7 +377,6 @@ def _get_data_dims_and_points_for_perspective():
@pytest.mark.parametrize("fill", (None, [0, 0, 0], [1, 2, 3], [255, 255, 255], [1], (2.0,)))
@pytest.mark.parametrize("fn", [F.perspective, torch.jit.script(F.perspective)])
def test_perspective_pil_vs_tensor(device, dims_and_points, dt, fill, fn):

if dt == torch.float16 and device == "cpu":
# skip float16 on CPU case
return
Expand Down Expand Up @@ -411,7 +408,6 @@ def test_perspective_pil_vs_tensor(device, dims_and_points, dt, fill, fn):
@pytest.mark.parametrize("dims_and_points", _get_data_dims_and_points_for_perspective())
@pytest.mark.parametrize("dt", [None, torch.float32, torch.float64, torch.float16])
def test_perspective_batch(device, dims_and_points, dt):

if dt == torch.float16 and device == "cpu":
# skip float16 on CPU case
return
Expand Down Expand Up @@ -451,7 +447,6 @@ def test_perspective_interpolation_type():
@pytest.mark.parametrize("max_size", [None, 34, 40, 1000])
@pytest.mark.parametrize("interpolation", [BILINEAR, BICUBIC, NEAREST, NEAREST_EXACT])
def test_resize(device, dt, size, max_size, interpolation):

if dt == torch.float16 and device == "cpu":
# skip float16 on CPU case
return
Expand Down Expand Up @@ -501,7 +496,6 @@ def test_resize(device, dt, size, max_size, interpolation):

@pytest.mark.parametrize("device", cpu_and_cuda())
def test_resize_asserts(device):

tensor, pil_img = _create_data(26, 36, device=device)

res1 = F.resize(tensor, size=32, interpolation=PIL.Image.BILINEAR)
Expand All @@ -521,7 +515,6 @@ def test_resize_asserts(device):
@pytest.mark.parametrize("size", [[96, 72], [96, 420], [420, 72]])
@pytest.mark.parametrize("interpolation", [BILINEAR, BICUBIC])
def test_resize_antialias(device, dt, size, interpolation):

if dt == torch.float16 and device == "cpu":
# skip float16 on CPU case
return
Expand Down Expand Up @@ -570,7 +563,6 @@ def test_resize_antialias(device, dt, size, interpolation):


def test_resize_antialias_default_warning():

img = torch.randint(0, 256, size=(3, 44, 56), dtype=torch.uint8)

match = "The default value of the antialias"
Expand All @@ -589,7 +581,6 @@ def test_resize_antialias_default_warning():
def check_functional_vs_PIL_vs_scripted(
fn, fn_pil, fn_t, config, device, dtype, channels=3, tol=2.0 + 1e-10, agg_method="max"
):

script_fn = torch.jit.script(fn)
torch.manual_seed(15)
tensor, pil_img = _create_data(26, 34, channels=channels, device=device)
Expand Down Expand Up @@ -1026,7 +1017,6 @@ def test_crop(device, top, left, height, width):
@pytest.mark.parametrize("sigma", [[0.5, 0.5], (0.5, 0.5), (0.8, 0.8), (1.7, 1.7)])
@pytest.mark.parametrize("fn", [F.gaussian_blur, torch.jit.script(F.gaussian_blur)])
def test_gaussian_blur(device, image_size, dt, ksize, sigma, fn):

# true_cv2_results = {
# # np_img = np.arange(3 * 10 * 12, dtype="uint8").reshape((10, 12, 3))
# # cv2.GaussianBlur(np_img, ksize=(3, 3), sigmaX=0.8)
Expand Down
3 changes: 0 additions & 3 deletions test/test_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ def normalize_dimensions(img_pil):
],
)
def test_decode_jpeg(img_path, pil_mode, mode):

with Image.open(img_path) as img:
is_cmyk = img.mode == "CMYK"
if pil_mode is not None:
Expand Down Expand Up @@ -152,7 +151,6 @@ def test_damaged_corrupt_images(img_path):
],
)
def test_decode_png(img_path, pil_mode, mode):

with Image.open(img_path) as img:
if pil_mode is not None:
img = img.convert(pil_mode)
Expand Down Expand Up @@ -402,7 +400,6 @@ def test_decode_jpeg_cuda_errors():


def test_encode_jpeg_errors():

with pytest.raises(RuntimeError, match="Input tensor dtype should be uint8"):
encode_jpeg(torch.empty((3, 100, 100), dtype=torch.float32))

Expand Down
3 changes: 0 additions & 3 deletions test/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -634,7 +634,6 @@ def checkOut(out):


def test_generalizedrcnn_transform_repr():

min_size, max_size = 224, 299
image_mean = [0.485, 0.456, 0.406]
image_std = [0.229, 0.224, 0.225]
Expand Down Expand Up @@ -1033,7 +1032,6 @@ def test_detection_model_trainable_backbone_layers(model_fn, disable_weight_load
@pytest.mark.parametrize("model_fn", list_model_fns(models.optical_flow))
@pytest.mark.parametrize("scripted", (False, True))
def test_raft(model_fn, scripted):

torch.manual_seed(0)

# We need very small images, otherwise the pickle size would exceed the 50KB
Expand All @@ -1058,7 +1056,6 @@ def test_raft(model_fn, scripted):


def test_presets_antialias():

img = torch.randint(0, 256, size=(1, 3, 224, 224), dtype=torch.uint8)

match = "The default value of the antialias parameter"
Expand Down
1 change: 0 additions & 1 deletion test/test_models_detection_negative_samples.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ def test_targets_to_anchors(self):
assert matched_gt_boxes[0].dtype == torch.float32

def test_assign_targets_to_proposals(self):

proposals = [torch.randint(-50, 50, (20, 4), dtype=torch.float32)]
gt_boxes = [torch.zeros((0, 4), dtype=torch.float32)]
gt_labels = [torch.tensor([[0]], dtype=torch.int64)]
Expand Down
1 change: 0 additions & 1 deletion test/test_onnx.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ def run_model(
self.ort_validate(onnx_io, test_inputs, test_ouputs)

def ort_validate(self, onnx_io, inputs, outputs):

inputs, _ = torch.jit._flatten(inputs)
outputs, _ = torch.jit._flatten(outputs)

Expand Down
2 changes: 1 addition & 1 deletion test/test_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from abc import ABC, abstractmethod
from functools import lru_cache
from itertools import product
from typing import Callable, List, Tuple
from typing import Callable, List

import numpy as np
import pytest
Expand Down
Loading