diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 3c5081e709dc..192a0ff3cba2 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -16,7 +16,7 @@ repos: - id: end-of-file-fixer - id: trailing-whitespace - id: check-case-conflict - - id: check-yaml + # - id: check-yaml - id: check-docstring-first - id: double-quote-string-fixer - id: detect-private-key @@ -26,7 +26,6 @@ repos: hooks: - id: pyupgrade name: Upgrade code - args: [--py37-plus] - repo: https://github.com/PyCQA/isort rev: 5.12.0 @@ -63,7 +62,12 @@ repos: args: - --ignore-words-list=crate,nd,strack,dota - #- repo: https://github.com/asottile/yesqa - # rev: v1.4.0 - # hooks: - # - id: yesqa +# - repo: https://github.com/asottile/yesqa +# rev: v1.4.0 +# hooks: +# - id: yesqa + +# - repo: https://github.com/asottile/dead +# rev: v1.5.0 +# hooks: +# - id: dead diff --git a/export.py b/export.py index 9399f0bbd221..5755774d2f54 100644 --- a/export.py +++ b/export.py @@ -110,7 +110,7 @@ def export_formats(): ['TensorFlow Lite', 'tflite', '.tflite', True, False], ['TensorFlow Edge TPU', 'edgetpu', '_edgetpu.tflite', False, False], ['TensorFlow.js', 'tfjs', '_web_model', False, False], - ['PaddlePaddle', 'paddle', '_paddle_model', True, True],] + ['PaddlePaddle', 'paddle', '_paddle_model', True, True], ] return pd.DataFrame(x, columns=['Format', 'Argument', 'Suffix', 'CPU', 'GPU']) @@ -221,7 +221,7 @@ def export_openvino(file, metadata, half, int8, data, prefix=colorstr('OpenVINO: import numpy as np from openvino.runtime import Core - from utils.dataloaders import create_dataloader, letterbox + from utils.dataloaders import create_dataloader core = Core() onnx_model = core.read_model(f_onnx) # export @@ -501,7 +501,7 @@ def export_edgetpu(file, prefix=colorstr('Edge TPU:')): '10', '--out_dir', str(file.parent), - f_tfl,], check=True) + f_tfl, ], check=True) return f, None @@ -522,7 +522,7 @@ def export_tfjs(file, int8, prefix=colorstr('TensorFlow.js:')): '--quantize_uint8' if int8 else '', '--output_node_names=Identity,Identity_1,Identity_2,Identity_3', str(f_pb), - str(f),] + str(f), ] subprocess.run([arg for arg in args if arg], check=True) json = Path(f_json).read_text() diff --git a/models/tf.py b/models/tf.py index bc0a465d7edd..62ba3ebf0782 100644 --- a/models/tf.py +++ b/models/tf.py @@ -310,7 +310,7 @@ def call(self, inputs): y = tf.concat([xy, wh, tf.sigmoid(y[..., 4:5 + self.nc]), y[..., 5 + self.nc:]], -1) z.append(tf.reshape(y, [-1, self.na * ny * nx, self.no])) - return tf.transpose(x, [0, 2, 1, 3]) if self.training else (tf.concat(z, 1),) + return tf.transpose(x, [0, 2, 1, 3]) if self.training else (tf.concat(z, 1), ) @staticmethod def _make_grid(nx=20, ny=20): @@ -486,7 +486,7 @@ def predict(self, iou_thres, conf_thres, clip_boxes=False) - return (nms,) + return (nms, ) return x # output [1,6300,85] = [xywh, conf, class0, class1, ...] # x = x[0] # [x(1,6300,85), ...] to x(6300,85) # xywh = x[..., :4] # x(6300,4) boxes diff --git a/models/yolo.py b/models/yolo.py index 18d2542bfb48..4f4d567bec73 100644 --- a/models/yolo.py +++ b/models/yolo.py @@ -21,8 +21,8 @@ if platform.system() != 'Windows': ROOT = Path(os.path.relpath(ROOT, Path.cwd())) # relative -from models.common import * -from models.experimental import * +from models.common import * # noqa +from models.experimental import * # noqa from utils.autoanchor import check_anchor_order from utils.general import LOGGER, check_version, check_yaml, make_divisible, print_args from utils.plots import feature_visualization @@ -76,7 +76,7 @@ def forward(self, x): y = torch.cat((xy, wh, conf), 4) z.append(y.view(bs, self.na * nx * ny, self.no)) - return x if self.training else (torch.cat(z, 1),) if self.export else (torch.cat(z, 1), x) + return x if self.training else (torch.cat(z, 1), ) if self.export else (torch.cat(z, 1), x) def _make_grid(self, nx=20, ny=20, i=0, torch_1_10=check_version(torch.__version__, '1.10.0')): d = self.anchors[i].device @@ -126,7 +126,7 @@ def _forward_once(self, x, profile=False, visualize=False): def _profile_one_layer(self, m, x, dt): c = m == self.model[-1] # is final layer, copy input as inplace fix - o = thop.profile(m, inputs=(x.copy() if c else x,), verbose=False)[0] / 1E9 * 2 if thop else 0 # FLOPs + o = thop.profile(m, inputs=(x.copy() if c else x, ), verbose=False)[0] / 1E9 * 2 if thop else 0 # FLOPs t = time_sync() for _ in range(10): m(x.copy() if c else x) diff --git a/segment/train.py b/segment/train.py index 5f1fa4a1e453..2ae09c1cbf66 100644 --- a/segment/train.py +++ b/segment/train.py @@ -605,7 +605,7 @@ def main(opt, callbacks=Callbacks()): 'gsutil', 'cp', f'gs://{opt.bucket}/evolve.csv', - str(evolve_csv),]) + str(evolve_csv), ]) for _ in range(opt.evolve): # generations to evolve if evolve_csv.exists(): # if evolve.csv exists: select best hyps and mutate diff --git a/setup.cfg b/setup.cfg index d7c4cb3e1a4d..2cde6a494836 100644 --- a/setup.cfg +++ b/setup.cfg @@ -3,7 +3,7 @@ # Local usage: pip install pre-commit, pre-commit run --all-files [metadata] -license_file = LICENSE +license_files = LICENSE description_file = README.md [tool:pytest] @@ -25,17 +25,19 @@ verbose = 2 # https://pep8.readthedocs.io/en/latest/intro.html#error-codes format = pylint # see: https://www.flake8rules.com/ -ignore = E731,F405,E402,F401,W504,E127,E231,E501,F403 +ignore = E731,F405,E402,W504,E501 # E731: Do not assign a lambda expression, use a def # F405: name may be undefined, or defined from star imports: module # E402: module level import not at top of file - # F401: module imported but unused # W504: line break after binary operator - # E127: continuation line over-indented for visual indent - # E231: missing whitespace after ‘,’, ‘;’, or ‘:’ # E501: line too long + # removed: + # F401: module imported but unused + # E231: missing whitespace after ‘,’, ‘;’, or ‘:’ + # E127: continuation line over-indented for visual indent # F403: ‘from module import *’ used; unable to detect undefined names + [isort] # https://pycqa.github.io/isort/docs/configuration/options.html line_length = 120 @@ -48,7 +50,7 @@ spaces_before_comment = 2 COLUMN_LIMIT = 120 COALESCE_BRACKETS = True SPACES_AROUND_POWER_OPERATOR = True -SPACE_BETWEEN_ENDING_COMMA_AND_CLOSING_BRACKET = False +SPACE_BETWEEN_ENDING_COMMA_AND_CLOSING_BRACKET = True SPLIT_BEFORE_CLOSING_BRACKET = False SPLIT_BEFORE_FIRST_ARGUMENT = False # EACH_DICT_ENTRY_ON_SEPARATE_LINE = False diff --git a/train.py b/train.py index b5044deb9b5c..004c8eeda121 100644 --- a/train.py +++ b/train.py @@ -584,7 +584,7 @@ def main(opt, callbacks=Callbacks()): 'gsutil', 'cp', f'gs://{opt.bucket}/evolve.csv', - str(evolve_csv),]) + str(evolve_csv), ]) for _ in range(opt.evolve): # generations to evolve if evolve_csv.exists(): # if evolve.csv exists: select best hyps and mutate diff --git a/utils/augmentations.py b/utils/augmentations.py index 52e2e346e36e..1e609303e209 100644 --- a/utils/augmentations.py +++ b/utils/augmentations.py @@ -330,7 +330,7 @@ def classify_albumentations( if vflip > 0: T += [A.VerticalFlip(p=vflip)] if jitter > 0: - color_jitter = (float(jitter),) * 3 # repeat value for brightness, contrast, satuaration, 0 hue + color_jitter = (float(jitter), ) * 3 # repeat value for brightness, contrast, satuaration, 0 hue T += [A.ColorJitter(*color_jitter, 0)] else: # Use fixed crop for eval set (reproducibility) T = [A.SmallestMaxSize(max_size=size), A.CenterCrop(height=size, width=size)] diff --git a/utils/callbacks.py b/utils/callbacks.py index ccebba02bcaa..c90fa824cdb4 100644 --- a/utils/callbacks.py +++ b/utils/callbacks.py @@ -32,7 +32,7 @@ def __init__(self): 'on_model_save': [], 'on_train_end': [], 'on_params_update': [], - 'teardown': [],} + 'teardown': [], } self.stop_training = False # set True to interrupt training def register_action(self, hook, name='', callback=None): diff --git a/utils/downloads.py b/utils/downloads.py index 629537d5ade6..9298259d4ab1 100644 --- a/utils/downloads.py +++ b/utils/downloads.py @@ -4,7 +4,6 @@ """ import logging -import os import subprocess import urllib from pathlib import Path @@ -53,7 +52,7 @@ def curl_download(url, filename, *, silent: bool = False) -> bool: '--retry', '9', '-C', - '-',]) + '-', ]) return proc.returncode == 0 diff --git a/utils/general.py b/utils/general.py index e95b07486619..049e5f6be414 100644 --- a/utils/general.py +++ b/utils/general.py @@ -139,12 +139,12 @@ def set_logging(name=LOGGING_NAME, verbose=True): name: { 'class': 'logging.StreamHandler', 'formatter': name, - 'level': level,}}, + 'level': level, }}, 'loggers': { name: { 'level': level, 'handlers': [name], - 'propagate': False,}}}) + 'propagate': False, }}}) set_logging(LOGGING_NAME) # run before defining LOGGER @@ -416,7 +416,7 @@ def check_imshow(warn=False): return False -def check_suffix(file='yolov5s.pt', suffix=('.pt',), msg=''): +def check_suffix(file='yolov5s.pt', suffix=('.pt', ), msg=''): # Check file(s) for acceptable suffix if file and suffix: if isinstance(suffix, str): diff --git a/utils/loggers/comet/__init__.py b/utils/loggers/comet/__init__.py index aac06b11c8c0..839fcf907e8f 100644 --- a/utils/loggers/comet/__init__.py +++ b/utils/loggers/comet/__init__.py @@ -90,7 +90,7 @@ def __init__(self, opt, hyp, run_id=None, job_type='Training', **experiment_kwar 'log_code': False, 'log_env_gpu': True, 'log_env_cpu': True, - 'project_name': COMET_PROJECT_NAME,} + 'project_name': COMET_PROJECT_NAME, } self.default_experiment_kwargs.update(experiment_kwargs) self.experiment = self._get_experiment(self.comet_mode, run_id) self.experiment.set_name(self.opt.name) @@ -153,7 +153,7 @@ def __init__(self, opt, hyp, run_id=None, job_type='Training', **experiment_kwar 'comet_log_per_class_metrics': COMET_LOG_PER_CLASS_METRICS, 'comet_log_batch_metrics': COMET_LOG_BATCH_METRICS, 'comet_log_confusion_matrix': COMET_LOG_CONFUSION_MATRIX, - 'comet_model_name': COMET_MODEL_NAME,}) + 'comet_model_name': COMET_MODEL_NAME, }) # Check if running the Experiment with the Comet Optimizer if hasattr(self.opt, 'comet_optimizer_id'): @@ -170,7 +170,7 @@ def _get_experiment(self, mode, experiment_id=None): **self.default_experiment_kwargs, ) - return comet_ml.OfflineExperiment(**self.default_experiment_kwargs,) + return comet_ml.OfflineExperiment(**self.default_experiment_kwargs, ) else: try: @@ -214,7 +214,7 @@ def log_model(self, path, opt, epoch, fitness_score, best_model=False): 'fitness_score': fitness_score[-1], 'epochs_trained': epoch + 1, 'save_period': opt.save_period, - 'total_epochs': opt.epochs,} + 'total_epochs': opt.epochs, } model_files = glob.glob(f'{path}/*.pt') for model_path in model_files: @@ -270,7 +270,7 @@ def log_predictions(self, image, labelsn, path, shape, predn): 'x': xyxy[0], 'y': xyxy[1], 'x2': xyxy[2], - 'y2': xyxy[3]},}) + 'y2': xyxy[3]}, }) for *xyxy, conf, cls in filtered_detections.tolist(): metadata.append({ 'label': f'{self.class_names[int(cls)]}', @@ -279,7 +279,7 @@ def log_predictions(self, image, labelsn, path, shape, predn): 'x': xyxy[0], 'y': xyxy[1], 'x2': xyxy[2], - 'y2': xyxy[3]},}) + 'y2': xyxy[3]}, }) self.metadata_dict[image_name] = metadata self.logged_images_count += 1 diff --git a/utils/segment/metrics.py b/utils/segment/metrics.py index 6020fa062ba5..787961bee1bf 100644 --- a/utils/segment/metrics.py +++ b/utils/segment/metrics.py @@ -196,7 +196,7 @@ def ap_class_index(self): 'val/cls_loss', 'x/lr0', 'x/lr1', - 'x/lr2',] + 'x/lr2', ] BEST_KEYS = [ 'best/epoch', @@ -207,4 +207,4 @@ def ap_class_index(self): 'best/precision(M)', 'best/recall(M)', 'best/mAP_0.5(M)', - 'best/mAP_0.5:0.95(M)',] + 'best/mAP_0.5:0.95(M)', ] diff --git a/utils/torch_utils.py b/utils/torch_utils.py index d9e060ab99df..13a356f3238c 100644 --- a/utils/torch_utils.py +++ b/utils/torch_utils.py @@ -170,7 +170,7 @@ def profile(input, ops, n=10, device=None): m = m.half() if hasattr(m, 'half') and isinstance(x, torch.Tensor) and x.dtype is torch.float16 else m tf, tb, t = 0, 0, [0, 0, 0] # dt forward, backward try: - flops = thop.profile(m, inputs=(x,), verbose=False)[0] / 1E9 * 2 # GFLOPs + flops = thop.profile(m, inputs=(x, ), verbose=False)[0] / 1E9 * 2 # GFLOPs except Exception: flops = 0 @@ -284,7 +284,7 @@ def model_info(model, verbose=False, imgsz=640): p = next(model.parameters()) stride = max(int(model.stride.max()), 32) if hasattr(model, 'stride') else 32 # max stride im = torch.empty((1, p.shape[1], stride, stride), device=p.device) # input image in BCHW format - flops = thop.profile(deepcopy(model), inputs=(im,), verbose=False)[0] / 1E9 * 2 # stride GFLOPs + flops = thop.profile(deepcopy(model), inputs=(im, ), verbose=False)[0] / 1E9 * 2 # stride GFLOPs imgsz = imgsz if isinstance(imgsz, list) else [imgsz, imgsz] # expand if int/float fs = f', {flops * imgsz[0] / stride * imgsz[1] / stride:.1f} GFLOPs' # 640x640 GFLOPs except Exception: