From 16f1f77b41484c21e349910b81c31e391d099f41 Mon Sep 17 00:00:00 2001 From: Mike Date: Wed, 6 May 2020 23:21:50 -0400 Subject: [PATCH 1/4] Add a test workflow for github actions --- .github/workflows/tests.yml | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 .github/workflows/tests.yml diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 00000000..2d75edff --- /dev/null +++ b/.github/workflows/tests.yml @@ -0,0 +1,31 @@ +name: Python tests + +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] + +jobs: + test: + name: Run tests on ${{ matrix.os }} with Python ${{ matrix.python }} + strategy: + matrix: + os: [ubuntu-latest, macOS-latest] + python: ['3.8', '3.7'] + runs-on: ${{ matrix.os }} + + steps: + - uses: actions/checkout@v2 + - name: Set up Python ${{ matrix.python }} + uses: actions/setup-python@v1 + with: + python-version: ${{ matrix.python }} + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install pytest + if [ -f requirements.txt ]; then pip install -r requirements.txt; fi + - name: Run tests + run: | + pytest From 8da43e06171c5d796dc4b518412e6ea146dee421 Mon Sep 17 00:00:00 2001 From: michal Date: Thu, 7 May 2020 00:20:34 -0400 Subject: [PATCH 2/4] Install extra dependencies required by some models and log test durations --- .github/workflows/tests.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 2d75edff..d035f3b2 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -24,8 +24,10 @@ jobs: - name: Install dependencies run: | python -m pip install --upgrade pip - pip install pytest + pip install pytest pytest-timeout if [ -f requirements.txt ]; then pip install -r requirements.txt; fi + pip install scipy + pip install git+https://github.com/mapillary/inplace_abn.git@v1.0.11 - name: Run tests run: | - pytest + pytest -vv --durations=0 ./tests From 69d725c9fe92efed62e954d31e95653fb091a797 Mon Sep 17 00:00:00 2001 From: michal Date: Thu, 7 May 2020 00:20:58 -0400 Subject: [PATCH 3/4] Basic forward pass test for all registered models --- tests/__init__.py | 0 tests/test_inference.py | 19 +++++++++++++++++++ 2 files changed, 19 insertions(+) create mode 100644 tests/__init__.py create mode 100644 tests/test_inference.py diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/tests/test_inference.py b/tests/test_inference.py new file mode 100644 index 00000000..75b8d445 --- /dev/null +++ b/tests/test_inference.py @@ -0,0 +1,19 @@ +import pytest +import torch + +from timm import list_models, create_model + + +@pytest.mark.timeout(60) +@pytest.mark.parametrize('model_name', list_models()) +@pytest.mark.parametrize('batch_size', [1]) +def test_model_forward(model_name, batch_size): + """Run a single forward pass with each model""" + model = create_model(model_name, pretrained=False) + model.eval() + + inputs = torch.randn((batch_size, *model.default_cfg['input_size'])) + outputs = model(inputs) + + assert outputs.shape[0] == batch_size + assert not torch.isnan(outputs).any(), 'Output included NaNs' From 8c77f14cae7d974abb35a5c9f206274da49970ed Mon Sep 17 00:00:00 2001 From: michal Date: Thu, 7 May 2020 01:09:16 -0400 Subject: [PATCH 4/4] Install cpu version of torch on ubuntu --- .github/workflows/tests.yml | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index d035f3b2..68fa4741 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -12,7 +12,9 @@ jobs: strategy: matrix: os: [ubuntu-latest, macOS-latest] - python: ['3.8', '3.7'] + python: ['3.8'] + torch: ['1.5.0'] + torchvision: ['0.6.0'] runs-on: ${{ matrix.os }} steps: @@ -21,10 +23,18 @@ jobs: uses: actions/setup-python@v1 with: python-version: ${{ matrix.python }} - - name: Install dependencies + - name: Install testing dependencies run: | python -m pip install --upgrade pip pip install pytest pytest-timeout + - name: Install torch on mac + if: startsWith(matrix.os, 'macOS') + run: pip install torch==${{ matrix.torch }} torchvision==${{ matrix.torchvision }} + - name: Install torch on ubuntu + if: startsWith(matrix.os, 'ubuntu') + run: pip install torch==${{ matrix.torch }}+cpu torchvision==${{ matrix.torchvision }}+cpu -f https://download.pytorch.org/whl/torch_stable.html + - name: Install requirements + run: | if [ -f requirements.txt ]; then pip install -r requirements.txt; fi pip install scipy pip install git+https://github.com/mapillary/inplace_abn.git@v1.0.11