Update setup.cfg ()

* Update setup.cfg

Signed-off-by: Glenn Jocher <glenn.jocher@ultralytics.com>

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Update .pre-commit-config.yaml

Signed-off-by: Glenn Jocher <glenn.jocher@ultralytics.com>

* Update export.py

Signed-off-by: Glenn Jocher <glenn.jocher@ultralytics.com>

* Update downloads.py

Signed-off-by: Glenn Jocher <glenn.jocher@ultralytics.com>

* Update yolo.py

Signed-off-by: Glenn Jocher <glenn.jocher@ultralytics.com>

---------

Signed-off-by: Glenn Jocher <glenn.jocher@ultralytics.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
pull/11818/head^2
Glenn Jocher 2023-07-05 00:42:57 +02:00 committed by GitHub
parent 0b3f751a6f
commit 459dd49c02
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 46 additions and 41 deletions

View File

@ -16,7 +16,7 @@ repos:
- id: end-of-file-fixer - id: end-of-file-fixer
- id: trailing-whitespace - id: trailing-whitespace
- id: check-case-conflict - id: check-case-conflict
- id: check-yaml # - id: check-yaml
- id: check-docstring-first - id: check-docstring-first
- id: double-quote-string-fixer - id: double-quote-string-fixer
- id: detect-private-key - id: detect-private-key
@ -26,7 +26,6 @@ repos:
hooks: hooks:
- id: pyupgrade - id: pyupgrade
name: Upgrade code name: Upgrade code
args: [--py37-plus]
- repo: https://github.com/PyCQA/isort - repo: https://github.com/PyCQA/isort
rev: 5.12.0 rev: 5.12.0
@ -63,7 +62,12 @@ repos:
args: args:
- --ignore-words-list=crate,nd,strack,dota - --ignore-words-list=crate,nd,strack,dota
#- repo: https://github.com/asottile/yesqa # - repo: https://github.com/asottile/yesqa
# rev: v1.4.0 # rev: v1.4.0
# hooks: # hooks:
# - id: yesqa # - id: yesqa
# - repo: https://github.com/asottile/dead
# rev: v1.5.0
# hooks:
# - id: dead

View File

@ -110,7 +110,7 @@ def export_formats():
['TensorFlow Lite', 'tflite', '.tflite', True, False], ['TensorFlow Lite', 'tflite', '.tflite', True, False],
['TensorFlow Edge TPU', 'edgetpu', '_edgetpu.tflite', False, False], ['TensorFlow Edge TPU', 'edgetpu', '_edgetpu.tflite', False, False],
['TensorFlow.js', 'tfjs', '_web_model', 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']) 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 import numpy as np
from openvino.runtime import Core from openvino.runtime import Core
from utils.dataloaders import create_dataloader, letterbox from utils.dataloaders import create_dataloader
core = Core() core = Core()
onnx_model = core.read_model(f_onnx) # export onnx_model = core.read_model(f_onnx) # export
@ -501,7 +501,7 @@ def export_edgetpu(file, prefix=colorstr('Edge TPU:')):
'10', '10',
'--out_dir', '--out_dir',
str(file.parent), str(file.parent),
f_tfl,], check=True) f_tfl, ], check=True)
return f, None return f, None
@ -522,7 +522,7 @@ def export_tfjs(file, int8, prefix=colorstr('TensorFlow.js:')):
'--quantize_uint8' if int8 else '', '--quantize_uint8' if int8 else '',
'--output_node_names=Identity,Identity_1,Identity_2,Identity_3', '--output_node_names=Identity,Identity_1,Identity_2,Identity_3',
str(f_pb), str(f_pb),
str(f),] str(f), ]
subprocess.run([arg for arg in args if arg], check=True) subprocess.run([arg for arg in args if arg], check=True)
json = Path(f_json).read_text() json = Path(f_json).read_text()

View File

