🎨 [Update] pre-commit module, add isort
Browse files- .pre-commit-config.yaml +6 -0
- config/config.py +1 -1
- model/module.py +15 -11
- model/yolo.py +1 -0
- tests/test_model/test_yolo.py +3 -3
- tests/test_utils/test_dataaugment.py +3 -2
- tools/layer_helper.py +2 -0
- tools/log_helper.py +1 -0
- train.py +3 -2
- utils/dataargument.py +1 -1
- utils/dataloader.py +7 -7
- utils/get_dataset.py +1 -1
.pre-commit-config.yaml
CHANGED
@@ -6,3 +6,9 @@ repos:
|
|
6 |
language_version: python3 # Specify the Python version
|
7 |
exclude: '.*\.yaml$' # Regex pattern to exclude all YAML files
|
8 |
args: ["--line-length", "120"] # Set max line length to 100 characters
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
language_version: python3 # Specify the Python version
|
7 |
exclude: '.*\.yaml$' # Regex pattern to exclude all YAML files
|
8 |
args: ["--line-length", "120"] # Set max line length to 100 characters
|
9 |
+
|
10 |
+
- repo: https://github.com/pre-commit/mirrors-isort
|
11 |
+
rev: v5.10.1 # Use the appropriate version or "stable" for the latest stable release
|
12 |
+
hooks:
|
13 |
+
- id: isort
|
14 |
+
args: ["--profile", "black", "--verbose"]
|
config/config.py
CHANGED
@@ -1,5 +1,5 @@
|
|
1 |
from dataclasses import dataclass
|
2 |
-
from typing import
|
3 |
|
4 |
|
5 |
@dataclass
|
|
|
1 |
from dataclasses import dataclass
|
2 |
+
from typing import Dict, List, Union
|
3 |
|
4 |
|
5 |
@dataclass
|
model/module.py
CHANGED
@@ -48,10 +48,12 @@ class Conv(nn.Module):
|
|
48 |
# RepVGG
|
49 |
class RepConv(nn.Module):
|
50 |
# https://github.com/DingXiaoH/RepVGG
|
51 |
-
def __init__(
|
|
|
|
|
52 |
|
53 |
super().__init__()
|
54 |
-
self.deploy = deploy
|
55 |
self.conv1 = Conv(in_channels, out_channels, kernel_size, stride, groups=groups, act=False)
|
56 |
self.conv2 = Conv(in_channels, out_channels, 1, stride, groups=groups, act=False)
|
57 |
self.act = act if isinstance(act, nn.Module) else nn.Identity()
|
@@ -73,15 +75,17 @@ class RepConv(nn.Module):
|
|
73 |
weights = conv.weight * t
|
74 |
|
75 |
bn = nn.Identity()
|
76 |
-
conv = nn.Conv2d(
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
|
|
|
|
85 |
|
86 |
conv.weight = torch.nn.Parameter(weights)
|
87 |
conv.bias = torch.nn.Parameter(bias)
|
|
|
48 |
# RepVGG
|
49 |
class RepConv(nn.Module):
|
50 |
# https://github.com/DingXiaoH/RepVGG
|
51 |
+
def __init__(
|
52 |
+
self, in_channels, out_channels, kernel_size=3, padding=None, stride=1, groups=1, act=nn.SiLU(), deploy=False
|
53 |
+
):
|
54 |
|
55 |
super().__init__()
|
56 |
+
self.deploy = deploy
|
57 |
self.conv1 = Conv(in_channels, out_channels, kernel_size, stride, groups=groups, act=False)
|
58 |
self.conv2 = Conv(in_channels, out_channels, 1, stride, groups=groups, act=False)
|
59 |
self.act = act if isinstance(act, nn.Module) else nn.Identity()
|
|
|
75 |
weights = conv.weight * t
|
76 |
|
77 |
bn = nn.Identity()
|
78 |
+
conv = nn.Conv2d(
|
79 |
+
in_channels=conv.in_channels,
|
80 |
+
out_channels=conv.out_channels,
|
81 |
+
kernel_size=conv.kernel_size,
|
82 |
+
stride=conv.stride,
|
83 |
+
padding=conv.padding,
|
84 |
+
dilation=conv.dilation,
|
85 |
+
groups=conv.groups,
|
86 |
+
bias=True,
|
87 |
+
padding_mode=conv.padding_mode,
|
88 |
+
)
|
89 |
|
90 |
conv.weight = torch.nn.Parameter(weights)
|
91 |
conv.bias = torch.nn.Parameter(bias)
|
model/yolo.py
CHANGED
@@ -4,6 +4,7 @@ import torch
|
|
4 |
import torch.nn as nn
|
5 |
from loguru import logger
|
6 |
from omegaconf import OmegaConf
|
|
|
7 |
from tools.layer_helper import get_layer_map
|
8 |
|
9 |
|
|
|
4 |
import torch.nn as nn
|
5 |
from loguru import logger
|
6 |
from omegaconf import OmegaConf
|
7 |
+
|
8 |
from tools.layer_helper import get_layer_map
|
9 |
|
10 |
|
tests/test_model/test_yolo.py
CHANGED
@@ -1,11 +1,11 @@
|
|
|
|
|
|
1 |
import pytest
|
2 |
import torch
|
3 |
-
from hydra import
|
4 |
from hydra.core.global_hydra import GlobalHydra
|
5 |
from omegaconf import DictConfig, OmegaConf
|
6 |
|
7 |
-
import sys
|
8 |
-
|
9 |
sys.path.append("./")
|
10 |
from model.yolo import YOLO, get_model
|
11 |
|
|
|
1 |
+
import sys
|
2 |
+
|
3 |
import pytest
|
4 |
import torch
|
5 |
+
from hydra import compose, initialize
|
6 |
from hydra.core.global_hydra import GlobalHydra
|
7 |
from omegaconf import DictConfig, OmegaConf
|
8 |
|
|
|
|
|
9 |
sys.path.append("./")
|
10 |
from model.yolo import YOLO, get_model
|
11 |
|
tests/test_utils/test_dataaugment.py
CHANGED
@@ -1,11 +1,12 @@
|
|
|
|
|
|
1 |
import pytest
|
2 |
import torch
|
3 |
from PIL import Image
|
4 |
from torchvision.transforms import functional as TF
|
5 |
-
import sys
|
6 |
|
7 |
sys.path.append("./")
|
8 |
-
from utils.dataargument import
|
9 |
|
10 |
|
11 |
def test_random_horizontal_flip():
|
|
|
1 |
+
import sys
|
2 |
+
|
3 |
import pytest
|
4 |
import torch
|
5 |
from PIL import Image
|
6 |
from torchvision.transforms import functional as TF
|
|
|
7 |
|
8 |
sys.path.append("./")
|
9 |
+
from utils.dataargument import Compose, Mosaic, RandomHorizontalFlip
|
10 |
|
11 |
|
12 |
def test_random_horizontal_flip():
|
tools/layer_helper.py
CHANGED
@@ -1,5 +1,7 @@
|
|
1 |
import inspect
|
|
|
2 |
import torch.nn as nn
|
|
|
3 |
from model import module
|
4 |
|
5 |
|
|
|
1 |
import inspect
|
2 |
+
|
3 |
import torch.nn as nn
|
4 |
+
|
5 |
from model import module
|
6 |
|
7 |
|
tools/log_helper.py
CHANGED
@@ -12,6 +12,7 @@ Example:
|
|
12 |
"""
|
13 |
|
14 |
import sys
|
|
|
15 |
from loguru import logger
|
16 |
|
17 |
|
|
|
12 |
"""
|
13 |
|
14 |
import sys
|
15 |
+
|
16 |
from loguru import logger
|
17 |
|
18 |
|
train.py
CHANGED
@@ -1,9 +1,10 @@
|
|
|
|
1 |
from loguru import logger
|
|
|
|
|
2 |
from model.yolo import get_model
|
3 |
from tools.log_helper import custom_logger
|
4 |
from utils.get_dataset import prepare_dataset
|
5 |
-
import hydra
|
6 |
-
from config.config import Config
|
7 |
|
8 |
|
9 |
@hydra.main(config_path="config", config_name="config", version_base=None)
|
|
|
1 |
+
import hydra
|
2 |
from loguru import logger
|
3 |
+
|
4 |
+
from config.config import Config
|
5 |
from model.yolo import get_model
|
6 |
from tools.log_helper import custom_logger
|
7 |
from utils.get_dataset import prepare_dataset
|
|
|
|
|
8 |
|
9 |
|
10 |
@hydra.main(config_path="config", config_name="config", version_base=None)
|
utils/dataargument.py
CHANGED
@@ -1,6 +1,6 @@
|
|
1 |
-
from PIL import Image
|
2 |
import numpy as np
|
3 |
import torch
|
|
|
4 |
from torchvision.transforms import functional as TF
|
5 |
|
6 |
|
|
|
|
|
1 |
import numpy as np
|
2 |
import torch
|
3 |
+
from PIL import Image
|
4 |
from torchvision.transforms import functional as TF
|
5 |
|
6 |
|
utils/dataloader.py
CHANGED
@@ -1,16 +1,16 @@
|
|
1 |
-
from
|
2 |
-
from
|
3 |
|
|
|
4 |
import hydra
|
5 |
import numpy as np
|
6 |
import torch
|
7 |
-
from
|
|
|
8 |
from loguru import logger
|
|
|
|
|
9 |
from tqdm.rich import tqdm
|
10 |
-
import diskcache as dc
|
11 |
-
from typing import Union
|
12 |
-
from drawer import draw_bboxes
|
13 |
-
from dataargument import Compose, RandomHorizontalFlip, Mosaic
|
14 |
|
15 |
|
16 |
class YoloDataset(Dataset):
|
|
|
1 |
+
from os import listdir, path
|
2 |
+
from typing import Union
|
3 |
|
4 |
+
import diskcache as dc
|
5 |
import hydra
|
6 |
import numpy as np
|
7 |
import torch
|
8 |
+
from dataargument import Compose, Mosaic, RandomHorizontalFlip
|
9 |
+
from drawer import draw_bboxes
|
10 |
from loguru import logger
|
11 |
+
from PIL import Image
|
12 |
+
from torch.utils.data import Dataset
|
13 |
from tqdm.rich import tqdm
|
|
|
|
|
|
|
|
|
14 |
|
15 |
|
16 |
class YoloDataset(Dataset):
|
utils/get_dataset.py
CHANGED
@@ -2,8 +2,8 @@ import os
|
|
2 |
import zipfile
|
3 |
|
4 |
import hydra
|
5 |
-
from loguru import logger
|
6 |
import requests
|
|
|
7 |
from tqdm.rich import tqdm
|
8 |
|
9 |
|
|
|
2 |
import zipfile
|
3 |
|
4 |
import hydra
|
|
|
5 |
import requests
|
6 |
+
from loguru import logger
|
7 |
from tqdm.rich import tqdm
|
8 |
|
9 |
|