Skip to content

Commit

Permalink
reformat with isort (fcakyon#71)
Browse files Browse the repository at this point in the history
  • Loading branch information
fcakyon authored Dec 8, 2021
1 parent 8be5473 commit dec0381
Show file tree
Hide file tree
Showing 20 changed files with 88 additions and 60 deletions.
4 changes: 2 additions & 2 deletions yolov5/cli.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import fire

from yolov5.train import run as train
from yolov5.val import run as val
from yolov5.detect import run as detect
from yolov5.export import run as export
from yolov5.train import run as train
from yolov5.val import run as val


def app() -> None:
Expand Down
10 changes: 7 additions & 3 deletions yolov5/detect.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,13 @@

from yolov5.models.experimental import attempt_load
from yolov5.utils.datasets import LoadImages, LoadStreams
from yolov5.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, set_logging, \
strip_optimizer, xyxy2xywh, yolov5_in_syspath
from yolov5.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, set_logging,
strip_optimizer, xyxy2xywh,
yolov5_in_syspath)
from yolov5.utils.plots import Annotator, colors
from yolov5.utils.torch_utils import load_classifier, select_device, time_sync

Expand Down
11 changes: 7 additions & 4 deletions yolov5/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@
from yolov5.models.yolo import Detect
from yolov5.utils.activations import SiLU
from yolov5.utils.datasets import LoadImages
from yolov5.utils.general import colorstr, check_dataset, check_img_size, check_requirements, file_size, print_args, \
set_logging, url2file
from yolov5.utils.general import (check_dataset, check_img_size,
check_requirements, colorstr, file_size,
print_args, set_logging, url2file)
from yolov5.utils.torch_utils import select_device