@ -310,7 +310,7 @@ class TFDetect(keras.layers.Layer):
y = tf.concat([xy, wh, tf.sigmoid(y[..., 4:5 + self.nc]), y[..., 5 + self.nc:]], -1) 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])) 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 @staticmethod
def _make_grid(nx=20, ny=20): def _make_grid(nx=20, ny=20):
@ -486,7 +486,7 @@ class TFModel:
iou_thres, iou_thres,
conf_thres, conf_thres,
clip_boxes=False) clip_boxes=False)
return (nms,) return (nms, )
return x # output [1,6300,85] = [xywh, conf, class0, class1, ...] return x # output [1,6300,85] = [xywh, conf, class0, class1, ...]
# x = x[0] # [x(1,6300,85), ...] to x(6300,85) # x = x[0] # [x(1,6300,85), ...] to x(6300,85)
# xywh = x[..., :4] # x(6300,4) boxes # xywh = x[..., :4] # x(6300,4) boxes

View File

@ -21,8 +21,8 @@ if str(ROOT) not in sys.path:
if platform.system() != 'Windows': if platform.system() != 'Windows':
ROOT = Path(os.path.relpath(ROOT, Path.cwd())) # relative ROOT = Path(os.path.relpath(ROOT, Path.cwd())) # relative
from models.common import * from models.common import * # noqa
from models.experimental import * from models.experimental import * # noqa
from utils.autoanchor import check_anchor_order from utils.autoanchor import check_anchor_order
from utils.general import LOGGER, check_version, check_yaml, make_divisible, print_args from utils.general import LOGGER, check_version, check_yaml, make_divisible, print_args
from utils.plots import feature_visualization from utils.plots import feature_visualization
@ -76,7 +76,7 @@ class Detect(nn.Module):
y = torch.cat((xy, wh, conf), 4) y = torch.cat((xy, wh, conf), 4)
z.append(y.view(bs, self.na * nx * ny, self.no)) 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')): 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 d = self.anchors[i].device
@ -126,7 +126,7 @@ class BaseModel(nn.Module):
def _profile_one_layer(self, m, x, dt): def _profile_one_layer(self, m, x, dt):
c = m == self.model[-1] # is final layer, copy input as inplace fix 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() t = time_sync()
for _ in range(10): for _ in range(10):
m(x.copy() if c else x) m(x.copy() if c else x)

View File

@ -605,7 +605,7 @@ def main(opt, callbacks=Callbacks()):
'gsutil', 'gsutil',
'cp', 'cp',
f'gs://{opt.bucket}/evolve.csv', f'gs://{opt.bucket}/evolve.csv',
str(evolve_csv),]) str(evolve_csv), ])
for _ in range(opt.evolve): # generations to evolve for _ in range(opt.evolve): # generations to evolve
if evolve_csv.exists(): # if evolve.csv exists: select best hyps and mutate if evolve_csv.exists(): # if evolve.csv exists: select best hyps and mutate

View File

@ -3,7 +3,7 @@
# Local usage: pip install pre-commit, pre-commit run --all-files # Local usage: pip install pre-commit, pre-commit run --all-files
[metadata] [metadata]
license_file = LICENSE license_files = LICENSE
description_file = README.md description_file = README.md
[tool:pytest] [tool:pytest]
@ -25,17 +25,19 @@ verbose = 2
# https://pep8.readthedocs.io/en/latest/intro.html#error-codes # https://pep8.readthedocs.io/en/latest/intro.html#error-codes
format = pylint format = pylint
# see: https://www.flake8rules.com/ # 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 # E731: Do not assign a lambda expression, use a def
# F405: name may be undefined, or defined from star imports: module # F405: name may be undefined, or defined from star imports: module
# E402: module level import not at top of file # E402: module level import not at top of file
# F401: module imported but unused
# W504: line break after binary operator # W504: line break after binary operator
# E127: continuation line over-indented for visual indent
# E231: missing whitespace after ,, ;, or :
# E501: line too long # 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 # F403: from module import * used; unable to detect undefined names
[isort] [isort]
# https://pycqa.github.io/isort/docs/configuration/options.html # https://pycqa.github.io/isort/docs/configuration/options.html
line_length = 120 line_length = 120
@ -48,7 +50,7 @@ spaces_before_comment = 2
COLUMN_LIMIT = 120 COLUMN_LIMIT = 120
COALESCE_BRACKETS = True COALESCE_BRACKETS = True
SPACES_AROUND_POWER_OPERATOR = 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_CLOSING_BRACKET = False
SPLIT_BEFORE_FIRST_ARGUMENT = False SPLIT_BEFORE_FIRST_ARGUMENT = False
# EACH_DICT_ENTRY_ON_SEPARATE_LINE = False # EACH_DICT_ENTRY_ON_SEPARATE_LINE = False

