precommit: isort (#5493)
Browse files* precommit: isort
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Update isort config
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Update name
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Glenn Jocher <[email protected]>
- .pre-commit-config.yaml +5 -6
- detect.py +3 -2
- export.py +6 -3
- hubconf.py +4 -3
- models/common.py +2 -2
- models/experimental.py +1 -0
- models/tf.py +2 -2
- models/yolo.py +3 -3
- setup.cfg +6 -0
- train.py +11 -10
- utils/augmentations.py +1 -1
- utils/datasets.py +4 -4
- utils/flask_rest_api/restapi.py +1 -1
- utils/loggers/wandb/sweep.py +2 -2
- utils/loggers/wandb/wandb_utils.py +1 -2
- utils/plots.py +1 -1
- val.py +5 -5
.pre-commit-config.yaml
CHANGED
@@ -30,12 +30,11 @@ repos:
|
|
30 |
args: [--py36-plus]
|
31 |
name: Upgrade code
|
32 |
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
# name: imports
|
39 |
|
40 |
# TODO
|
41 |
#- repo: https://github.com/pre-commit/mirrors-yapf
|
|
|
30 |
args: [--py36-plus]
|
31 |
name: Upgrade code
|
32 |
|
33 |
+
- repo: https://github.com/PyCQA/isort
|
34 |
+
rev: 5.9.3
|
35 |
+
hooks:
|
36 |
+
- id: isort
|
37 |
+
name: Sort imports
|
|
|
38 |
|
39 |
# TODO
|
40 |
#- repo: https://github.com/pre-commit/mirrors-yapf
|
detect.py
CHANGED
@@ -25,8 +25,9 @@ ROOT = Path(os.path.relpath(ROOT, Path.cwd())) # relative
|
|
25 |
|
26 |
from models.experimental import attempt_load
|
27 |
from utils.datasets import LoadImages, LoadStreams
|
28 |
-
from utils.general import apply_classifier, check_img_size, check_imshow, check_requirements, check_suffix,
|
29 |
-
|
|
|
30 |
from utils.plots import Annotator, colors
|
31 |
from utils.torch_utils import load_classifier, select_device, time_sync
|
32 |
|
|
|
25 |
|
26 |
from models.experimental import attempt_load
|
27 |
from utils.datasets import LoadImages, LoadStreams
|
28 |
+
from utils.general import (LOGGER, apply_classifier, check_img_size, check_imshow, check_requirements, check_suffix,
|
29 |
+
colorstr, increment_path, non_max_suppression, print_args, save_one_box, scale_coords,
|
30 |
+
strip_optimizer, xyxy2xywh)
|
31 |
from utils.plots import Annotator, colors
|
32 |
from utils.torch_utils import load_classifier, select_device, time_sync
|
33 |
|
export.py
CHANGED
@@ -42,8 +42,8 @@ from models.experimental import attempt_load
|
|
42 |
from models.yolo import Detect
|
43 |
from utils.activations import SiLU
|
44 |
from utils.datasets import LoadImages
|
45 |
-
from utils.general import check_dataset, check_img_size, check_requirements, colorstr, file_size, print_args,
|
46 |
-
|
47 |
from utils.torch_utils import select_device
|
48 |
|
49 |
|
@@ -135,7 +135,8 @@ def export_saved_model(model, im, file, dynamic,
|
|
135 |
try:
|
136 |
import tensorflow as tf
|
137 |
from tensorflow import keras
|
138 |
-
|
|
|
139 |
|
140 |
LOGGER.info(f'\n{prefix} starting export with tensorflow {tf.__version__}...')
|
141 |
f = str(file).replace('.pt', '_saved_model')
|
@@ -182,6 +183,7 @@ def export_tflite(keras_model, im, file, int8, data, ncalib, prefix=colorstr('Te
|
|
182 |
# YOLOv5 TensorFlow Lite export
|
183 |
try:
|
184 |
import tensorflow as tf
|
|
|
185 |
from models.tf import representative_dataset_gen
|
186 |
|
187 |
LOGGER.info(f'\n{prefix} starting export with tensorflow {tf.__version__}...')
|
@@ -215,6 +217,7 @@ def export_tfjs(keras_model, im, file, prefix=colorstr('TensorFlow.js:')):
|
|
215 |
try:
|
216 |
check_requirements(('tensorflowjs',))
|
217 |
import re
|
|
|
218 |
import tensorflowjs as tfjs
|
219 |
|
220 |
LOGGER.info(f'\n{prefix} starting export with tensorflowjs {tfjs.__version__}...')
|
|
|
42 |
from models.yolo import Detect
|
43 |
from utils.activations import SiLU
|
44 |
from utils.datasets import LoadImages
|
45 |
+
from utils.general import (LOGGER, check_dataset, check_img_size, check_requirements, colorstr, file_size, print_args,
|
46 |
+
url2file)
|
47 |
from utils.torch_utils import select_device
|
48 |
|
49 |
|
|
|
135 |
try:
|
136 |
import tensorflow as tf
|
137 |
from tensorflow import keras
|
138 |
+
|
139 |
+
from models.tf import TFDetect, TFModel
|
140 |
|
141 |
LOGGER.info(f'\n{prefix} starting export with tensorflow {tf.__version__}...')
|
142 |
f = str(file).replace('.pt', '_saved_model')
|
|
|
183 |
# YOLOv5 TensorFlow Lite export
|
184 |
try:
|
185 |
import tensorflow as tf
|
186 |
+
|
187 |
from models.tf import representative_dataset_gen
|
188 |
|
189 |
LOGGER.info(f'\n{prefix} starting export with tensorflow {tf.__version__}...')
|
|
|
217 |
try:
|
218 |
check_requirements(('tensorflowjs',))
|
219 |
import re
|
220 |
+
|
221 |
import tensorflowjs as tfjs
|
222 |
|
223 |
LOGGER.info(f'\n{prefix} starting export with tensorflowjs {tfjs.__version__}...')
|
hubconf.py
CHANGED
@@ -27,10 +27,10 @@ def _create(name, pretrained=True, channels=3, classes=80, autoshape=True, verbo
|
|
27 |
"""
|
28 |
from pathlib import Path
|
29 |
|
30 |
-
from models.yolo import Model
|
31 |
from models.experimental import attempt_load
|
32 |
-
from
|
33 |
from utils.downloads import attempt_download
|
|
|
34 |
from utils.torch_utils import select_device
|
35 |
|
36 |
file = Path(__file__).resolve()
|
@@ -125,10 +125,11 @@ if __name__ == '__main__':
|
|
125 |
# model = custom(path='path/to/model.pt') # custom
|
126 |
|
127 |
# Verify inference
|
|
|
|
|
128 |
import cv2
|
129 |
import numpy as np
|
130 |
from PIL import Image
|
131 |
-
from pathlib import Path
|
132 |
|
133 |
imgs = ['data/images/zidane.jpg', # filename
|
134 |
Path('data/images/zidane.jpg'), # Path
|
|
|
27 |
"""
|
28 |
from pathlib import Path
|
29 |
|
|
|
30 |
from models.experimental import attempt_load
|
31 |
+
from models.yolo import Model
|
32 |
from utils.downloads import attempt_download
|
33 |
+
from utils.general import check_requirements, set_logging
|
34 |
from utils.torch_utils import select_device
|
35 |
|
36 |
file = Path(__file__).resolve()
|
|
|
125 |
# model = custom(path='path/to/model.pt') # custom
|
126 |
|
127 |
# Verify inference
|
128 |
+
from pathlib import Path
|
129 |
+
|
130 |
import cv2
|
131 |
import numpy as np
|
132 |
from PIL import Image
|
|
|
133 |
|
134 |
imgs = ['data/images/zidane.jpg', # filename
|
135 |
Path('data/images/zidane.jpg'), # Path
|
models/common.py
CHANGED
@@ -18,8 +18,8 @@ from PIL import Image
|
|
18 |
from torch.cuda import amp
|
19 |
|
20 |
from utils.datasets import exif_transpose, letterbox
|
21 |
-
from utils.general import colorstr, increment_path, make_divisible, non_max_suppression, save_one_box,
|
22 |
-
|
23 |
from utils.plots import Annotator, colors
|
24 |
from utils.torch_utils import time_sync
|
25 |
|
|
|
18 |
from torch.cuda import amp
|
19 |
|
20 |
from utils.datasets import exif_transpose, letterbox
|
21 |
+
from utils.general import (colorstr, increment_path, make_divisible, non_max_suppression, save_one_box, scale_coords,
|
22 |
+
xyxy2xywh)
|
23 |
from utils.plots import Annotator, colors
|
24 |
from utils.torch_utils import time_sync
|
25 |
|
models/experimental.py
CHANGED
@@ -3,6 +3,7 @@
|
|
3 |
Experimental modules
|
4 |
"""
|
5 |
import math
|
|
|
6 |
import numpy as np
|
7 |
import torch
|
8 |
import torch.nn as nn
|
|
|
3 |
Experimental modules
|
4 |
"""
|
5 |
import math
|
6 |
+
|
7 |
import numpy as np
|
8 |
import torch
|
9 |
import torch.nn as nn
|
models/tf.py
CHANGED
@@ -28,11 +28,11 @@ import torch
|
|
28 |
import torch.nn as nn
|
29 |
from tensorflow import keras
|
30 |
|
31 |
-
from models.common import Bottleneck, BottleneckCSP, Concat, Conv,
|
32 |
from models.experimental import CrossConv, MixConv2d, attempt_load
|
33 |
from models.yolo import Detect
|
34 |
-
from utils.general import make_divisible, print_args, LOGGER
|
35 |
from utils.activations import SiLU
|
|
|
36 |
|
37 |
|
38 |
class TFBN(keras.layers.Layer):
|
|
|
28 |
import torch.nn as nn
|
29 |
from tensorflow import keras
|
30 |
|
31 |
+
from models.common import C3, SPP, SPPF, Bottleneck, BottleneckCSP, Concat, Conv, DWConv, Focus, autopad
|
32 |
from models.experimental import CrossConv, MixConv2d, attempt_load
|
33 |
from models.yolo import Detect
|
|
|
34 |
from utils.activations import SiLU
|
35 |
+
from utils.general import LOGGER, make_divisible, print_args
|
36 |
|
37 |
|
38 |
class TFBN(keras.layers.Layer):
|
models/yolo.py
CHANGED
@@ -20,10 +20,10 @@ if str(ROOT) not in sys.path:
|
|
20 |
from models.common import *
|
21 |
from models.experimental import *
|
22 |
from utils.autoanchor import check_anchor_order
|
23 |
-
from utils.general import check_version, check_yaml, make_divisible, print_args
|
24 |
from utils.plots import feature_visualization
|
25 |
-
from utils.torch_utils import copy_attr, fuse_conv_and_bn, initialize_weights, model_info, scale_img,
|
26 |
-
|
27 |
|
28 |
try:
|
29 |
import thop # for FLOPs computation
|
|
|
20 |
from models.common import *
|
21 |
from models.experimental import *
|
22 |
from utils.autoanchor import check_anchor_order
|
23 |
+
from utils.general import LOGGER, check_version, check_yaml, make_divisible, print_args
|
24 |
from utils.plots import feature_visualization
|
25 |
+
from utils.torch_utils import (copy_attr, fuse_conv_and_bn, initialize_weights, model_info, scale_img, select_device,
|
26 |
+
time_sync)
|
27 |
|
28 |
try:
|
29 |
import thop # for FLOPs computation
|
setup.cfg
CHANGED
@@ -43,3 +43,9 @@ ignore =
|
|
43 |
F403
|
44 |
E302
|
45 |
F541
|
|
|
|
|
|
|
|
|
|
|
|
|
|
43 |
F403
|
44 |
E302
|
45 |
F541
|
46 |
+
|
47 |
+
|
48 |
+
[isort]
|
49 |
+
# https://pycqa.github.io/isort/docs/configuration/options.html
|
50 |
+
line_length = 120
|
51 |
+
multi_line_output = 0
|
train.py
CHANGED
@@ -23,7 +23,7 @@ import torch.nn as nn
|
|
23 |
import yaml
|
24 |
from torch.cuda import amp
|
25 |
from torch.nn.parallel import DistributedDataParallel as DDP
|
26 |
-
from torch.optim import
|
27 |
from tqdm import tqdm
|
28 |
|
29 |
FILE = Path(__file__).resolve()
|
@@ -37,19 +37,20 @@ from models.experimental import attempt_load
|
|
37 |
from models.yolo import Model
|
38 |
from utils.autoanchor import check_anchors
|
39 |
from utils.autobatch import check_train_batch_size
|
|
|
40 |
from utils.datasets import create_dataloader
|
41 |
-
from utils.general import labels_to_class_weights, increment_path, labels_to_image_weights, init_seeds, \
|
42 |
-
strip_optimizer, get_latest_run, check_dataset, check_git_status, check_img_size, check_requirements, \
|
43 |
-
check_file, check_yaml, check_suffix, print_args, print_mutation, one_cycle, colorstr, methods, LOGGER
|
44 |
from utils.downloads import attempt_download
|
45 |
-
from utils.
|
46 |
-
|
47 |
-
|
48 |
-
|
|
|
49 |
from utils.loggers.wandb.wandb_utils import check_wandb_resume
|
|
|
50 |
from utils.metrics import fitness
|
51 |
-
from utils.
|
52 |
-
from utils.
|
|
|
53 |
|
54 |
LOCAL_RANK = int(os.getenv('LOCAL_RANK', -1)) # https://pytorch.org/docs/stable/elastic/run.html
|
55 |
RANK = int(os.getenv('RANK', -1))
|
|
|
23 |
import yaml
|
24 |
from torch.cuda import amp
|
25 |
from torch.nn.parallel import DistributedDataParallel as DDP
|
26 |
+
from torch.optim import SGD, Adam, lr_scheduler
|
27 |
from tqdm import tqdm
|
28 |
|
29 |
FILE = Path(__file__).resolve()
|
|
|
37 |
from models.yolo import Model
|
38 |
from utils.autoanchor import check_anchors
|
39 |
from utils.autobatch import check_train_batch_size
|
40 |
+
from utils.callbacks import Callbacks
|
41 |
from utils.datasets import create_dataloader
|
|
|
|
|
|
|
42 |
from utils.downloads import attempt_download
|
43 |
+
from utils.general import (LOGGER, check_dataset, check_file, check_git_status, check_img_size, check_requirements,
|
44 |
+
check_suffix, check_yaml, colorstr, get_latest_run, increment_path, init_seeds,
|
45 |
+
labels_to_class_weights, labels_to_image_weights, methods, one_cycle, print_args,
|
46 |
+
print_mutation, strip_optimizer)
|
47 |
+
from utils.loggers import Loggers
|
48 |
from utils.loggers.wandb.wandb_utils import check_wandb_resume
|
49 |
+
from utils.loss import ComputeLoss
|
50 |
from utils.metrics import fitness
|
51 |
+
from utils.plots import plot_evolve, plot_labels
|
52 |
+
from utils.torch_utils import (EarlyStopping, ModelEMA, de_parallel, intersect_dicts, select_device,
|
53 |
+
torch_distributed_zero_first)
|
54 |
|
55 |
LOCAL_RANK = int(os.getenv('LOCAL_RANK', -1)) # https://pytorch.org/docs/stable/elastic/run.html
|
56 |
RANK = int(os.getenv('RANK', -1))
|
utils/augmentations.py
CHANGED
@@ -10,7 +10,7 @@ import random
|
|
10 |
import cv2
|
11 |
import numpy as np
|
12 |
|
13 |
-
from utils.general import
|
14 |
from utils.metrics import bbox_ioa
|
15 |
|
16 |
|
|
|
10 |
import cv2
|
11 |
import numpy as np
|
12 |
|
13 |
+
from utils.general import check_version, colorstr, resample_segments, segment2box
|
14 |
from utils.metrics import bbox_ioa
|
15 |
|
16 |
|
utils/datasets.py
CHANGED
@@ -12,7 +12,7 @@ import random
|
|
12 |
import shutil
|
13 |
import time
|
14 |
from itertools import repeat
|
15 |
-
from multiprocessing.pool import
|
16 |
from pathlib import Path
|
17 |
from threading import Thread
|
18 |
from zipfile import ZipFile
|
@@ -22,13 +22,13 @@ import numpy as np
|
|
22 |
import torch
|
23 |
import torch.nn.functional as F
|
24 |
import yaml
|
25 |
-
from PIL import Image, ImageOps
|
26 |
from torch.utils.data import Dataset
|
27 |
from tqdm import tqdm
|
28 |
|
29 |
from utils.augmentations import Albumentations, augment_hsv, copy_paste, letterbox, mixup, random_perspective
|
30 |
-
from utils.general import check_dataset, check_requirements, check_yaml, clean_str, segments2boxes,
|
31 |
-
|
32 |
from utils.torch_utils import torch_distributed_zero_first
|
33 |
|
34 |
# Parameters
|
|
|
12 |
import shutil
|
13 |
import time
|
14 |
from itertools import repeat
|
15 |
+
from multiprocessing.pool import Pool, ThreadPool
|
16 |
from pathlib import Path
|
17 |
from threading import Thread
|
18 |
from zipfile import ZipFile
|
|
|
22 |
import torch
|
23 |
import torch.nn.functional as F
|
24 |
import yaml
|
25 |
+
from PIL import ExifTags, Image, ImageOps
|
26 |
from torch.utils.data import Dataset
|
27 |
from tqdm import tqdm
|
28 |
|
29 |
from utils.augmentations import Albumentations, augment_hsv, copy_paste, letterbox, mixup, random_perspective
|
30 |
+
from utils.general import (LOGGER, check_dataset, check_requirements, check_yaml, clean_str, segments2boxes, xyn2xy,
|
31 |
+
xywh2xyxy, xywhn2xyxy, xyxy2xywhn)
|
32 |
from utils.torch_utils import torch_distributed_zero_first
|
33 |
|
34 |
# Parameters
|
utils/flask_rest_api/restapi.py
CHANGED
@@ -5,8 +5,8 @@ import argparse
|
|
5 |
import io
|
6 |
|
7 |
import torch
|
8 |
-
from PIL import Image
|
9 |
from flask import Flask, request
|
|
|
10 |
|
11 |
app = Flask(__name__)
|
12 |
|
|
|
5 |
import io
|
6 |
|
7 |
import torch
|
|
|
8 |
from flask import Flask, request
|
9 |
+
from PIL import Image
|
10 |
|
11 |
app = Flask(__name__)
|
12 |
|
utils/loggers/wandb/sweep.py
CHANGED
@@ -8,10 +8,10 @@ ROOT = FILE.parents[3] # YOLOv5 root directory
|
|
8 |
if str(ROOT) not in sys.path:
|
9 |
sys.path.append(str(ROOT)) # add ROOT to PATH
|
10 |
|
11 |
-
from train import
|
|
|
12 |
from utils.general import increment_path
|
13 |
from utils.torch_utils import select_device
|
14 |
-
from utils.callbacks import Callbacks
|
15 |
|
16 |
|
17 |
def sweep():
|
|
|
8 |
if str(ROOT) not in sys.path:
|
9 |
sys.path.append(str(ROOT)) # add ROOT to PATH
|
10 |
|
11 |
+
from train import parse_opt, train
|
12 |
+
from utils.callbacks import Callbacks
|
13 |
from utils.general import increment_path
|
14 |
from utils.torch_utils import select_device
|
|
|
15 |
|
16 |
|
17 |
def sweep():
|
utils/loggers/wandb/wandb_utils.py
CHANGED
@@ -16,8 +16,7 @@ ROOT = FILE.parents[3] # YOLOv5 root directory
|
|
16 |
if str(ROOT) not in sys.path:
|
17 |
sys.path.append(str(ROOT)) # add ROOT to PATH
|
18 |
|
19 |
-
from utils.datasets import LoadImagesAndLabels
|
20 |
-
from utils.datasets import img2label_paths
|
21 |
from utils.general import check_dataset, check_file
|
22 |
|
23 |
try:
|
|
|
16 |
if str(ROOT) not in sys.path:
|
17 |
sys.path.append(str(ROOT)) # add ROOT to PATH
|
18 |
|
19 |
+
from utils.datasets import LoadImagesAndLabels, img2label_paths
|
|
|
20 |
from utils.general import check_dataset, check_file
|
21 |
|
22 |
try:
|
utils/plots.py
CHANGED
@@ -17,7 +17,7 @@ import seaborn as sn
|
|
17 |
import torch
|
18 |
from PIL import Image, ImageDraw, ImageFont
|
19 |
|
20 |
-
from utils.general import
|
21 |
from utils.metrics import fitness
|
22 |
|
23 |
# Settings
|
|
|
17 |
import torch
|
18 |
from PIL import Image, ImageDraw, ImageFont
|
19 |
|
20 |
+
from utils.general import is_ascii, is_chinese, user_config_dir, xywh2xyxy, xyxy2xywh
|
21 |
from utils.metrics import fitness
|
22 |
|
23 |
# Settings
|
val.py
CHANGED
@@ -24,14 +24,14 @@ if str(ROOT) not in sys.path:
|
|
24 |
ROOT = Path(os.path.relpath(ROOT, Path.cwd())) # relative
|
25 |
|
26 |
from models.experimental import attempt_load
|
|
|
27 |
from utils.datasets import create_dataloader
|
28 |
-
from utils.general import box_iou,
|
29 |
-
|
30 |
-
|
31 |
-
from utils.metrics import
|
32 |
from utils.plots import output_to_target, plot_images, plot_val_study
|
33 |
from utils.torch_utils import select_device, time_sync
|
34 |
-
from utils.callbacks import Callbacks
|
35 |
|
36 |
|
37 |
def save_one_txt(predn, save_conf, shape, file):
|
|
|
24 |
ROOT = Path(os.path.relpath(ROOT, Path.cwd())) # relative
|
25 |
|
26 |
from models.experimental import attempt_load
|
27 |
+
from utils.callbacks import Callbacks
|
28 |
from utils.datasets import create_dataloader
|
29 |
+
from utils.general import (LOGGER, box_iou, check_dataset, check_img_size, check_requirements, check_suffix, check_yaml,
|
30 |
+
coco80_to_coco91_class, colorstr, increment_path, non_max_suppression, print_args,
|
31 |
+
scale_coords, xywh2xyxy, xyxy2xywh)
|
32 |
+
from utils.metrics import ConfusionMatrix, ap_per_class
|
33 |
from utils.plots import output_to_target, plot_images, plot_val_study
|
34 |
from utils.torch_utils import select_device, time_sync
|
|
|
35 |
|
36 |
|
37 |
def save_one_txt(predn, save_conf, shape, file):
|