From d0b6dceefaa56bbc9064bca524255237890c5e03 Mon Sep 17 00:00:00 2001 From: Jan Gutsche Date: Wed, 29 Dec 2021 19:04:52 +0100 Subject: [PATCH 1/2] Add flake8 linter as dev dependency --- poetry.lock | 78 +++++++++++++++++++++++++++++++++++++++++--------- pyproject.toml | 3 +- 2 files changed, 66 insertions(+), 15 deletions(-) diff --git a/poetry.lock b/poetry.lock index 4fbd22e31a..a21df867a4 100644 --- a/poetry.lock +++ b/poetry.lock @@ -68,6 +68,20 @@ category = "main" optional = false python-versions = ">=2.6, !=3.0.*, !=3.1.*" +[[package]] +name = "flake8" +version = "4.0.1" +description = "the modular source code checker: pep8 pyflakes and co" +category = "dev" +optional = false +python-versions = ">=3.6" + +[package.dependencies] +importlib-metadata = {version = "<4.3", markers = "python_version < \"3.8\""} +mccabe = ">=0.6.0,<0.7.0" +pycodestyle = ">=2.8.0,<2.9.0" +pyflakes = ">=2.4.0,<2.5.0" + [[package]] name = "google-auth" version = "2.3.3" @@ -170,9 +184,9 @@ six = "*" [[package]] name = "importlib-metadata" -version = "4.8.2" +version = "4.2.0" description = "Read metadata from Python packages" -category = "main" +category = "dev" optional = false python-versions = ">=3.6" @@ -182,8 +196,7 @@ zipp = ">=0.5" [package.extras] docs = ["sphinx", "jaraco.packaging (>=8.2)", "rst.linker (>=1.9)"] -perf = ["ipython"] -testing = ["pytest (>=6)", "pytest-checkdocs (>=2.4)", "pytest-flake8", "pytest-cov", "pytest-enabler (>=1.0.1)", "packaging", "pep517", "pyfakefs", "flufl.flake8", "pytest-perf (>=0.9.2)", "pytest-black (>=0.3.7)", "pytest-mypy", "importlib-resources (>=1.3)"] +testing = ["pytest (>=4.6)", "pytest-checkdocs (>=2.4)", "pytest-flake8", "pytest-cov", "pytest-enabler (>=1.0.1)", "packaging", "pep517", "pyfakefs", "flufl.flake8", "pytest-black (>=0.3.7)", "pytest-mypy", "importlib-resources (>=1.3)"] [[package]] name = "kiwisolver" @@ -195,15 +208,12 @@ python-versions = ">=3.6" [[package]] name = "markdown" -version = "3.3.6" +version = "3.3.5" description = "Python implementation of Markdown." category = "main" optional = false python-versions = ">=3.6" -[package.dependencies] -importlib-metadata = {version = ">=4.4", markers = "python_version < \"3.10\""} - [package.extras] testing = ["coverage", "pyyaml"] @@ -223,6 +233,14 @@ pillow = ">=6.2.0" pyparsing = ">=2.0.3,<2.0.4 || >2.0.4,<2.1.2 || >2.1.2,<2.1.6 || >2.1.6" python-dateutil = ">=2.1" +[[package]] +name = "mccabe" +version = "0.6.1" +description = "McCabe checker, plugin for flake8" +category = "dev" +optional = false +python-versions = "*" + [[package]] name = "networkx" version = "2.5.1" @@ -322,6 +340,22 @@ python-versions = "*" [package.dependencies] pyasn1 = ">=0.4.6,<0.5.0" +[[package]] +name = "pycodestyle" +version = "2.8.0" +description = "Python style guide checker" +category = "dev" +optional = false +python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*" + +[[package]] +name = "pyflakes" +version = "2.4.0" +description = "passive checker of Python programs" +category = "dev" +optional = false +python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*" + [[package]] name = "pyparsing" version = "3.0.6" @@ -603,7 +637,7 @@ watchdog = ["watchdog"] name = "zipp" version = "3.6.0" description = "Backport of pathlib-compatible object wrapper for zip files" -category = "main" +category = "dev" optional = false python-versions = ">=3.6" @@ -614,7 +648,7 @@ testing = ["pytest (>=4.6)", "pytest-checkdocs (>=2.4)", "pytest-flake8", "pytes [metadata] lock-version = "1.1" python-versions = ">=3.6.2" -content-hash = "f4ec2f40adb919ec07e6de39051a70ca5826ee8ee596d805412f2ccb6dcf0ceb" +content-hash = "6b86d5042d088471a4e607f32f9a3384c69ad08ed506dc4a609b8432ccab975c" [metadata.files] absl-py = [ @@ -649,6 +683,10 @@ decorator = [ {file = "decorator-4.4.2-py2.py3-none-any.whl", hash = "sha256:41fa54c2a0cc4ba648be4fd43cff00aedf5b9465c9bf18d64325bc225f08f760"}, {file = "decorator-4.4.2.tar.gz", hash = "sha256:e3a62f0520172440ca0dcc823749319382e377f37f140a0b99ef45fecb84bfe7"}, ] +flake8 = [ + {file = "flake8-4.0.1-py2.py3-none-any.whl", hash = "sha256:479b1304f72536a55948cb40a32dce8bb0ffe3501e26eaf292c7e60eb5e0428d"}, + {file = "flake8-4.0.1.tar.gz", hash = "sha256:806e034dda44114815e23c16ef92f95c91e4c71100ff52813adf7132a6ad870d"}, +] google-auth = [ {file = "google-auth-2.3.3.tar.gz", hash = "sha256:d83570a664c10b97a1dc6f8df87e5fdfff012f48f62be131e449c20dfc32630e"}, {file = "google_auth-2.3.3-py2.py3-none-any.whl", hash = "sha256:a348a50b027679cb7dae98043ac8dbcc1d7951f06d8387496071a1e05a2465c0"}, @@ -716,8 +754,8 @@ imgaug = [ {file = "imgaug-0.4.0.tar.gz", hash = "sha256:46bab63ed38f8980630ff721a09ca2281b7dbd4d8c11258818b6ebcc69ea46c7"}, ] importlib-metadata = [ - {file = "importlib_metadata-4.8.2-py3-none-any.whl", hash = "sha256:53ccfd5c134223e497627b9815d5030edf77d2ed573922f7a0b8f8bb81a1c100"}, - {file = "importlib_metadata-4.8.2.tar.gz", hash = "sha256:75bdec14c397f528724c1bfd9709d660b33a4d2e77387a3358f20b848bb5e5fb"}, + {file = "importlib_metadata-4.2.0-py3-none-any.whl", hash = "sha256:057e92c15bc8d9e8109738a48db0ccb31b4d9d5cfbee5a8670879a30be66304b"}, + {file = "importlib_metadata-4.2.0.tar.gz", hash = "sha256:b7e52a1f8dec14a75ea73e0891f3060099ca1d8e6a462a4dff11c3e119ea1b31"}, ] kiwisolver = [ {file = "kiwisolver-1.3.1-cp36-cp36m-macosx_10_9_x86_64.whl", hash = "sha256:fd34fbbfbc40628200730bc1febe30631347103fc8d3d4fa012c21ab9c11eca9"}, @@ -759,8 +797,8 @@ kiwisolver = [ {file = "kiwisolver-1.3.1.tar.gz", hash = "sha256:950a199911a8d94683a6b10321f9345d5a3a8433ec58b217ace979e18f16e248"}, ] markdown = [ - {file = "Markdown-3.3.6-py3-none-any.whl", hash = "sha256:9923332318f843411e9932237530df53162e29dc7a4e2b91e35764583c46c9a3"}, - {file = "Markdown-3.3.6.tar.gz", hash = "sha256:76df8ae32294ec39dcf89340382882dfa12975f87f45c3ed1ecdb1e8cefc7006"}, + {file = "Markdown-3.3.5-py3-none-any.whl", hash = "sha256:0d2d09f75cb8d1ffc6770c65c61770b23a61708101f47bda416a002a0edbc480"}, + {file = "Markdown-3.3.5.tar.gz", hash = "sha256:26e9546bfbcde5fcd072bd8f612c9c1b6e2677cb8aadbdf65206674f46dde069"}, ] matplotlib = [ {file = "matplotlib-3.3.4-cp36-cp36m-macosx_10_9_x86_64.whl", hash = "sha256:672960dd114e342b7c610bf32fb99d14227f29919894388b41553217457ba7ef"}, @@ -789,6 +827,10 @@ matplotlib = [ {file = "matplotlib-3.3.4-pp37-pypy37_pp73-manylinux2010_x86_64.whl", hash = "sha256:cf3a7e54eff792f0815dbbe9b85df2f13d739289c93d346925554f71d484be78"}, {file = "matplotlib-3.3.4.tar.gz", hash = "sha256:3e477db76c22929e4c6876c44f88d790aacdf3c3f8f3a90cb1975c0bf37825b0"}, ] +mccabe = [ + {file = "mccabe-0.6.1-py2.py3-none-any.whl", hash = "sha256:ab8a6258860da4b6677da4bd2fe5dc2c659cff31b3ee4f7f5d64e79735b80d42"}, + {file = "mccabe-0.6.1.tar.gz", hash = "sha256:dd8d182285a0fe56bace7f45b5e7d1a6ebcbf524e8f3bd87eb0f125271b8831f"}, +] networkx = [ {file = "networkx-2.5.1-py3-none-any.whl", hash = "sha256:0635858ed7e989f4c574c2328380b452df892ae85084144c73d8cd819f0c4e06"}, {file = "networkx-2.5.1.tar.gz", hash = "sha256:109cd585cac41297f71103c3c42ac6ef7379f29788eb54cb751be5a663bb235a"}, @@ -958,6 +1000,14 @@ pyasn1-modules = [ {file = "pyasn1_modules-0.2.8-py3.6.egg", hash = "sha256:cbac4bc38d117f2a49aeedec4407d23e8866ea4ac27ff2cf7fb3e5b570df19e0"}, {file = "pyasn1_modules-0.2.8-py3.7.egg", hash = "sha256:c29a5e5cc7a3f05926aff34e097e84f8589cd790ce0ed41b67aed6857b26aafd"}, ] +pycodestyle = [ + {file = "pycodestyle-2.8.0-py2.py3-none-any.whl", hash = "sha256:720f8b39dde8b293825e7ff02c475f3077124006db4f440dcbc9a20b76548a20"}, + {file = "pycodestyle-2.8.0.tar.gz", hash = "sha256:eddd5847ef438ea1c7870ca7eb78a9d47ce0cdb4851a5523949f2601d0cbbe7f"}, +] +pyflakes = [ + {file = "pyflakes-2.4.0-py2.py3-none-any.whl", hash = "sha256:3bb3a3f256f4b7968c9c788781e4ff07dce46bdf12339dcda61053375426ee2e"}, + {file = "pyflakes-2.4.0.tar.gz", hash = "sha256:05a85c2872edf37a4ed30b0cce2f6093e1d0581f8c19d7393122da7e25b2b24c"}, +] pyparsing = [ {file = "pyparsing-3.0.6-py3-none-any.whl", hash = "sha256:04ff808a5b90911829c55c4e26f75fa5ca8a2f5f36aa3a51f68e27033341d3e4"}, {file = "pyparsing-3.0.6.tar.gz", hash = "sha256:d9bdec0013ef1eb5a84ab39a3b3868911598afa494f5faa038647101504e2b81"}, diff --git a/pyproject.toml b/pyproject.toml index 394fc794fd..d543503217 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "PyTorchYolo" -version = "1.6.2" +version = "1.6.3" readme = "README.md" repository = "https://github.com/eriklindernoren/PyTorch-YOLOv3" description = "Minimal PyTorch implementation of YOLO" @@ -22,6 +22,7 @@ torchsummary = "^1.5.1" [tool.poetry.dev-dependencies] profilehooks = "^1.12.0" +flake8 = "^4.0.1" [build-system] requires = ["poetry-core>=1.0.0"] From c02ae7e3866c56e2d63035fa42758eeae4ea17fe Mon Sep 17 00:00:00 2001 From: Jan Gutsche Date: Wed, 29 Dec 2021 19:05:05 +0100 Subject: [PATCH 2/2] Resolve linter warnings --- pytorchyolo/models.py | 6 ++++-- pytorchyolo/test.py | 2 +- pytorchyolo/train.py | 2 +- pytorchyolo/utils/loss.py | 2 +- pytorchyolo/utils/utils.py | 4 +++- 5 files changed, 10 insertions(+), 6 deletions(-) diff --git a/pytorchyolo/models.py b/pytorchyolo/models.py index 1eca59f637..092597ffb3 100644 --- a/pytorchyolo/models.py +++ b/pytorchyolo/models.py @@ -114,6 +114,7 @@ def forward(self, x): x = F.interpolate(x, scale_factor=self.scale_factor, mode=self.mode) return x + class Mish(nn.Module): """ The MISH activation function (https://github.com/digantamisra98/Mish) """ @@ -123,6 +124,7 @@ def __init__(self): def forward(self, x): return x * torch.tanh(F.softplus(x)) + class YOLOLayer(nn.Module): """Detection layer""" @@ -152,7 +154,7 @@ def forward(self, x, img_size): self.grid = self._make_grid(nx, ny).to(x.device) x[..., 0:2] = (x[..., 0:2].sigmoid() + self.grid) * stride # xy - x[..., 2:4] = torch.exp(x[..., 2:4]) * self.anchor_grid # wh + x[..., 2:4] = torch.exp(x[..., 2:4]) * self.anchor_grid # wh x[..., 4:] = x[..., 4:].sigmoid() x = x.view(bs, -1, self.no) @@ -186,7 +188,7 @@ def forward(self, x): combined_outputs = torch.cat([layer_outputs[int(layer_i)] for layer_i in module_def["layers"].split(",")], 1) group_size = combined_outputs.shape[1] // int(module_def.get("groups", 1)) group_id = int(module_def.get("group_id", 0)) - x = combined_outputs[:, group_size * group_id : group_size * (group_id + 1)] # Slice groupings used by yolo v4 + x = combined_outputs[:, group_size * group_id:group_size * (group_id + 1)] # Slice groupings used by yolo v4 elif module_def["type"] == "shortcut": layer_i = int(module_def["from"]) x = layer_outputs[-1] + layer_outputs[layer_i] diff --git a/pytorchyolo/test.py b/pytorchyolo/test.py index f0bc7439af..9737baf8e4 100755 --- a/pytorchyolo/test.py +++ b/pytorchyolo/test.py @@ -13,7 +13,7 @@ from torch.autograd import Variable from pytorchyolo.models import load_model -from pytorchyolo.utils.utils import load_classes, ap_per_class, get_batch_statistics, non_max_suppression, to_cpu, xywh2xyxy, print_environment_info +from pytorchyolo.utils.utils import load_classes, ap_per_class, get_batch_statistics, non_max_suppression, xywh2xyxy, print_environment_info from pytorchyolo.utils.datasets import ListDataset from pytorchyolo.utils.transforms import DEFAULT_TRANSFORMS from pytorchyolo.utils.parse_config import parse_data_config diff --git a/pytorchyolo/train.py b/pytorchyolo/train.py index 2a1ae02549..a4aab979b0 100755 --- a/pytorchyolo/train.py +++ b/pytorchyolo/train.py @@ -15,7 +15,7 @@ from pytorchyolo.utils.utils import to_cpu, load_classes, print_environment_info, provide_determinism, worker_seed_set from pytorchyolo.utils.datasets import ListDataset from pytorchyolo.utils.augmentations import AUGMENTATION_TRANSFORMS -#from pytorchyolo.utils.transforms import DEFAULT_TRANSFORMS +# from pytorchyolo.utils.transforms import DEFAULT_TRANSFORMS from pytorchyolo.utils.parse_config import parse_data_config from pytorchyolo.utils.loss import compute_loss from pytorchyolo.test import _evaluate, _create_validation_data_loader diff --git a/pytorchyolo/utils/loss.py b/pytorchyolo/utils/loss.py index 1f1d259c33..ba0dfee652 100644 --- a/pytorchyolo/utils/loss.py +++ b/pytorchyolo/utils/loss.py @@ -113,7 +113,7 @@ def compute_loss(predictions, targets, model): # Classification of the objectness the sequel # Calculate the BCE loss between the on the fly generated target and the network prediction - lobj += BCEobj(layer_predictions[..., 4], tobj) # obj loss + lobj += BCEobj(layer_predictions[..., 4], tobj) # obj loss lbox *= 0.05 lobj *= 1.0 diff --git a/pytorchyolo/utils/utils.py b/pytorchyolo/utils/utils.py index bce7a900b8..f39dad00dd 100644 --- a/pytorchyolo/utils/utils.py +++ b/pytorchyolo/utils/utils.py @@ -20,6 +20,7 @@ def provide_determinism(seed=42): torch.backends.cudnn.benchmark = False torch.backends.cudnn.deterministic = True + def worker_seed_set(worker_id): # See for details of numpy: # https://github.com/pytorch/pytorch/issues/5059#issuecomment-817392562 @@ -390,6 +391,7 @@ def print_environment_info(): # Print commit hash if possible try: - print(f"Current Commit Hash: {subprocess.check_output(['git', 'rev-parse', '--short', 'HEAD'], stderr=subprocess.DEVNULL).decode('ascii').strip()}") + commit_hash = subprocess.check_output(['git', 'rev-parse', '--short', 'HEAD'], stderr=subprocess.DEVNULL).decode('ascii').strip() + print(f"Current Commit Hash: {commit_hash}") except (subprocess.CalledProcessError, FileNotFoundError): print("No git or repo found")