View File

@ -584,7 +584,7 @@ def main(opt, callbacks=Callbacks()):
'gsutil', 'gsutil',
'cp', 'cp',
f'gs://{opt.bucket}/evolve.csv', f'gs://{opt.bucket}/evolve.csv',
str(evolve_csv),]) str(evolve_csv), ])
for _ in range(opt.evolve): # generations to evolve for _ in range(opt.evolve): # generations to evolve
if evolve_csv.exists(): # if evolve.csv exists: select best hyps and mutate if evolve_csv.exists(): # if evolve.csv exists: select best hyps and mutate

View File

@ -330,7 +330,7 @@ def classify_albumentations(
if vflip > 0: if vflip > 0:
T += [A.VerticalFlip(p=vflip)] T += [A.VerticalFlip(p=vflip)]
if jitter > 0: 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)] T += [A.ColorJitter(*color_jitter, 0)]
else: # Use fixed crop for eval set (reproducibility) else: # Use fixed crop for eval set (reproducibility)
T = [A.SmallestMaxSize(max_size=size), A.CenterCrop(height=size, width=size)] T = [A.SmallestMaxSize(max_size=size), A.CenterCrop(height=size, width=size)]

View File

@ -32,7 +32,7 @@ class Callbacks:
'on_model_save': [], 'on_model_save': [],
'on_train_end': [], 'on_train_end': [],
'on_params_update': [], 'on_params_update': [],
'teardown': [],} 'teardown': [], }
self.stop_training = False # set True to interrupt training self.stop_training = False # set True to interrupt training
def register_action(self, hook, name='', callback=None): def register_action(self, hook, name='', callback=None):

View File

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

View File

@ -139,12 +139,12 @@ def set_logging(name=LOGGING_NAME, verbose=True):
name: { name: {
'class': 'logging.StreamHandler', 'class': 'logging.StreamHandler',
'formatter': name, 'formatter': name,
'level': level,}}, 'level': level, }},
'loggers': { 'loggers': {
name: { name: {
'level': level, 'level': level,
'handlers': [name], 'handlers': [name],
'propagate': False,}}}) 'propagate': False, }}})
set_logging(LOGGING_NAME) # run before defining LOGGER set_logging(LOGGING_NAME) # run before defining LOGGER
@ -416,7 +416,7 @@ def check_imshow(warn=False):
return 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 # Check file(s) for acceptable suffix
if file and suffix: if file and suffix:
if isinstance(suffix, str): if isinstance(suffix, str):

View File

