Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Refactor] code quality #289

Merged
merged 67 commits into from
Jul 18, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
9530562
isort
RangiLyu Jun 14, 2021
a2f3818
format
RangiLyu Jun 14, 2021
b0cdb3c
lint
RangiLyu Jun 19, 2021
4f3d5a1
add flake8 config
RangiLyu Jun 19, 2021
56e1ac3
lint
RangiLyu Jun 19, 2021
557ff0c
add isort config
RangiLyu Jun 19, 2021
c266ebb
add pre-commit
RangiLyu Jun 19, 2021
b7d8be8
format
RangiLyu Jun 19, 2021
4546163
fix string
RangiLyu Jun 19, 2021
f659c45
update
RangiLyu Jun 19, 2021
9e496a9
change to black code style
RangiLyu Jun 19, 2021
36351ee
add CI
RangiLyu Jun 19, 2021
0f04abe
isort style
RangiLyu Jun 19, 2021
3eb77bb
extend flake8
RangiLyu Jun 19, 2021
be551a6
add config unit test
RangiLyu Jun 20, 2021
74ef816
add CUDA test
RangiLyu Jun 20, 2021
1c4db4c
update workflow
RangiLyu Jun 20, 2021
f259409
fix torchvision version
RangiLyu Jun 20, 2021
5bac8d8
add conv unit test
RangiLyu Jun 20, 2021
64dcc39
remove cache
RangiLyu Jun 20, 2021
3490ee0
add repvgg conv test
RangiLyu Jun 20, 2021
ebae7e7
add nms unit test
RangiLyu Jun 26, 2021
9467bc7
add scale unit test
RangiLyu Jun 26, 2021
db58ccf
add test data
RangiLyu Jun 26, 2021
9f28958
fix workflow
RangiLyu Jun 26, 2021
4c5dacf
fix workflow
RangiLyu Jun 26, 2021
5d82473
fix workflow
RangiLyu Jun 26, 2021
a51017b
add transformer unit test
RangiLyu Jun 26, 2021
0b858f7
add init_weights unit test
RangiLyu Jun 26, 2021
035a7aa
add norm unit test
RangiLyu Jun 26, 2021
65ce4b6
add iou loss test and fix bug
RangiLyu Jun 26, 2021
a79f4b1
add gfl loss unit test
RangiLyu Jun 26, 2021
85e4007
fix pop
RangiLyu Jun 26, 2021
f2d8be7
iou coverage
RangiLyu Jun 26, 2021
51afd92
add shufflenet efficientnet unit test
RangiLyu Jun 26, 2021
fd5f825
fix lint
RangiLyu Jun 26, 2021
fc6764f
add resnet unit test
RangiLyu Jun 27, 2021
b5a65f0
add repvgg backbone unit test
RangiLyu Jul 4, 2021
95c67ff
add repvgg backbone unit test
RangiLyu Jul 4, 2021
a7858ac
add mbv2 backbone unit test
RangiLyu Jul 4, 2021
60bfd89
add csp backbone unit test
RangiLyu Jul 4, 2021
5a69f88
add csp backbone unit test
RangiLyu Jul 4, 2021
0c3906b
add csp backbone unit test
RangiLyu Jul 4, 2021
effea88
add ghostnet backbone unit test
RangiLyu Jul 4, 2021
25d609e
add pytorch lightning task unit test
RangiLyu Jul 4, 2021
89cb812
update flake8
RangiLyu Jul 4, 2021
c3ec3b2
fix pt1.6
RangiLyu Jul 4, 2021
3c3118e
add trainer unit test
RangiLyu Jul 4, 2021
739f844
use tmp dir
RangiLyu Jul 4, 2021
73ef835
replace dataset name in cfg
RangiLyu Jul 4, 2021
6eb4ce9
add cocodataset unit test
RangiLyu Jul 4, 2021
c9d5958
test collate
RangiLyu Jul 10, 2021
55d2ba5
add xml dataset unit test
RangiLyu Jul 10, 2021
aa82901
change build evaluator
RangiLyu Jul 10, 2021
a8a9bbd
add evaluator unit test
RangiLyu Jul 10, 2021
75f3f64
add transform unit test
RangiLyu Jul 11, 2021
47d4663
add GFL head unit test
RangiLyu Jul 11, 2021
6f24f42
add flops unit test
RangiLyu Jul 11, 2021
b8cb8b3
add coco instance seg unit test
RangiLyu Jul 17, 2021
e7b54cb
add nanodet head unit test
RangiLyu Jul 17, 2021
b8f8631
add fpn unit test
RangiLyu Jul 17, 2021
6c1b473
add pan unit test
RangiLyu Jul 17, 2021
00843f3
add pan unit test
RangiLyu Jul 17, 2021
b48e619
add tan unit test
RangiLyu Jul 17, 2021
5c06d4b
fix unit test
RangiLyu Jul 17, 2021
deaafc2
merge master
RangiLyu Jul 17, 2021
46a4962
Merge pull request #260 from RangiLyu/unit_test
RangiLyu Jul 18, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
isort
  • Loading branch information
