Skip to content

Commit 69d725c

Browse files
committed
Basic forward pass test for all registered models
1 parent 8da43e0 commit 69d725c

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

tests/__init__.py

Whitespace-only changes.

tests/test_inference.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import pytest
2+
import torch
3+
4+
from timm import list_models, create_model
5+
6+
7+
@pytest.mark.timeout(60)
8+
@pytest.mark.parametrize('model_name', list_models())
9+
@pytest.mark.parametrize('batch_size', [1])
10+
def test_model_forward(model_name, batch_size):
11+
"""Run a single forward pass with each model"""
12+
model = create_model(model_name, pretrained=False)
13+
model.eval()
14+
15+
inputs = torch.randn((batch_size, *model.default_cfg['input_size']))
16+
outputs = model(inputs)
17+
18+
assert outputs.shape[0] == batch_size
19+
assert not torch.isnan(outputs).any(), 'Output included NaNs'

0 commit comments

Comments
 (0)