Expand Down Expand Up @@ -131,8 +132,8 @@ def export_saved_model(model, im, file, dynamic,
keras_model = None
try:
import tensorflow as tf
from models.tf import TFDetect, TFModel
from tensorflow import keras
from models.tf import TFModel, TFDetect

print(f'\n{prefix} starting export with tensorflow {tf.__version__}...')
f = str(file).replace('.pt', '_saved_model')
Expand All @@ -159,7 +160,8 @@ def export_pb(keras_model, im, file, prefix=colorstr('TensorFlow GraphDef:')):
# YOLOv5 TensorFlow GraphDef *.pb export https://github.com/leimao/Frozen_Graph_TensorFlow
try:
import tensorflow as tf
from tensorflow.python.framework.convert_to_constants import convert_variables_to_constants_v2
from tensorflow.python.framework.convert_to_constants import \
convert_variables_to_constants_v2

print(f'\n{prefix} starting export with tensorflow {tf.__version__}...')
f = file.with_suffix('.pb')
Expand Down Expand Up @@ -212,6 +214,7 @@ def export_tfjs(keras_model, im, file, prefix=colorstr('TensorFlow.js:')):
try:
#check_requirements(('tensorflowjs',))
import re

import tensorflowjs as tfjs

print(f'\n{prefix} starting export with tensorflowjs {tfjs.__version__}...')
Expand Down
5 changes: 2 additions & 3 deletions yolov5/helpers.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
from pathlib import Path

from yolov5.models.yolo import Model
from yolov5.models.experimental import attempt_load
from yolov5.models.yolo import Model
from yolov5.utils.general import set_logging, yolov5_in_syspath
from yolov5.utils.google_utils import attempt_download
from yolov5.utils.torch_utils import select_device
from yolov5.utils.torch_utils import torch
from yolov5.utils.torch_utils import select_device, torch


def load_model(model_path, device=None, autoshape=True, verbose=False):
Expand Down
8 changes: 5 additions & 3 deletions yolov5/hubconf.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,11 @@ def _create(name, pretrained=True, channels=3, classes=80, autoshape=True, verbo
"""
from pathlib import Path

from yolov5.models.yolo import Model
from yolov5.models.experimental import attempt_load
from yolov5.utils.general import check_requirements, set_logging, yolov5_in_syspath
from yolov5.models.yolo import Model
from yolov5.utils.downloads import attempt_download
from yolov5.utils.general import (check_requirements, set_logging,
yolov5_in_syspath)
from yolov5.utils.torch_utils import select_device

file = Path(__file__).resolve()
Expand Down Expand Up @@ -126,10 +127,11 @@ def yolov5x6(pretrained=True, channels=3, classes=80, autoshape=True, verbose=Tr
# model = custom(path='path/to/model.pt') # custom

# Verify inference
from pathlib import Path

import cv2
import numpy as np
from PIL import Image
from pathlib import Path

imgs = ['data/images/zidane.jpg', # filename
Path('data/images/zidane.jpg'), # Path
Expand Down
5 changes: 3 additions & 2 deletions yolov5/models/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@
from torch.cuda import amp

from yolov5.utils.datasets import exif_transpose, letterbox
from yolov5.utils.general import colorstr, increment_path, make_divisible, non_max_suppression, save_one_box, \
scale_coords, xyxy2xywh
from yolov5.utils.general import (colorstr, increment_path, make_divisible,
non_max_suppression, save_one_box,
scale_coords, xyxy2xywh)
from yolov5.utils.plots import Annotator, colors
from yolov5.utils.torch_utils import time_sync

Expand Down
2 changes: 1 addition & 1 deletion yolov5/models/experimental.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
import torch.nn as nn

from yolov5.models.common import Conv
from yolov5.utils.general import yolov5_in_syspath
from yolov5.utils.downloads import attempt_download
from yolov5.utils.general import yolov5_in_syspath


class CrossConv(nn.Module):
Expand Down
5 changes: 3 additions & 2 deletions yolov5/models/tf.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,12 @@
import torch.nn as nn
from tensorflow import keras

from yolov5.models.common import Bottleneck, BottleneckCSP, Concat, Conv, C3, DWConv, Focus, SPP, SPPF, autopad
from yolov5.models.common import (C3, SPP, SPPF, Bottleneck, BottleneckCSP,
Concat, Conv, DWConv, Focus, autopad)
from yolov5.models.experimental import CrossConv, MixConv2d, attempt_load
from yolov5.models.yolo import Detect
from yolov5.utils.general import make_divisible, print_args, set_logging
from yolov5.utils.activations import SiLU
from yolov5.utils.general import make_divisible, print_args, set_logging

LOGGER = logging.getLogger(__name__)

Expand Down
8 changes: 5 additions & 3 deletions yolov5/models/yolo.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@
from yolov5.models.common import *
from yolov5.models.experimental import *
from yolov5.utils.autoanchor import check_anchor_order
from yolov5.utils.general import check_yaml, make_divisible, print_args, set_logging
from yolov5.utils.general import (check_yaml, make_divisible, print_args,
set_logging)
from yolov5.utils.plots import feature_visualization
from yolov5.utils.torch_utils import copy_attr, fuse_conv_and_bn, initialize_weights, model_info, scale_img, \
select_device, time_sync
from yolov5.utils.torch_utils import (copy_attr, fuse_conv_and_bn,
initialize_weights, model_info,
scale_img, select_device, time_sync)

try:
import thop # for FLOPs computation
Expand Down
28 changes: 17 additions & 11 deletions yolov5/train.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import yaml
from torch.cuda import amp
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

FILE = Path(__file__).resolve()
Expand All @@ -34,20 +34,26 @@
from yolov5.models.experimental import attempt_load
from yolov5.models.yolo import Model
from yolov5.utils.autoanchor import check_anchors
from yolov5.utils.aws import upload_file_to_s3, upload_folder_to_s3
from yolov5.utils.callbacks import Callbacks
from yolov5.utils.datasets import create_dataloader
from yolov5.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, set_logging, one_cycle, colorstr, methods, yolov5_in_syspath
from yolov5.utils.downloads import attempt_download
from yolov5.utils.loss import ComputeLoss
from yolov5.utils.plots import plot_labels, plot_evolve
from yolov5.utils.torch_utils import EarlyStopping, ModelEMA, de_parallel, intersect_dicts, select_device, \
torch_distributed_zero_first
from yolov5.utils.general import (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, set_logging,
strip_optimizer, yolov5_in_syspath)
from yolov5.utils.loggers import Loggers
from yolov5.utils.loggers.wandb.wandb_utils import check_wandb_resume
from yolov5.utils.loss import ComputeLoss
from yolov5.utils.metrics import fitness
from yolov5.utils.loggers import Loggers
from yolov5.utils.callbacks import Callbacks
from yolov5.utils.aws import upload_file_to_s3, upload_folder_to_s3
from yolov5.utils.plots import plot_evolve, plot_labels
from yolov5.utils.torch_utils import (EarlyStopping, ModelEMA, de_parallel,
intersect_dicts, select_device,
torch_distributed_zero_first)

LOGGER = logging.getLogger(__name__)
LOCAL_RANK = int(os.getenv('LOCAL_RANK', -1)) # https://pytorch.org/docs/stable/elastic/run.html
Expand Down
3 changes: 2 additions & 1 deletion yolov5/utils/augmentations.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
import cv2
import numpy as np

from yolov5.utils.general import colorstr, segment2box, resample_segments, check_version
from yolov5.utils.general import (check_version, colorstr, resample_segments,
segment2box)
from yolov5.utils.metrics import bbox_ioa


Expand Down
9 changes: 5 additions & 4 deletions yolov5/utils/aws.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import os
import concurrent.futures
from pathlib import Path
import logging
import os
from pathlib import Path

import boto3
import numpy as np
from botocore.exceptions import NoCredentialsError
from tqdm import tqdm
import numpy as np
from yolov5.utils.general import colorstr

from yolov5.utils.general import colorstr

AWS_ACCESS_KEY_ID = os.getenv("AWS_ACCESS_KEY_ID")
AWS_SECRET_ACCESS_KEY = os.environ.get("AWS_SECRET_ACCESS_KEY")
Expand Down
14 changes: 9 additions & 5 deletions yolov5/utils/datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import shutil
import time
from itertools import repeat
from multiprocessing.pool import ThreadPool, Pool
from multiprocessing.pool import Pool, ThreadPool
from pathlib import Path
from threading import Thread
from zipfile import ZipFile
Expand All @@ -22,13 +22,17 @@
import torch
import torch.nn.functional as F
import yaml
from PIL import Image, ExifTags
from PIL import ExifTags, Image
from torch.utils.data import Dataset
from tqdm import tqdm

from yolov5.utils.augmentations import Albumentations, augment_hsv, copy_paste, letterbox, mixup, random_perspective
from yolov5.utils.general import check_dataset, check_requirements, check_yaml, clean_str, segments2boxes, \
xywh2xyxy, xywhn2xyxy, xyxy2xywhn, xyn2xy, yolov5_in_syspath
from yolov5.utils.augmentations import (Albumentations, augment_hsv,
copy_paste, letterbox, mixup,
random_perspective)
from yolov5.utils.general import (check_dataset, check_requirements,
check_yaml, clean_str, segments2boxes,
xyn2xy, xywh2xyxy, xywhn2xyxy, xyxy2xywhn,
yolov5_in_syspath)
from yolov5.utils.torch_utils import torch_distributed_zero_first

# Parameters
Expand Down
2 changes: 1 addition & 1 deletion yolov5/utils/general.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import random
import re
import signal
import sys
import time
import urllib
from itertools import repeat
Expand All @@ -27,7 +28,6 @@
import torch
import torchvision
import yaml
import sys

from yolov5.utils.downloads import gsutil_getsize
from yolov5.utils.metrics import box_iou, fitness
Expand Down
4 changes: 2 additions & 2 deletions yolov5/utils/loggers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@
"""

import os
from pathlib import Path
import warnings
from pathlib import Path
from threading import Thread

import pkg_resources as pkg
import torch
from torch.utils.tensorboard import SummaryWriter

from yolov5.utils.general import colorstr, emojis
from yolov5.utils.loggers.wandb.wandb_utils import WandbLogger
from yolov5.utils.loggers.neptune.neptune_utils import NeptuneLogger
from yolov5.utils.loggers.wandb.wandb_utils import WandbLogger
from yolov5.utils.plots import plot_images, plot_results
from yolov5.utils.torch_utils import de_parallel

Expand Down
5 changes: 3 additions & 2 deletions yolov5/utils/loggers/neptune/neptune_utils.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import os
from pathlib import Path

from yolov5.utils.general import colorstr
import yaml
import os

from yolov5.utils.general import colorstr

try:
import neptune.new as neptune
Expand Down
4 changes: 2 additions & 2 deletions yolov5/utils/loggers/wandb/sweep.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
FILE = Path(__file__).resolve()
ROOT = FILE.parents[3] # YOLOv5 root directory

from yolov5.train import train, parse_opt
from yolov5.train import parse_opt, train
from yolov5.utils.callbacks import Callbacks
from yolov5.utils.general import increment_path
from yolov5.utils.torch_utils import select_device
from yolov5.utils.callbacks import Callbacks


def sweep():
Expand Down
3 changes: 1 addition & 2 deletions yolov5/utils/loggers/wandb/wandb_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@
FILE = Path(__file__).resolve()
ROOT = FILE.parents[3] # YOLOv5 root directory

from yolov5.utils.datasets import LoadImagesAndLabels
from yolov5.utils.datasets import img2label_paths
from yolov5.utils.datasets import LoadImagesAndLabels, img2label_paths
from yolov5.utils.general import check_dataset, check_file

RANK = int(os.getenv('RANK', -1))
Expand Down
3 changes: 2 additions & 1 deletion yolov5/utils/plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
import torch
from PIL import Image, ImageDraw, ImageFont

from yolov5.utils.general import user_config_dir, is_ascii, is_chinese, xywh2xyxy, xyxy2xywh
from yolov5.utils.general import (is_ascii, is_chinese, user_config_dir,
xywh2xyxy, xyxy2xywh)
from yolov5.utils.metrics import fitness

# Settings
Expand Down
15 changes: 9 additions & 6 deletions yolov5/val.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,25 @@
from threading import Thread

import numpy as np
import pandas as pd
import torch
from tqdm import tqdm
import pandas as pd

FILE = Path(__file__).resolve()
ROOT = FILE.parents[0] # YOLOv5 root directory

from yolov5.models.experimental import attempt_load
from yolov5.utils.callbacks import Callbacks
from yolov5.utils.datasets import create_dataloader
from yolov5.utils.general import coco80_to_coco91_class, check_dataset, check_img_size, check_requirements, \
check_suffix, check_yaml, box_iou, non_max_suppression, scale_coords, xyxy2xywh, xywh2xyxy, set_logging, \
increment_path, colorstr, print_args
from yolov5.utils.metrics import ap_per_class, ConfusionMatrix
from yolov5.utils.general import (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, set_logging,
xywh2xyxy, xyxy2xywh)
from yolov5.utils.metrics import ConfusionMatrix, ap_per_class
from yolov5.utils.plots import output_to_target, plot_images, plot_val_study
from yolov5.utils.torch_utils import select_device, time_sync
from yolov5.utils.callbacks import Callbacks


def save_one_txt(predn, save_conf, shape, file):
Expand Down

0 comments on commit dec0381

Please sign in to comment.