RangiLyu committed Jun 14, 2021
commit 953056277c33201ec731db6bbfc702beee51c0c8
11 changes: 6 additions & 5 deletions demo/demo.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import cv2
import argparse
import os
import time

import cv2
import torch
import argparse
from nanodet.util import cfg, load_config, Logger
from nanodet.model.arch import build_model
from nanodet.util import load_model_weight

from nanodet.data.transform import Pipeline
from nanodet.model.arch import build_model
from nanodet.util import Logger, cfg, load_config, load_model_weight
from nanodet.util.path import mkdir

image_ext = ['.jpg', '.jpeg', '.webp', '.bmp', '.png']
Expand Down
7 changes: 3 additions & 4 deletions demo_mnn/python/demo_mnn.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,14 @@
'''

import argparse
from pathlib import Path
from abc import ABCMeta, abstractmethod
from pathlib import Path

import cv2
import numpy as np
import matplotlib.pyplot as plt
from tqdm import tqdm
import numpy as np
from scipy.special import softmax

from tqdm import tqdm

# Copy from nanodet/util/visualization.py
_COLORS = np.array(
Expand Down
8 changes: 4 additions & 4 deletions demo_ncnn/python/demo_ncnn.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,14 @@
'''

import argparse
from pathlib import Path
from abc import ABCMeta, abstractmethod
from pathlib import Path

import cv2
import numpy as np
import matplotlib.pyplot as plt
from tqdm import tqdm
import numpy as np
from scipy.special import softmax

from tqdm import tqdm

