Skip to content

Add CircleCI job for python lint #2056

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

Merged
merged 5 commits into from
Apr 3, 2020
Merged
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
13 changes: 13 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,17 @@ jobs:
python .circleci/regenerate.py
git diff --exit-code || (echo ".circleci/config.yml not in sync with config.yml.in! Run .circleci/regenerate.py to update config"; exit 1)


python_lint:
docker:
- image: circleci/python:3.7
steps:
- checkout
- run:
command: |
pip install --user --progress-bar off flake8 typing
flake8 .

binary_linux_wheel:
<<: *binary_common
docker:
Expand Down Expand Up @@ -509,6 +520,8 @@ workflows:
name: torchvision_win_py3.6_cu101
python_version: "3.6"
cu_version: "cu101"
- python_lint


nightly:
jobs:
Expand Down
13 changes: 13 additions & 0 deletions .circleci/config.yml.in
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,17 @@ jobs:
python .circleci/regenerate.py
git diff --exit-code || (echo ".circleci/config.yml not in sync with config.yml.in! Run .circleci/regenerate.py to update config"; exit 1)


python_lint:
docker:
- image: circleci/python:3.7
steps:
- checkout
- run:
command: |
pip install --user --progress-bar off flake8 typing
flake8 .

binary_linux_wheel:
<<: *binary_common
docker:
Expand Down Expand Up @@ -311,6 +322,8 @@ workflows:
name: torchvision_win_py3.6_cu101
python_version: "3.6"
cu_version: "cu101"
- python_lint


nightly:
{%- endif %}
Expand Down
5 changes: 0 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,6 @@ matrix:
before_install: skip
install: skip
script: ./travis-scripts/run-clang-format/run-clang-format.py -r torchvision/csrc
- env: LINT_CHECK
python: "3.6"
install: pip install flake8 typing
script: flake8 .circleci
after_success: []
- python: "3.6"
env: IMAGE_BACKEND=Pillow-SIMD
- python: "3.6"
Expand Down
7 changes: 4 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,9 @@ def get_extensions():
includes="torchvision/csrc/cuda/*",
show_detailed=True,
is_pytorch_extension=True,
)
)
source_cuda = glob.glob(os.path.join(extensions_dir, 'hip', '*.hip'))
## Copy over additional files
# Copy over additional files
shutil.copy("torchvision/csrc/cuda/cuda_helpers.h", "torchvision/csrc/hip/cuda_helpers.h")
shutil.copy("torchvision/csrc/cuda/vision_cuda.h", "torchvision/csrc/hip/vision_cuda.h")

Expand All @@ -122,7 +122,8 @@ def get_extensions():
define_macros = []

extra_compile_args = {}
if (torch.cuda.is_available() and ((CUDA_HOME is not None) or is_rocm_pytorch)) or os.getenv('FORCE_CUDA', '0') == '1':
if (torch.cuda.is_available() and ((CUDA_HOME is not None) or is_rocm_pytorch)) \
or os.getenv('FORCE_CUDA', '0') == '1':
extension = CUDAExtension
sources += source_cuda
if not is_rocm_pytorch:
Expand Down
5 changes: 3 additions & 2 deletions test/fakedata_generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,13 +253,14 @@ def _make_mat(file):

yield root


@contextlib.contextmanager
def voc_root():
with get_tmp_dir() as tmp_dir:
voc_dir = os.path.join(tmp_dir, 'VOCdevkit',
'VOC2012','ImageSets','Main')
'VOC2012', 'ImageSets', 'Main')
os.makedirs(voc_dir)
train_file = os.path.join(voc_dir,'train.txt')
train_file = os.path.join(voc_dir, 'train.txt')
with open(train_file, 'w') as f:
f.write('test')

Expand Down
5 changes: 3 additions & 2 deletions test/test_onnx.py
Original file line number Diff line number Diff line change
Expand Up @@ -415,13 +415,14 @@ def test_heatmaps_to_keypoints(self):

assert torch.all(out2[0].eq(out_trace2[0]))
assert torch.all(out2[1].eq(out_trace2[1]))

@unittest.skip("Disable test until export of interpolate script module to ONNX is fixed")
def test_keypoint_rcnn(self):
class KeyPointRCNN(torch.nn.Module):
def __init__(self):
super(KeyPointRCNN, self).__init__()
self.model = models.detection.keypoint_rcnn.keypointrcnn_resnet50_fpn(pretrained=True, min_size=200, max_size=300)
self.model = models.detection.keypoint_rcnn.keypointrcnn_resnet50_fpn(
pretrained=True, min_size=200, max_size=300)

