Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion gluonfr/model_zoo/attention_net.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ def get_attention_net(classes, num_layers, **kwargs):
ptr, modules = attention_net_spec[num_layers]
assert len(ptr) == len(modules) == 3
p, t, r = ptr
net = AttentionNet(classes, modules, p, t, r, **kwargs)
net = AttentionNetFace(classes, modules, p, t, r, **kwargs)
return net


Expand Down
4 changes: 4 additions & 0 deletions tests/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# This is Gluon-Face test module.

We use pytest as our test runner
and will use Jenkins+Github as CI.
44 changes: 44 additions & 0 deletions tests/unittests/common.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# -*- coding: utf-8 -*-
# @Author : PistonYang(pistonyang@gmail.com)


import mxnet as mx
import functools


def try_gpu(gpu_id=0):
"""Try execute on gpu, if not fallback to cpu"""

def test_helper(orig_test):
@functools.wraps(orig_test)
def test_wapper(*args, **kwargs):
try:
a = mx.nd.zeros((1,), ctx=mx.gpu(gpu_id))
ctx = mx.gpu(gpu_id)
except Exception:
ctx = mx.cpu()
with ctx:
orig_test(*args, **kwargs)

return test_wapper

return test_helper


def try_cpu(cpu_id=0):
"""Try execute on gpu, if not fallback to cpu"""

def test_helper(orig_test):
@functools.wraps(orig_test)
def test_wapper(*args, **kwargs):
try:
a = mx.nd.zeros((1,), ctx=mx.cpu(cpu_id))
ctx = mx.gpu(cpu_id)
except Exception:
ctx = mx.cpu(0)
with ctx:
orig_test(*args, **kwargs)

return test_wapper

return test_helper
38 changes: 38 additions & 0 deletions tests/unittests/test_basic_block.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# -*- coding: utf-8 -*-
# @Author : PistonYang(pistonyang@gmail.com)

import pytest
import mxnet as mx
from mxnet import nd
from mxnet.gluon import nn
from gluonfr.nn.basic_blocks import FrBase
from tests.unittests.common import try_gpu


class Model(FrBase):
def __init__(self, embedding_size=1, weight_norm=False, feature_norm=False,
need_cls_layer=True):
super(Model, self).__init__(1, embedding_size, weight_norm, feature_norm, need_cls_layer)
self.features = nn.HybridSequential()
self.features.add(
nn.Conv2D(16, 3, 1, 1, use_bias=False),
nn.BatchNorm(),
nn.Dense(embedding_size, use_bias=False),
nn.BatchNorm(center=False, scale=False),
)


@pytest.fixture(params=[[16, False, False, False],
[16, True, True, False],
[16, True, True, True]])
def get_model(request):
return Model(*request.param)


@try_gpu(0)
def test_model(get_model):
ctx = mx.context.current_context()
x = nd.random.normal(shape=(2, 3, 112, 112), ctx=ctx)
model = get_model
model.initialize(ctx=ctx)
model(x)
5 changes: 5 additions & 0 deletions tests/unittests/test_data_dataloader.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# -*- coding: utf-8 -*-
# @Author : PistonYang(pistonyang@gmail.com)

"""No additional Dataloader to test"""
pass
55 changes: 0 additions & 55 deletions tests/unittests/test_data_dataset.py

This file was deleted.

43 changes: 43 additions & 0 deletions tests/unittests/test_data_datasets.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# -*- coding: utf-8 -*-
# @Author : PistonYang(pistonyang@gmail.com)

import pytest
import numpy as np
from gluonfr.data.dataset import FRValDataset, FRTrainRecordDataset

train_sets = ['vgg', 'webface', 'emore']
val_sets = ['agedb_30', 'calfw', 'cfp_ff', 'cfp_fp', 'cplfw', 'lfw']


def parse_sets(datasets):
return [[dataset] for dataset in datasets]


@pytest.fixture(params=parse_sets(train_sets))
def get_train_datasets(request):
dt = FRTrainRecordDataset(*request.param)
return dt


@pytest.fixture(params=parse_sets(val_sets))
def get_val_datasets(request):
dt = FRValDataset(*request.param)
return dt


def test_train_datasets(get_train_datasets):
dt = get_train_datasets
for _ in range(10):
index = np.random.randint(0, len(dt))
img, label = dt[index]
assert img.shape == (112, 112, 3)
assert type(label) is float


def test_val_datasets(get_val_datasets):
dt = get_val_datasets
for _ in range(10):
index = np.random.randint(0, len(dt))
imgs, label = dt[index]
assert imgs[0].shape == imgs[1].shape == (112, 112, 3)
assert label in (0, 1)
4 changes: 4 additions & 0 deletions tests/unittests/test_loss.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# -*- coding: utf-8 -*-
# @Author : PistonYang(pistonyang@gmail.com)
"""loss test please look at our examples."""
pass
18 changes: 18 additions & 0 deletions tests/unittests/test_model_zoo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# -*- coding: utf-8 -*-
# @Author : PistonYang(pistonyang@gmail.com)

import mxnet as mx
from gluonfr.model_zoo.model_zoo import *
from tests.unittests.common import try_gpu


@try_gpu(0)
def test_model_zoo():
ctx = mx.context.current_context()
models = get_model_list()
data = mx.random.normal(shape=(2, 3, 112, 112), ctx=ctx)
for model_name in models:
model = get_model(model_name, classes=10, weight_norm=True, feature_norm=True)
model.initialize(ctx=ctx)
model(data)
mx.nd.waitall()