Skip to content

Commit

Permalink
add config unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
RangiLyu committed Jun 20, 2021
1 parent 3eb77bb commit be551a6
Show file tree
Hide file tree
Showing 6 changed files with 98 additions and 3 deletions.
40 changes: 40 additions & 0 deletions .github/workflows/workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,43 @@ jobs:
black --check .
echo "Running flake8"
flake8 .
test_cpu:
runs-on: ubuntu-latest
strategy:
matrix:
torch: [1.6, 1.7, 1.8]
include:
- torch: 1.6
torchvision: 0.7
- torch: 1.7
torchvision: 0.8
- torch: 1.8
torchvision: 0.9
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Set up Python 3.6
uses: actions/setup-python@v2
with:
python-version: 3.6
- name: Cache dependencies
uses: actions/cache@v2
with:
path: |
${{ env.pythonLocation }}/lib/python3.6/site-packages
~/.torch
key: ${{ runner.os }}-torch${{ matrix.torch }}-${{ hashFiles('setup.py') }}-20210420
- name: Install dependencies
run: |
python -m pip install -U pip
python -m pip install ninja opencv-python-headless onnx pytest-xdist
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 develop
- name: Run unittests and generate coverage report
run: |
coverage run --branch --source nanodet -m pytest tests/
coverage xml
coverage report -m
1 change: 0 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ repos:
- id: check-docstring-first
- id: check-yaml
- id: debug-statements
- id: name-tests-test
- id: requirements-txt-fixer

- repo: https://github.com/pycqa/isort
Expand Down
3 changes: 2 additions & 1 deletion nanodet/util/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from .flops_counter import get_model_complexity_info
from .logger import AverageMeter, Logger, MovingAverage
from .misc import images_to_levels, multi_apply, unmap
from .path import mkdir
from .path import collect_files, mkdir
from .rank_filter import rank_filter
from .scatter_gather import gather_results, scatter_kwargs
from .util_mixins import NiceRepr
Expand Down Expand Up @@ -36,4 +36,5 @@
"NiceRepr",
"Visualizer",
"overlay_bbox_cv",
"collect_files",
]
2 changes: 1 addition & 1 deletion nanodet/util/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
cfg.model = CfgNode()
cfg.model.arch = CfgNode(new_allowed=True)
cfg.model.arch.backbone = CfgNode(new_allowed=True)
cfg.model.arch.neck = CfgNode(new_allowed=True)
cfg.model.arch.fpn = CfgNode(new_allowed=True)
cfg.model.arch.head = CfgNode(new_allowed=True)

# DATASET related params
Expand Down
11 changes: 11 additions & 0 deletions nanodet/util/path.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,14 @@
def mkdir(path):
if not os.path.exists(path):
os.makedirs(path)


def collect_files(path, exts):
file_paths = []
for maindir, subdir, filename_list in os.walk(path):
for filename in filename_list:
file_path = os.path.join(maindir, filename)
ext = os.path.splitext(file_path)[1]
if ext in exts:
file_paths.append(file_path)
return file_paths
44 changes: 44 additions & 0 deletions tests/test_configs/test_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# 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 os.path import dirname, exists, join

from nanodet.model.arch import build_model
from nanodet.util import cfg, collect_files, load_config


def test_config_files():
root_path = join(dirname(__file__), "../..")
cfg_folder = join(root_path, "config")
if not exists(cfg_folder):
raise FileNotFoundError("Cannot find config folder.")

cfg_paths = collect_files(cfg_folder, [".yml", ".yaml"])
for cfg_path in cfg_paths:
print(f"Start testing {cfg_path}")
config = copy.deepcopy(cfg)

# test load cfg
load_config(config, cfg_path)
assert "save_dir" in config
assert "model" in config
assert "data" in config
assert "device" in config
assert "schedule" in config
assert "log" in config

# test build model
model = build_model(config.model)
assert config.model.arch.name == model.__class__.__name__

0 comments on commit be551a6

Please sign in to comment.