# Copy from nanodet/util/visualization.py
_COLORS = np.array(
Expand Down Expand Up @@ -427,6 +426,7 @@ def infer_image(self, img_input):
class NanoDetTorch(NanoDetABC):
def __init__(self, model_path, cfg_path, *args, **kwargs):
import torch

from nanodet.model.arch import build_model
from nanodet.util import Logger, cfg, load_config, load_model_weight

Expand Down
18 changes: 15 additions & 3 deletions nanodet/data/collate.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@
import torch
import torch.nn.functional as F
# Copyright 2021 RangiLyu.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import re
from torch._six import container_abcs, string_classes, int_classes

import torch
from torch._six import container_abcs, int_classes, string_classes

np_str_obj_array_pattern = re.compile(r'[SaUO]')

Expand Down
15 changes: 15 additions & 0 deletions nanodet/data/dataset/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,19 @@
# Copyright 2021 RangiLyu.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import copy

from .coco import CocoDataset
from .xml_dataset import XMLDataset

Expand Down
17 changes: 16 additions & 1 deletion nanodet/data/dataset/base.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,22 @@
# Copyright 2021 RangiLyu.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from abc import ABCMeta, abstractmethod
import torch

import numpy as np
from torch.utils.data import Dataset

from ..transform import Pipeline


Expand Down
20 changes: 18 additions & 2 deletions nanodet/data/dataset/coco.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,24 @@
# Copyright 2021 RangiLyu.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import os
import torch
import numpy as np

import cv2
import numpy as np
import torch
from pycocotools.coco import COCO

from .base import BaseDataset


Expand Down
27 changes: 20 additions & 7 deletions nanodet/data/dataset/xml_dataset.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,25 @@
# Copyright 2021 RangiLyu.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import logging
import os
import torch
import numpy as np
import cv2
import time
import logging
from collections import defaultdict
import xml.etree.ElementTree as ET
from collections import defaultdict

from pycocotools.coco import COCO

from .coco import CocoDataset


Expand All @@ -21,7 +34,7 @@ def get_file_list(path, type='.xml'):
return file_names


class COCO_XML(COCO):
class CocoXML(COCO):

def __init__(self, annotation):
"""
Expand Down Expand Up @@ -121,7 +134,7 @@ def get_data_info(self, ann_path):
]
"""
coco_dict = self.xml_to_coco(ann_path)
self.coco_api = COCO_XML(coco_dict)
self.coco_api = CocoXML(coco_dict)
self.cat_ids = sorted(self.coco_api.getCatIds())
self.cat2label = {cat_id: i for i, cat_id in enumerate(self.cat_ids)}
self.cats = self.coco_api.loadCats(self.cat_ids)
Expand Down
15 changes: 14 additions & 1 deletion nanodet/data/transform/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,15 @@
# Copyright 2021 RangiLyu.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from .pipeline import Pipeline
from .pipeline import Pipeline
19 changes: 17 additions & 2 deletions nanodet/data/transform/color.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,22 @@
import numpy as np
import cv2
# Copyright 2021 RangiLyu.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import random

import cv2
import numpy as np


def random_brightness(img, delta):
img += random.uniform(-delta, delta)
Expand Down
19 changes: 17 additions & 2 deletions nanodet/data/transform/pipeline.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,22 @@
from .warp import warp_and_resize
from .color import color_aug_and_norm
# Copyright 2021 RangiLyu.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import functools

from .color import color_aug_and_norm
from .warp import warp_and_resize


class Pipeline:
def __init__(self,
Expand Down
38 changes: 21 additions & 17 deletions nanodet/data/transform/warp.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,31 @@
# Copyright 2021 RangiLyu.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import math
import random
import numpy as np

import cv2
import math
import numpy as np


def get_flip_matrix(prob=0.5):
F = np.eye(3)
if random.random() < prob:
F[0, 0] = -1
return F


def get_perspective_matrix(perspective=0):
"""

Expand Down Expand Up @@ -36,8 +53,7 @@ def get_rotation_matrix(degree=0):
def get_scale_matrix(ratio=(1, 1)):
"""

:param width_ratio:
:param height_ratio:
:param ratio:
"""
Scl = np.eye(3)
scale = random.uniform(*ratio)
Expand Down Expand Up @@ -114,6 +130,7 @@ def get_resize_matrix(raw_shape, dst_shape, keep_ratio):
Rs[1, 1] *= d_h / r_h
return Rs


def warp_and_resize(meta, warp_kwargs, dst_shape, keep_ratio=True):
# TODO: background, type
raw_img = meta['img']
Expand Down Expand Up @@ -204,16 +221,3 @@ def warp_boxes(boxes, M, width, height):
# xy[:, [0, 2]] = xy[:, [0, 2]].clip(0, width)
# xy[:, [1, 3]] = xy[:, [1, 3]].clip(0, height)
# return xy













14 changes: 14 additions & 0 deletions nanodet/evaluator/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
# Copyright 2021 RangiLyu.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from .coco_detection import CocoDetectionEvaluator


Expand Down
20 changes: 17 additions & 3 deletions nanodet/evaluator/coco_detection.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,22 @@
import pycocotools.coco as coco
from pycocotools.cocoeval import COCOeval
# Copyright 2021 RangiLyu.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import copy
import json
import os
import copy

from pycocotools.cocoeval import COCOeval


def xyxy2xywh(bbox):
Expand Down
Loading