def forward(self, images):
output = self.model(images)
Expand Down
3 changes: 1 addition & 2 deletions test/test_transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ def test_randomperspective_fill(self):
startpoints, endpoints = transforms.RandomPerspective.get_params(width, height, 0.5)
tr_img = F.perspective(img_conv, startpoints, endpoints, fill=fill)
pixel = tr_img.getpixel((0, 0))

if not isinstance(pixel, tuple):
pixel = (pixel,)
self.assertTupleEqual(pixel, tuple([fill] * num_bands))
Expand Down Expand Up @@ -896,7 +896,6 @@ def test_normalize_3d_tensor(self):
assert_array_almost_equal(target, result1.numpy())
assert_array_almost_equal(target, result2.numpy())


def test_adjust_brightness(self):
x_shape = [2, 2, 3]
x_data = [0, 5, 13, 54, 135, 226, 37, 8, 234, 90, 255, 1]
Expand Down
14 changes: 10 additions & 4 deletions torchvision/models/detection/transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,11 @@ def __repr__(self):

def resize_keypoints(keypoints, original_size, new_size):
# type: (Tensor, List[int], List[int])
ratios = [torch.tensor(s, dtype=torch.float32, device=keypoints.device) / torch.tensor(s_orig, dtype=torch.float32, device=keypoints.device)
for s, s_orig in zip(new_size, original_size)]
ratios = [
torch.tensor(s, dtype=torch.float32, device=keypoints.device) /
torch.tensor(s_orig, dtype=torch.float32, device=keypoints.device)
for s, s_orig in zip(new_size, original_size)
]
ratio_h, ratio_w = ratios
resized_data = keypoints.clone()
if torch._C._get_tracing_state():
Expand All @@ -208,8 +211,11 @@ def resize_keypoints(keypoints, original_size, new_size):

def resize_boxes(boxes, original_size, new_size):
# type: (Tensor, List[int], List[int])
ratios = [torch.tensor(s, dtype=torch.float32, device=boxes.device) / torch.tensor(s_orig, dtype=torch.float32, device=boxes.device)
for s, s_orig in zip(new_size, original_size)]
ratios = [
torch.tensor(s, dtype=torch.float32, device=boxes.device) /
torch.tensor(s_orig, dtype=torch.float32, device=boxes.device)
for s, s_orig in zip(new_size, original_size)
]
ratio_height, ratio_width = ratios
xmin, ymin, xmax, ymax = boxes.unbind(1)

Expand Down
2 changes: 1 addition & 1 deletion torchvision/ops/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def _check_size_scale_factor(dim, size, scale_factor):
raise ValueError("either size or scale_factor should be defined")
if size is not None and scale_factor is not None:
raise ValueError("only one of size or scale_factor should be defined")
if scale_factor is not None:
if scale_factor is not None:
if isinstance(scale_factor, (list, tuple)):
if len(scale_factor) != dim:
raise ValueError(
Expand Down
6 changes: 3 additions & 3 deletions torchvision/transforms/functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ def normalize(tensor, mean, std, inplace=False):
"""
if not torch.is_tensor(tensor):
raise TypeError('tensor should be a torch tensor. Got {}.'.format(type(tensor)))

if tensor.ndimension() != 3:
raise ValueError('Expected tensor to be a tensor image of size (C, H, W). Got tensor.size() = '
'{}.'.format(tensor.size()))
Expand Down Expand Up @@ -342,7 +342,7 @@ def pad(img, padding, fill=0, padding_mode='constant'):

def crop(img, top, left, height, width):
"""Crop the given PIL Image.

Args:
img (PIL Image): Image to be cropped. (0,0) denotes the top left corner of the image.
top (int): Vertical component of the top left corner of the crop box.
Expand Down Expand Up @@ -423,7 +423,7 @@ def _parse_fill(fill, img, min_pil_version):
image. If int or float, the value is used for all bands respectively.
Defaults to 0 for all bands.
img (PIL Image): Image to be filled.
min_pil_version (str): The minimum PILLOW version for when the ``fillcolor`` option
min_pil_version (str): The minimum PILLOW version for when the ``fillcolor`` option
was first introduced in the calling function. (e.g. rotate->5.2.0, perspective->5.0.0)

Returns:
Expand Down