Skip to content
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

Update setup.cfg #11814

Merged
merged 6 commits into from
Jul 4, 2023
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
16 changes: 10 additions & 6 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -26,7 +26,6 @@ repos:
hooks:
- id: pyupgrade
name: Upgrade code
args: [--py37-plus]

- repo: https://github.com/PyCQA/isort
rev: 5.12.0
Expand Down Expand Up @@ -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
8 changes: 4 additions & 4 deletions export.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'])


Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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


Expand All @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions models/tf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions models/yolo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion segment/train.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 8 additions & 6 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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
Expand All @@ -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
2 changes: 1 addition & 1 deletion train.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion utils/augmentations.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
2 changes: 1 addition & 1 deletion utils/callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
3 changes: 1 addition & 2 deletions utils/downloads.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
"""

import logging
import os
import subprocess
import urllib
from pathlib import Path
Expand Down Expand Up @@ -53,7 +52,7 @@ def curl_download(url, filename, *, silent: bool = False) -> bool:
'--retry',
'9',
'-C',
'-',])
'-', ])
return proc.returncode == 0


Expand Down
6 changes: 3 additions & 3 deletions utils/general.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down
12 changes: 6 additions & 6 deletions utils/loggers/comet/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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'):
Expand All @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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)]}',
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions utils/segment/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ def ap_class_index(self):
'val/cls_loss',
'x/lr0',
'x/lr1',
'x/lr2',]
'x/lr2', ]

BEST_KEYS = [
'best/epoch',
Expand All @@ -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)', ]
4 changes: 2 additions & 2 deletions utils/torch_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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:
Expand Down