* 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 <glenn.jocher@ultralytics.com>modifyDataloader
args: [--py36-plus] | args: [--py36-plus] | ||||
name: Upgrade code | name: Upgrade code | ||||
# TODO | |||||
#- repo: https://github.com/PyCQA/isort | |||||
# rev: 5.9.3 | |||||
# hooks: | |||||
# - id: isort | |||||
# name: imports | |||||
- repo: https://github.com/PyCQA/isort | |||||
rev: 5.9.3 | |||||
hooks: | |||||
- id: isort | |||||
name: Sort imports | |||||
# TODO | # TODO | ||||
#- repo: https://github.com/pre-commit/mirrors-yapf | #- repo: https://github.com/pre-commit/mirrors-yapf |
from models.experimental import attempt_load | from models.experimental import attempt_load | ||||
from utils.datasets import LoadImages, LoadStreams | from utils.datasets import LoadImages, LoadStreams | ||||
from utils.general import apply_classifier, check_img_size, check_imshow, check_requirements, check_suffix, colorstr, \ | |||||
increment_path, non_max_suppression, print_args, save_one_box, scale_coords, strip_optimizer, xyxy2xywh, LOGGER | |||||
from utils.general import (LOGGER, apply_classifier, check_img_size, check_imshow, check_requirements, check_suffix, | |||||
colorstr, increment_path, non_max_suppression, print_args, save_one_box, scale_coords, | |||||
strip_optimizer, xyxy2xywh) | |||||
from utils.plots import Annotator, colors | from utils.plots import Annotator, colors | ||||
from utils.torch_utils import load_classifier, select_device, time_sync | from utils.torch_utils import load_classifier, select_device, time_sync | ||||
from models.yolo import Detect | from models.yolo import Detect | ||||
from utils.activations import SiLU | from utils.activations import SiLU | ||||
from utils.datasets import LoadImages | from utils.datasets import LoadImages | ||||
from utils.general import check_dataset, check_img_size, check_requirements, colorstr, file_size, print_args, \ | |||||
url2file, LOGGER | |||||
from utils.general import (LOGGER, check_dataset, check_img_size, check_requirements, colorstr, file_size, print_args, | |||||
url2file) | |||||
from utils.torch_utils import select_device | from utils.torch_utils import select_device | ||||
try: | try: | ||||
import tensorflow as tf | import tensorflow as tf | ||||
from tensorflow import keras | from tensorflow import keras | ||||
from models.tf import TFModel, TFDetect | |||||
from models.tf import TFDetect, TFModel | |||||
LOGGER.info(f'\n{prefix} starting export with tensorflow {tf.__version__}...') | LOGGER.info(f'\n{prefix} starting export with tensorflow {tf.__version__}...') | ||||
f = str(file).replace('.pt', '_saved_model') | f = str(file).replace('.pt', '_saved_model') | ||||
# YOLOv5 TensorFlow Lite export | # YOLOv5 TensorFlow Lite export | ||||
try: | try: | ||||
import tensorflow as tf | import tensorflow as tf | ||||
from models.tf import representative_dataset_gen | from models.tf import representative_dataset_gen | ||||
LOGGER.info(f'\n{prefix} starting export with tensorflow {tf.__version__}...') | LOGGER.info(f'\n{prefix} starting export with tensorflow {tf.__version__}...') | ||||
try: | try: | ||||
check_requirements(('tensorflowjs',)) | check_requirements(('tensorflowjs',)) | ||||
import re | import re | ||||
import tensorflowjs as tfjs | import tensorflowjs as tfjs | ||||
LOGGER.info(f'\n{prefix} starting export with tensorflowjs {tfjs.__version__}...') | LOGGER.info(f'\n{prefix} starting export with tensorflowjs {tfjs.__version__}...') |
""" | """ | ||||
from pathlib import Path | from pathlib import Path | ||||
from models.yolo import Model | |||||
from models.experimental import attempt_load | from models.experimental import attempt_load | ||||
from utils.general import check_requirements, set_logging | |||||
from models.yolo import Model | |||||
from utils.downloads import attempt_download | from utils.downloads import attempt_download | ||||
from utils.general import check_requirements, set_logging | |||||
from utils.torch_utils import select_device | from utils.torch_utils import select_device | ||||
file = Path(__file__).resolve() | file = Path(__file__).resolve() | ||||
# model = custom(path='path/to/model.pt') # custom | # model = custom(path='path/to/model.pt') # custom | ||||
# Verify inference | # Verify inference | ||||
from pathlib import Path | |||||
import cv2 | import cv2 | ||||
import numpy as np | import numpy as np | ||||
from PIL import Image | from PIL import Image | ||||
from pathlib import Path | |||||
imgs = ['data/images/zidane.jpg', # filename | imgs = ['data/images/zidane.jpg', # filename | ||||
Path('data/images/zidane.jpg'), # Path | Path('data/images/zidane.jpg'), # Path |
from torch.cuda import amp | from torch.cuda import amp | ||||
from utils.datasets import exif_transpose, letterbox | from utils.datasets import exif_transpose, letterbox | ||||
from utils.general import colorstr, increment_path, make_divisible, non_max_suppression, save_one_box, \ | |||||
scale_coords, xyxy2xywh | |||||
from utils.general import (colorstr, increment_path, make_divisible, non_max_suppression, save_one_box, scale_coords, | |||||
xyxy2xywh) | |||||
from utils.plots import Annotator, colors | from utils.plots import Annotator, colors | ||||
from utils.torch_utils import time_sync | from utils.torch_utils import time_sync | ||||
Experimental modules | Experimental modules | ||||
""" | """ | ||||
import math | import math | ||||
import numpy as np | import numpy as np | ||||
import torch | import torch | ||||
import torch.nn as nn | import torch.nn as nn |
import torch.nn as nn | import torch.nn as nn | ||||
from tensorflow import keras | from tensorflow import keras | ||||
from models.common import Bottleneck, BottleneckCSP, Concat, Conv, C3, DWConv, Focus, SPP, SPPF, autopad | |||||
from models.common import C3, SPP, SPPF, Bottleneck, BottleneckCSP, Concat, Conv, DWConv, Focus, autopad | |||||
from models.experimental import CrossConv, MixConv2d, attempt_load | from models.experimental import CrossConv, MixConv2d, attempt_load | ||||
from models.yolo import Detect | from models.yolo import Detect | ||||
from utils.general import make_divisible, print_args, LOGGER | |||||
from utils.activations import SiLU | from utils.activations import SiLU | ||||
from utils.general import LOGGER, make_divisible, print_args | |||||
class TFBN(keras.layers.Layer): | class TFBN(keras.layers.Layer): |
from models.common import * | from models.common import * | ||||
from models.experimental import * | from models.experimental import * | ||||
from utils.autoanchor import check_anchor_order | from utils.autoanchor import check_anchor_order | ||||
from utils.general import check_version, check_yaml, make_divisible, print_args, LOGGER | |||||
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 | ||||
from utils.torch_utils import copy_attr, fuse_conv_and_bn, initialize_weights, model_info, scale_img, \ | |||||
select_device, time_sync | |||||
from utils.torch_utils import (copy_attr, fuse_conv_and_bn, initialize_weights, model_info, scale_img, select_device, | |||||
time_sync) | |||||
try: | try: | ||||
import thop # for FLOPs computation | import thop # for FLOPs computation |
F403 | F403 | ||||
E302 | E302 | ||||
F541 | F541 | ||||
[isort] | |||||
# https://pycqa.github.io/isort/docs/configuration/options.html | |||||
line_length = 120 | |||||
multi_line_output = 0 |
import yaml | import yaml | ||||
from torch.cuda import amp | from torch.cuda import amp | ||||
from torch.nn.parallel import DistributedDataParallel as DDP | from torch.nn.parallel import DistributedDataParallel as DDP | ||||
from torch.optim import Adam, SGD, lr_scheduler | |||||
from torch.optim import SGD, Adam, lr_scheduler | |||||
from tqdm import tqdm | from tqdm import tqdm | ||||
FILE = Path(__file__).resolve() | FILE = Path(__file__).resolve() | ||||
from models.yolo import Model | from models.yolo import Model | ||||
from utils.autoanchor import check_anchors | from utils.autoanchor import check_anchors | ||||
from utils.autobatch import check_train_batch_size | from utils.autobatch import check_train_batch_size | ||||
from utils.callbacks import Callbacks | |||||
from utils.datasets import create_dataloader | from utils.datasets import create_dataloader | ||||
from utils.general import labels_to_class_weights, increment_path, labels_to_image_weights, init_seeds, \ | |||||
strip_optimizer, get_latest_run, check_dataset, check_git_status, check_img_size, check_requirements, \ | |||||
check_file, check_yaml, check_suffix, print_args, print_mutation, one_cycle, colorstr, methods, LOGGER | |||||
from utils.downloads import attempt_download | from utils.downloads import attempt_download | ||||
from utils.loss import ComputeLoss | |||||
from utils.plots import plot_labels, plot_evolve | |||||
from utils.torch_utils import EarlyStopping, ModelEMA, de_parallel, intersect_dicts, select_device, \ | |||||
torch_distributed_zero_first | |||||
from utils.general import (LOGGER, check_dataset, check_file, check_git_status, check_img_size, check_requirements, | |||||
check_suffix, check_yaml, colorstr, get_latest_run, increment_path, init_seeds, | |||||
labels_to_class_weights, labels_to_image_weights, methods, one_cycle, print_args, | |||||
print_mutation, strip_optimizer) | |||||
from utils.loggers import Loggers | |||||
from utils.loggers.wandb.wandb_utils import check_wandb_resume | from utils.loggers.wandb.wandb_utils import check_wandb_resume | ||||
from utils.loss import ComputeLoss | |||||
from utils.metrics import fitness | from utils.metrics import fitness | ||||
from utils.loggers import Loggers | |||||
from utils.callbacks import Callbacks | |||||
from utils.plots import plot_evolve, plot_labels | |||||
from utils.torch_utils import (EarlyStopping, ModelEMA, de_parallel, intersect_dicts, select_device, | |||||
torch_distributed_zero_first) | |||||
LOCAL_RANK = int(os.getenv('LOCAL_RANK', -1)) # https://pytorch.org/docs/stable/elastic/run.html | LOCAL_RANK = int(os.getenv('LOCAL_RANK', -1)) # https://pytorch.org/docs/stable/elastic/run.html | ||||
RANK = int(os.getenv('RANK', -1)) | RANK = int(os.getenv('RANK', -1)) |
import cv2 | import cv2 | ||||
import numpy as np | import numpy as np | ||||
from utils.general import colorstr, segment2box, resample_segments, check_version | |||||
from utils.general import check_version, colorstr, resample_segments, segment2box | |||||
from utils.metrics import bbox_ioa | from utils.metrics import bbox_ioa | ||||
import shutil | import shutil | ||||
import time | import time | ||||
from itertools import repeat | from itertools import repeat | ||||
from multiprocessing.pool import ThreadPool, Pool | |||||
from multiprocessing.pool import Pool, ThreadPool | |||||
from pathlib import Path | from pathlib import Path | ||||
from threading import Thread | from threading import Thread | ||||
from zipfile import ZipFile | from zipfile import ZipFile | ||||
import torch | import torch | ||||
import torch.nn.functional as F | import torch.nn.functional as F | ||||
import yaml | import yaml | ||||
from PIL import Image, ImageOps, ExifTags | |||||
from PIL import ExifTags, Image, ImageOps | |||||
from torch.utils.data import Dataset | from torch.utils.data import Dataset | ||||
from tqdm import tqdm | from tqdm import tqdm | ||||
from utils.augmentations import Albumentations, augment_hsv, copy_paste, letterbox, mixup, random_perspective | from utils.augmentations import Albumentations, augment_hsv, copy_paste, letterbox, mixup, random_perspective | ||||
from utils.general import check_dataset, check_requirements, check_yaml, clean_str, segments2boxes, \ | |||||
xywh2xyxy, xywhn2xyxy, xyxy2xywhn, xyn2xy, LOGGER | |||||
from utils.general import (LOGGER, check_dataset, check_requirements, check_yaml, clean_str, segments2boxes, xyn2xy, | |||||
xywh2xyxy, xywhn2xyxy, xyxy2xywhn) | |||||
from utils.torch_utils import torch_distributed_zero_first | from utils.torch_utils import torch_distributed_zero_first | ||||
# Parameters | # Parameters |
import io | import io | ||||
import torch | import torch | ||||
from PIL import Image | |||||
from flask import Flask, request | from flask import Flask, request | ||||
from PIL import Image | |||||
app = Flask(__name__) | app = Flask(__name__) | ||||
if str(ROOT) not in sys.path: | if str(ROOT) not in sys.path: | ||||
sys.path.append(str(ROOT)) # add ROOT to PATH | sys.path.append(str(ROOT)) # add ROOT to PATH | ||||
from train import train, parse_opt | |||||
from train import parse_opt, train | |||||
from utils.callbacks import Callbacks | |||||
from utils.general import increment_path | from utils.general import increment_path | ||||
from utils.torch_utils import select_device | from utils.torch_utils import select_device | ||||
from utils.callbacks import Callbacks | |||||
def sweep(): | def sweep(): |
if str(ROOT) not in sys.path: | if str(ROOT) not in sys.path: | ||||
sys.path.append(str(ROOT)) # add ROOT to PATH | sys.path.append(str(ROOT)) # add ROOT to PATH | ||||
from utils.datasets import LoadImagesAndLabels | |||||
from utils.datasets import img2label_paths | |||||
from utils.datasets import LoadImagesAndLabels, img2label_paths | |||||
from utils.general import check_dataset, check_file | from utils.general import check_dataset, check_file | ||||
try: | try: |
import torch | import torch | ||||
from PIL import Image, ImageDraw, ImageFont | from PIL import Image, ImageDraw, ImageFont | ||||
from utils.general import user_config_dir, is_ascii, is_chinese, xywh2xyxy, xyxy2xywh | |||||
from utils.general import is_ascii, is_chinese, user_config_dir, xywh2xyxy, xyxy2xywh | |||||
from utils.metrics import fitness | from utils.metrics import fitness | ||||
# Settings | # Settings |
ROOT = Path(os.path.relpath(ROOT, Path.cwd())) # relative | ROOT = Path(os.path.relpath(ROOT, Path.cwd())) # relative | ||||
from models.experimental import attempt_load | from models.experimental import attempt_load | ||||
from utils.callbacks import Callbacks | |||||
from utils.datasets import create_dataloader | from utils.datasets import create_dataloader | ||||
from utils.general import box_iou, coco80_to_coco91_class, colorstr, check_dataset, check_img_size, \ | |||||
check_requirements, check_suffix, check_yaml, increment_path, non_max_suppression, print_args, scale_coords, \ | |||||
xyxy2xywh, xywh2xyxy, LOGGER | |||||
from utils.metrics import ap_per_class, ConfusionMatrix | |||||
from utils.general import (LOGGER, box_iou, check_dataset, check_img_size, check_requirements, check_suffix, check_yaml, | |||||
coco80_to_coco91_class, colorstr, increment_path, non_max_suppression, print_args, | |||||
scale_coords, xywh2xyxy, xyxy2xywh) | |||||
from utils.metrics import ConfusionMatrix, ap_per_class | |||||
from utils.plots import output_to_target, plot_images, plot_val_study | from utils.plots import output_to_target, plot_images, plot_val_study | ||||
from utils.torch_utils import select_device, time_sync | from utils.torch_utils import select_device, time_sync | ||||
from utils.callbacks import Callbacks | |||||
def save_one_txt(predn, save_conf, shape, file): | def save_one_txt(predn, save_conf, shape, file): |