@ -90,7 +90,7 @@ class CometLogger:
'log_code': False, 'log_code': False,
'log_env_gpu': True, 'log_env_gpu': True,
'log_env_cpu': True, 'log_env_cpu': True,
'project_name': COMET_PROJECT_NAME,} 'project_name': COMET_PROJECT_NAME, }
self.default_experiment_kwargs.update(experiment_kwargs) self.default_experiment_kwargs.update(experiment_kwargs)
self.experiment = self._get_experiment(self.comet_mode, run_id) self.experiment = self._get_experiment(self.comet_mode, run_id)
self.experiment.set_name(self.opt.name) self.experiment.set_name(self.opt.name)
@ -153,7 +153,7 @@ class CometLogger:
'comet_log_per_class_metrics': COMET_LOG_PER_CLASS_METRICS, 'comet_log_per_class_metrics': COMET_LOG_PER_CLASS_METRICS,
'comet_log_batch_metrics': COMET_LOG_BATCH_METRICS, 'comet_log_batch_metrics': COMET_LOG_BATCH_METRICS,
'comet_log_confusion_matrix': COMET_LOG_CONFUSION_MATRIX, '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 # Check if running the Experiment with the Comet Optimizer
if hasattr(self.opt, 'comet_optimizer_id'): if hasattr(self.opt, 'comet_optimizer_id'):
@ -170,7 +170,7 @@ class CometLogger:
**self.default_experiment_kwargs, **self.default_experiment_kwargs,
) )
return comet_ml.OfflineExperiment(**self.default_experiment_kwargs,) return comet_ml.OfflineExperiment(**self.default_experiment_kwargs, )
else: else:
try: try:
@ -214,7 +214,7 @@ class CometLogger:
'fitness_score': fitness_score[-1], 'fitness_score': fitness_score[-1],
'epochs_trained': epoch + 1, 'epochs_trained': epoch + 1,
'save_period': opt.save_period, 'save_period': opt.save_period,
'total_epochs': opt.epochs,} 'total_epochs': opt.epochs, }
model_files = glob.glob(f'{path}/*.pt') model_files = glob.glob(f'{path}/*.pt')
for model_path in model_files: for model_path in model_files:
@ -270,7 +270,7 @@ class CometLogger:
'x': xyxy[0], 'x': xyxy[0],
'y': xyxy[1], 'y': xyxy[1],
'x2': xyxy[2], 'x2': xyxy[2],
'y2': xyxy[3]},}) 'y2': xyxy[3]}, })
for *xyxy, conf, cls in filtered_detections.tolist(): for *xyxy, conf, cls in filtered_detections.tolist():
metadata.append({ metadata.append({
'label': f'{self.class_names[int(cls)]}', 'label': f'{self.class_names[int(cls)]}',
@ -279,7 +279,7 @@ class CometLogger:
'x': xyxy[0], 'x': xyxy[0],
'y': xyxy[1], 'y': xyxy[1],
'x2': xyxy[2], 'x2': xyxy[2],
'y2': xyxy[3]},}) 'y2': xyxy[3]}, })
self.metadata_dict[image_name] = metadata self.metadata_dict[image_name] = metadata
self.logged_images_count += 1 self.logged_images_count += 1

View File

@ -196,7 +196,7 @@ KEYS = [
'val/cls_loss', 'val/cls_loss',
'x/lr0', 'x/lr0',
'x/lr1', 'x/lr1',
'x/lr2',] 'x/lr2', ]
BEST_KEYS = [ BEST_KEYS = [
'best/epoch', 'best/epoch',
@ -207,4 +207,4 @@ BEST_KEYS = [
'best/precision(M)', 'best/precision(M)',
'best/recall(M)', 'best/recall(M)',
'best/mAP_0.5(M)', 'best/mAP_0.5(M)',
'best/mAP_0.5:0.95(M)',] 'best/mAP_0.5:0.95(M)', ]

View File

@ -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 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 tf, tb, t = 0, 0, [0, 0, 0] # dt forward, backward
try: 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: except Exception:
flops = 0 flops = 0
@ -284,7 +284,7 @@ def model_info(model, verbose=False, imgsz=640):
p = next(model.parameters()) p = next(model.parameters())
stride = max(int(model.stride.max()), 32) if hasattr(model, 'stride') else 32 # max stride 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 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 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 fs = f', {flops * imgsz[0] / stride * imgsz[1] / stride:.1f} GFLOPs' # 640x640 GFLOPs
except Exception: except Exception: