Commit 8f943d4e authored by Kyryl Truskovskyi's avatar Kyryl Truskovskyi Committed by Soumith Chintala
Browse files

Fix Unused Variables and flake8 config (#635)

* cast mnist targer to int

* fix unused variables

* fix syntax in tests

* remove # noqa; rename l variable to line_split; use except OSError

* add W504

* add W504

* add W503,W504 tox.ini
parent b0acd55c
...@@ -9,5 +9,5 @@ max-line-length = 120 ...@@ -9,5 +9,5 @@ max-line-length = 120
[flake8] [flake8]
max-line-length = 120 max-line-length = 120
ignore = F401,E402,F403 ignore = F401,E402,F403,W503,W504
exclude = venv exclude = venv
...@@ -2,7 +2,6 @@ ...@@ -2,7 +2,6 @@
import os import os
import io import io
import re import re
import shutil
import sys import sys
from setuptools import setup, find_packages from setuptools import setup, find_packages
from pkg_resources import get_distribution, DistributionNotFound from pkg_resources import get_distribution, DistributionNotFound
......
...@@ -65,5 +65,6 @@ class Tester(unittest.TestCase): ...@@ -65,5 +65,6 @@ class Tester(unittest.TestCase):
[class_b_idx] * len(Tester.class_b_images)) [class_b_idx] * len(Tester.class_b_images))
self.assertEqual(targets, sorted(args)) self.assertEqual(targets, sorted(args))
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()
...@@ -284,6 +284,5 @@ def read_image_file(path): ...@@ -284,6 +284,5 @@ def read_image_file(path):
length = get_int(data[4:8]) length = get_int(data[4:8])
num_rows = get_int(data[8:12]) num_rows = get_int(data[8:12])
num_cols = get_int(data[12:16]) num_cols = get_int(data[12:16])
images = []
parsed = np.frombuffer(data, dtype=np.uint8, offset=16) parsed = np.frombuffer(data, dtype=np.uint8, offset=16)
return torch.from_numpy(parsed).view(length, num_rows, num_cols) return torch.from_numpy(parsed).view(length, num_rows, num_cols)
import os import os
import errno
import numpy as np import numpy as np
from PIL import Image from PIL import Image
import torch import torch
import torch.utils.data as data import torch.utils.data as data
from .utils import download_url, check_integrity from .utils import download_url
class PhotoTour(data.Dataset): class PhotoTour(data.Dataset):
...@@ -211,6 +210,6 @@ def read_matches_files(data_dir, matches_file): ...@@ -211,6 +210,6 @@ def read_matches_files(data_dir, matches_file):
matches = [] matches = []
with open(os.path.join(data_dir, matches_file), 'r') as f: with open(os.path.join(data_dir, matches_file), 'r') as f:
for line in f: for line in f:
l = line.split() line_split = line.split()
matches.append([int(l[0]), int(l[3]), int(l[1] == l[4])]) matches.append([int(line_split[0]), int(line_split[3]), int(line_split[1] == line_split[4])])
return torch.LongTensor(matches) return torch.LongTensor(matches)
...@@ -2,14 +2,7 @@ from __future__ import print_function ...@@ -2,14 +2,7 @@ from __future__ import print_function
from PIL import Image from PIL import Image
import os import os
import os.path import os.path
import errno
import numpy as np import numpy as np
import sys
if sys.version_info[0] == 2:
import cPickle as pickle
else:
import pickle
import torch.utils.data as data import torch.utils.data as data
from .utils import download_url, check_integrity from .utils import download_url, check_integrity
......
from __future__ import print_function from __future__ import print_function
import torch.utils.data as data
from PIL import Image from PIL import Image
import os import os
import os.path import os.path
import errno
import numpy as np import numpy as np
import sys
from .cifar import CIFAR10 from .cifar import CIFAR10
......
...@@ -62,7 +62,7 @@ def download_url(url, root, filename, md5): ...@@ -62,7 +62,7 @@ def download_url(url, root, filename, md5):
url, fpath, url, fpath,
reporthook=gen_bar_updater(tqdm(unit='B', unit_scale=True)) reporthook=gen_bar_updater(tqdm(unit='B', unit_scale=True))
) )
except: except OSError:
if url[:5] == 'https': if url[:5] == 'https':
url = url.replace('https:', 'http:') url = url.replace('https:', 'http:')
print('Failed download. Trying https -> http instead.' print('Failed download. Trying https -> http instead.'
......
import math
import torch import torch
import torch.nn as nn import torch.nn as nn
import torch.nn.init as init import torch.nn.init as init
......
import torch.nn as nn import torch.nn as nn
import torch.utils.model_zoo as model_zoo import torch.utils.model_zoo as model_zoo
import math
__all__ = [ __all__ = [
......
...@@ -2,7 +2,6 @@ from __future__ import division ...@@ -2,7 +2,6 @@ from __future__ import division
import torch import torch
import sys import sys
import math import math
import random
from PIL import Image, ImageOps, ImageEnhance, PILLOW_VERSION from PIL import Image, ImageOps, ImageEnhance, PILLOW_VERSION
try: try:
import accimage import accimage
...@@ -10,7 +9,6 @@ except ImportError: ...@@ -10,7 +9,6 @@ except ImportError:
accimage = None accimage = None
import numpy as np import numpy as np
import numbers import numbers
import types
import collections import collections
import warnings import warnings
......
...@@ -3,7 +3,7 @@ import torch ...@@ -3,7 +3,7 @@ import torch
import math import math
import sys import sys
import random import random
from PIL import Image, ImageOps, ImageEnhance from PIL import Image
try: try:
import accimage import accimage
except ImportError: except ImportError:
......
[flake8] [flake8]
max-line-length = 120 max-line-length = 120
ignore = E305,E402,E721,E722,E741,F401,F403,F405,F821,F841,F999 ignore = F401,E402,F403,W503,W504
exclude = docs/src exclude = docs/src
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment