Skip to content

Commit

Permalink
Merge pull request RangiLyu#289 from RangiLyu/refactor/code_quality
Browse files Browse the repository at this point in the history
[Refactor] code quality
  • Loading branch information
RangiLyu authored Jul 18, 2021
2 parents be08279 + 46a4962 commit 480ee5a
Show file tree
Hide file tree
Showing 156 changed files with 6,592 additions and 2,601 deletions.
11 changes: 11 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# This is an example .flake8 config, used when developing *Black* itself.
# Keep in sync with setup.cfg which is used for source packages.

[flake8]
ignore = W503, E203, E221, C901, C408, E741, C407, E741, B006, B007, B017, B950, C416
max-line-length = 88
max-complexity = 18
select = B,C,E,F,W,T4,B9
exclude = build
per-file-ignores =
**/__init__.py:F401,F403,E402
121 changes: 121 additions & 0 deletions .github/workflows/workflow.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
name: CI
on: [push, pull_request]

jobs:
linter:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Python 3.6
uses: actions/setup-python@v2
with:
python-version: 3.6
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install flake8==3.9.2 flake8-bugbear flake8-comprehensions isort==5.8.0
python -m pip install black==21.6b0
flake8 --version
- name: Lint
run: |
echo "Running isort"
isort --profile black .
echo "Running black"
black --check .
echo "Running flake8"
flake8 .
test_cpu:
runs-on: ubuntu-latest
strategy:
matrix:
torch: [1.6.0, 1.7.0, 1.8.0]
include:
- torch: 1.6.0
torchvision: 0.7.0
- torch: 1.7.0
torchvision: 0.8.1
- torch: 1.8.0
torchvision: 0.9.0
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Set up Python 3.6
uses: actions/setup-python@v2
with:
python-version: 3.6
- name: Install dependencies
run: |
python -m pip install -U pip
python -m pip install ninja opencv-python-headless onnx pytest-xdist codecov
python -m pip install torch==${{matrix.torch}}+cpu torchvision==${{matrix.torchvision}}+cpu -f https://download.pytorch.org/whl/torch_stable.html
python -m pip install Cython termcolor numpy tensorboard pycocotools matplotlib pyaml opencv-python tqdm pytorch-lightning torchmetrics codecov flake8 pytest
- name: Setup
run: rm -rf .eggs && python setup.py develop
- name: Run unittests and generate coverage report
run: |
coverage run --branch --source nanodet -m pytest tests/
coverage xml
coverage report -m
test_cuda:
runs-on: ubuntu-latest
env:
CUDA: 10.1.105-1
CUDA_SHORT: 10.1
UBUNTU_VERSION: ubuntu1804
strategy:
matrix:
torch: [1.6.0+cu101, 1.7.0+cu101, 1.8.0+cu101]
include:
- torch: 1.6.0+cu101
torchvision: 0.7.0+cu101
- torch: 1.7.0+cu101
torchvision: 0.8.1+cu101
- torch: 1.8.0+cu101
torchvision: 0.9.0+cu101
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Set up Python 3.6
uses: actions/setup-python@v2
with:
python-version: 3.6
- name: Install CUDA
run: |
export INSTALLER=cuda-repo-${UBUNTU_VERSION}_${CUDA}_amd64.deb
wget http://developer.download.nvidia.com/compute/cuda/repos/${UBUNTU_VERSION}/x86_64/${INSTALLER}
sudo dpkg -i ${INSTALLER}
wget https://developer.download.nvidia.com/compute/cuda/repos/${UBUNTU_VERSION}/x86_64/7fa2af80.pub
sudo apt-key add 7fa2af80.pub
sudo apt update -qq
sudo apt install -y cuda-${CUDA_SHORT/./-} cuda-cufft-dev-${CUDA_SHORT/./-}
sudo apt clean
export CUDA_HOME=/usr/local/cuda-${CUDA_SHORT}
export LD_LIBRARY_PATH=${CUDA_HOME}/lib64:${CUDA_HOME}/include:${LD_LIBRARY_PATH}
export PATH=${CUDA_HOME}/bin:${PATH}
- name: Install dependencies
run: |
python -m pip install -U pip
python -m pip install ninja opencv-python-headless onnx pytest-xdist codecov
python -m pip install torch==${{matrix.torch}} torchvision==${{matrix.torchvision}} -f https://download.pytorch.org/whl/torch_stable.html
python -m pip install Cython termcolor numpy tensorboard pycocotools matplotlib pyaml opencv-python tqdm pytorch-lightning torchmetrics codecov flake8 pytest
- name: Setup
run: |
rm -rf .eggs
python setup.py check -m -s
TORCH_CUDA_ARCH_LIST=7.0 pip install .
- name: Run unittests and generate coverage report
run: |
coverage run --branch --source nanodet -m pytest tests/
coverage xml
coverage report -m
- name: Upload coverage to Codecov
uses: codecov/[email protected]
if: matrix.torch == '1.8.0+cu101'
with:
file: ./coverage.xml
flags: unittests
env_vars: OS,PYTHON
name: codecov-umbrella
fail_ci_if_error: false
2 changes: 2 additions & 0 deletions .isort.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[tool.isort]
profile = "black"
26 changes: 26 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.5.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-docstring-first
- id: check-yaml
- id: debug-statements
- id: requirements-txt-fixer

- repo: https://github.com/pycqa/isort
rev: 5.8.0
hooks:
- id: isort
args: ["--profile", "black"]

- repo: https://github.com/psf/black
rev: 21.6b0
hooks:
- id: black

- repo: https://gitlab.com/pycqa/flake8
rev: 3.9.2
hooks:
- id: flake8
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Copyright 2020-2021 RangiLyu. All rights reserved.

Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
Expand Down
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ Model |Resolution|COCO mAP |Latency(ARM 4 Threads) | FLOPS | Par
:-------------:|:--------:|:-------:|:--------------------:|:----------:|:---------:|:-------:
NanoDet-m | 320*320 | 20.6 | **10.23ms** | **0.72G** | **0.95M** | **1.8MB(FP16)** | **980KB(INT8)**
NanoDet-m | 416*416 | 23.5 | 16.44ms | 1.2G | **0.95M** | **1.8MB(FP16)** | **980KB(INT8)**
NanoDet-m-1.5x | 320*320 | 23.5 | 13.53ms | 1.44G | 2.08M | 3.9MB(FP16) | 2MB(INT8)
NanoDet-m-1.5x | 416*416 | **26.8** | 21.53ms | 2.42G | 2.08M | 3.9MB(FP16) | 2MB(INT8)
NanoDet-m-1.5x | 320*320 | 23.5 | 13.53ms | 1.44G | 2.08M | 3.9MB(FP16) | 2MB(INT8)
NanoDet-m-1.5x | 416*416 | **26.8** | 21.53ms | 2.42G | 2.08M | 3.9MB(FP16) | 2MB(INT8)
NanoDet-g | 416*416 | 22.9 | Not Designed For ARM | 4.2G | 3.81M | 7.7MB(FP16) | 3.6MB(INT8)
YoloV3-Tiny | 416*416 | 16.6 | 37.6ms | 5.62G | 8.86M | 33.7MB
YoloV4-Tiny | 416*416 | 21.7 | 32.81ms | 6.96G | 6.06M | 23.0MB
Expand Down Expand Up @@ -222,15 +222,15 @@ NanoDet-RepVGG | RepVGG-A0 | 416*416 | 27.8 | 11.3G | 6.75M |
3. **Start training**

NanoDet is now using [pytorch lightning](https://github.com/PyTorchLightning/pytorch-lightning) for training.

For both single-GPU or multiple-GPUs, run:

```shell script
python tools/train.py CONFIG_FILE_PATH
```

For **Windows users**, if you have problems with the new lightning trainer, try to use tools/deprecated/train.py

<details>
<summary>follow this...</summary>

Expand All @@ -245,7 +245,7 @@ NanoDet-RepVGG | RepVGG-A0 | 416*416 | 27.8 | 11.3G | 6.75M |
```shell script
python -m torch.distributed.launch --nproc_per_node=GPU_NUM --master_port 29501 tools/deprecated/train.py CONFIG_FILE_PATH
```

</details>


Expand Down
4 changes: 2 additions & 2 deletions config/EfficientNet-Lite/nanodet-EfficientNet-Lite0_320.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ model:
loss_weight: 2.0
data:
train:
name: coco
name: CocoDataset
img_path: /coco/train2017
ann_path: /coco/annotations/instances_train2017.json
input_size: [320,320] #[w,h]
Expand All @@ -66,7 +66,7 @@ data:
saturation: [0.5, 1.2]
normalize: [[127.0, 127.0, 127.0], [128.0, 128.0, 128.0]]
val:
name: coco
name: CocoDataset
img_path: /coco/val2017
ann_path: /coco/annotations/instances_val2017.json
input_size: [320,320] #[w,h]
Expand Down
4 changes: 2 additions & 2 deletions config/EfficientNet-Lite/nanodet-EfficientNet-Lite1_416.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ model:
loss_weight: 2.0
data:
train:
name: coco
name: CocoDataset
img_path: /coco/train2017
ann_path: /coco/annotations/instances_train2017.json
input_size: [416,416] #[w,h]
Expand All @@ -67,7 +67,7 @@ data:
saturation: [0.5, 1.2]
normalize: [[127.0, 127.0, 127.0], [128.0, 128.0, 128.0]]
val:
name: coco
name: CocoDataset
img_path: /coco/val2017
ann_path: /coco/annotations/instances_val2017.json
input_size: [416,416] #[w,h]
Expand Down
4 changes: 2 additions & 2 deletions config/EfficientNet-Lite/nanodet-EfficientNet-Lite2_512.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ model:
loss_weight: 2.0
data:
train:
name: coco
name: CocoDataset
img_path: /coco/train2017
ann_path: /coco/annotations/instances_train2017.json
input_size: [512,512] #[w,h]
Expand All @@ -67,7 +67,7 @@ data:
saturation: [0.5, 1.2]
normalize: [[127.0, 127.0, 127.0], [128.0, 128.0, 128.0]]
val:
name: coco
name: CocoDataset
img_path: /coco/val2017
ann_path: /coco/annotations/instances_val2017.json
input_size: [512,512] #[w,h]
Expand Down
4 changes: 2 additions & 2 deletions config/RepVGG/nanodet-RepVGG-A0_416.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ model:
loss_weight: 2.0
data:
train:
name: coco
name: CocoDataset
img_path: /coco/train2017
ann_path: /coco/annotations/instances_train2017.json
input_size: [416,416] #[w,h]
Expand All @@ -63,7 +63,7 @@ data:
saturation: [0.5, 1.2]
normalize: [[103.53, 116.28, 123.675], [57.375, 57.12, 58.395]]
val:
name: coco
name: CocoDataset
img_path: /coco/val2017
ann_path: /coco/annotations/instances_val2017.json
input_size: [416,416] #[w,h]
Expand Down
4 changes: 2 additions & 2 deletions config/Transformer/nanodet-t.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ model:
loss_weight: 2.0
data:
train:
name: coco
name: CocoDataset
img_path: coco/train2017
ann_path: coco/annotations/instances_train2017.json
input_size: [320,320] #[w,h]
Expand All @@ -70,7 +70,7 @@ data:
saturation: [0.8, 1.2]
normalize: [[103.53, 116.28, 123.675], [57.375, 57.12, 58.395]]
val:
name: coco
name: CocoDataset
img_path: coco/val2017
ann_path: coco/annotations/instances_val2017.json
input_size: [320,320] #[w,h]
Expand Down
4 changes: 2 additions & 2 deletions config/nanodet-g.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ model:
loss_weight: 2.0
data:
train:
name: coco
name: CocoDataset
img_path: coco/train2017
ann_path: coco/annotations/instances_train2017.json
input_size: [416,416] #[w,h]
Expand All @@ -70,7 +70,7 @@ data:
saturation: [0.5, 1.2]
normalize: [[103.53, 116.28, 123.675], [57.375, 57.12, 58.395]]
val:
name: coco
name: CocoDataset
img_path: coco/val2017
ann_path: coco/annotations/instances_val2017.json
input_size: [416,416] #[w,h]
Expand Down
4 changes: 2 additions & 2 deletions config/nanodet-m-0.5x.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ model:
loss_weight: 2.0
data:
train:
name: coco
name: CocoDataset
img_path: coco/train2017
ann_path: coco/annotations/instances_train2017.json
input_size: [320,320] #[w,h]
Expand All @@ -65,7 +65,7 @@ data:
saturation: [0.5, 1.2]
normalize: [[103.53, 116.28, 123.675], [57.375, 57.12, 58.395]]
val:
name: coco
name: CocoDataset
img_path: coco/val2017
ann_path: coco/annotations/instances_val2017.json
input_size: [320,320] #[w,h]
Expand Down
4 changes: 2 additions & 2 deletions config/nanodet-m-1.5x-416.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ model:
loss_weight: 2.0
data:
train:
name: coco
name: CocoDataset
img_path: coco/train2017
ann_path: coco/annotations/instances_train2017.json
input_size: [416,416] #[w,h]
Expand All @@ -65,7 +65,7 @@ data:
saturation: [0.5, 1.2]
normalize: [[103.53, 116.28, 123.675], [57.375, 57.12, 58.395]]
val:
name: coco
name: CocoDataset
img_path: coco/val2017
ann_path: coco/annotations/instances_val2017.json
input_size: [416,416] #[w,h]
Expand Down
4 changes: 2 additions & 2 deletions config/nanodet-m-1.5x.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ model:
loss_weight: 2.0
data:
train:
name: coco
name: CocoDataset
img_path: coco/train2017
ann_path: coco/annotations/instances_train2017.json
input_size: [320,320] #[w,h]
Expand All @@ -65,7 +65,7 @@ data:
saturation: [0.5, 1.2]
normalize: [[103.53, 116.28, 123.675], [57.375, 57.12, 58.395]]
val:
name: coco
name: CocoDataset
img_path: coco/val2017
ann_path: coco/annotations/instances_val2017.json
input_size: [320,320] #[w,h]
Expand Down
4 changes: 2 additions & 2 deletions config/nanodet-m-416.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ model:
loss_weight: 2.0
data:
train:
name: coco
name: CocoDataset
img_path: coco/train2017
ann_path: coco/annotations/instances_train2017.json
input_size: [416,416] #[w,h]
Expand All @@ -65,7 +65,7 @@ data:
saturation: [0.5, 1.2]
normalize: [[103.53, 116.28, 123.675], [57.375, 57.12, 58.395]]
val:
name: coco
name: CocoDataset
img_path: coco/val2017
ann_path: coco/annotations/instances_val2017.json
input_size: [416,416] #[w,h]
Expand Down
Loading

0 comments on commit 480ee5a

Please sign in to comment.