Skip to content
This repository has been archived by the owner on Jul 2, 2021. It is now read-only.

Commit

Permalink
Merge pull request #823 from Hakuyume/chainer-ci
Browse files Browse the repository at this point in the history
pfnCI (pytest)
  • Loading branch information
yuyu2172 authored Mar 13, 2019
2 parents 975964d + 7d1ef5f commit 927b7e6
Show file tree
Hide file tree
Showing 32 changed files with 320 additions and 59 deletions.
167 changes: 167 additions & 0 deletions .pfnci/config.pbtxt
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
configs {
key: "chainercv.py2.stable"
value {
requirement {
cpu: 32
memory: 64
}
time_limit: {
seconds: 900
}
command: "sh .pfnci/tests.sh"
environment_variables {
key: "PYTHON"
value: "2"
}
environment_variables {
key: "CHAINER"
value: "5.2.0"
}
}
}

configs {
key: "chainercv.py3.stable"
value {
requirement {
cpu: 32
memory: 64
}
time_limit: {
seconds: 900
}
command: "sh .pfnci/tests.sh"
environment_variables {
key: "PYTHON"
value: "3"
}
environment_variables {
key: "CHAINER"
value: "5.2.0"
}
}
}

configs {
key: "chainercv.py2.latest"
value {
requirement {
cpu: 32
memory: 64
}
time_limit: {
seconds: 900
}
command: "sh .pfnci/tests.sh"
environment_variables {
key: "PYTHON"
value: "2"
}
environment_variables {
key: "CHAINER"
value: "6.0.0b2"
}
}
}

configs {
key: "chainercv.py3.latest"
value {
requirement {
cpu: 32
memory: 64
}
time_limit: {
seconds: 900
}
command: "sh .pfnci/tests.sh"
environment_variables {
key: "PYTHON"
value: "3"
}
environment_variables {
key: "CHAINER"
value: "6.0.0b2"
}
}
}

configs {
key: "chainercv.py2.stable.gpu"
value {
requirement {
cpu: 4
memory: 16
gpu: 1
}
command: "sh .pfnci/tests_gpu.sh"
environment_variables {
key: "PYTHON"
value: "2"
}
environment_variables {
key: "CHAINER"
value: "5.2.0"
}
}
}

configs {
key: "chainercv.py3.stable.gpu"
value {
requirement {
cpu: 4
memory: 16
gpu: 1
}
command: "sh .pfnci/tests_gpu.sh"
environment_variables {
key: "PYTHON"
value: "3"
}
environment_variables {
key: "CHAINER"
value: "5.2.0"
}
}
}

configs {
key: "chainercv.py2.latest.gpu"
value {
requirement {
cpu: 4
memory: 16
gpu: 1
}
command: "sh .pfnci/tests_gpu.sh"
environment_variables {
key: "PYTHON"
value: "2"
}
environment_variables {
key: "CHAINER"
value: "6.0.0b2"
}
}
}

configs {
key: "chainercv.py3.latest.gpu"
value {
requirement {
cpu: 4
memory: 16
gpu: 1
}
command: "sh .pfnci/tests_gpu.sh"
environment_variables {
key: "PYTHON"
value: "3"
}
environment_variables {
key: "CHAINER"
value: "6.0.0b2"
}
}
}
24 changes: 24 additions & 0 deletions .pfnci/tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#! /usr/bin/env sh
set -eux

TEMP=$(mktemp -d)
mount -t tmpfs tmpfs ${TEMP}/ -o size=100%
apt-get install -y --no-install-recommends unzip
gsutil -q cp gs://chainercv-pfn-public-ci/datasets-tiny.zip ${TEMP}/
unzip -q ${TEMP}/datasets-tiny.zip -d ${TEMP}/
rm ${TEMP}/datasets-tiny.zip

docker run --interactive --rm \
--volume $(pwd):/chainercv/ --workdir /chainercv/ \
--volume ${TEMP}/.chainer/:/root/.chainer/ \
--env MPLBACKEND=agg \
hakuyume/chainercv:chainer${CHAINER}-devel \
sh -ex << EOD
pip${PYTHON} install --user pytest-xdist
pip${PYTHON} install --user -e .
python${PYTHON} -m pytest --color=no -n $(nproc) \
-m 'not pfnci_skip and not gpu and not mpi' tests/
mpiexec -n 2 --allow-run-as-root \
python${PYTHON} -m pytest --color=no \
-m 'not pfnci_skip and not gpu and mpi' tests/
EOD
20 changes: 20 additions & 0 deletions .pfnci/tests_gpu.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#! /usr/bin/env sh
set -eux

TEMP=$(mktemp -d)
mount -t tmpfs tmpfs ${TEMP}/ -o size=100%
mkdir -p ${TEMP}/.chainer

docker run --runtime=nvidia --interactive --rm \
--volume $(pwd):/chainercv/ --workdir /chainercv/ \
--volume ${TEMP}/.chainer/:/root/.chainer/ \
--env MPLBACKEND=agg \
hakuyume/chainercv:chainer${CHAINER}-devel \
sh -ex << EOD
pip${PYTHON} install --user -e .
python${PYTHON} -m pytest --color=no \
-m 'not pfnci_skip and gpu and not mpi' tests/
mpiexec -n 2 --allow-run-as-root \
python${PYTHON} -m pytest --color=no \
-m 'not pfnci_skip and gpu and mpi' tests/
EOD
6 changes: 3 additions & 3 deletions chainercv/utils/image/read_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ def _read_image_cv2(file, dtype, color, alpha):
else:
color_option = cv2.IMREAD_GRAYSCALE

if isinstance(file, str):
img = cv2.imread(file, color_option)
else:
if hasattr(file, 'read'):
b = np.array(bytearray(file.read()))
img = cv2.imdecode(b, color_option)
else:
img = cv2.imread(file, color_option)

if img.ndim == 2:
# reshape (H, W) -> (1, H, W)
Expand Down
5 changes: 5 additions & 0 deletions chainercv/utils/testing/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
from chainer.testing import product # NOQA
from chainer.testing import product_dict # NOQA
from chainer.testing import run_module # NOQA

from chainercv.utils.testing.assertions import assert_is_bbox # NOQA
from chainercv.utils.testing.assertions import assert_is_bbox_dataset # NOQA
from chainercv.utils.testing.assertions import assert_is_detection_link # NOQA
Expand All @@ -11,3 +15,4 @@
from chainercv.utils.testing.assertions import assert_is_semantic_segmentation_link # NOQA
from chainercv.utils.testing.constant_stub_link import ConstantStubLink # NOQA
from chainercv.utils.testing.generate_random_bbox import generate_random_bbox # NOQA
from chainercv.utils.testing.parameterized import parameterize # NOQA
28 changes: 28 additions & 0 deletions chainercv/utils/testing/attr.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import unittest

from chainer.testing.attr import check_available
from chainer.testing.attr import gpu # NOQA
from chainer.testing.attr import slow # NOQA


try:
import pytest
pfnci_skip = pytest.mark.pfnci_skip

except ImportError:
from chainer.testing.attr import _dummy_callable
pfnci_skip = _dummy_callable


def mpi(f):
check_available()
import pytest

try:
import mpi4py.MPI # NOQA
available = True
except ImportError:
available = False

return unittest.skipUnless(
available, 'mpi4py is not installed')(pytest.mark.mpi(f))
9 changes: 9 additions & 0 deletions chainercv/utils/testing/constant_stub_link.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,15 @@ def __call__(self, *_):
tuple of :obj:`chainer.Variable`.
"""

# TODO(Hakuyume): Remove this fix when 'to_device' APIs is refactored.
# Fix for Chainer 6.x.
# https://github.com/chainer/chainer/issues/6244
for output in self._outputs:
if self.xp is np:
output.to_cpu()
else:
output.to_gpu()

if self._tuple:
return self._outputs
else:
Expand Down
31 changes: 31 additions & 0 deletions chainercv/utils/testing/parameterized.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import six

from chainer import testing


def parameterize(*params):
""":func:`chainer.testing.parameterize` for `pytest-xdist`.
:func:`chainer.testing.parameterize` cannot work with `pytest-xdist`
when the params contain functions (lambdas), classes, and random values.
This wrapper replaces the params with their indices
and restore the original params in :meth:`setUp`.
"""

def deco(cls):
setUp_orig = cls.setUp

def setUp(self):
param = params[self._chainercv_parameterize_index]
print('params: {}'.format(param))
for k, v in six.iteritems(param):
setattr(self, k, v)
setUp_orig(self)

cls.setUp = setUp

params_indices = [
{'_chainercv_parameterize_index': i} for i in range(len(params))]
return testing.parameterize(*params_indices)(cls)

return deco
3 changes: 1 addition & 2 deletions tests/evaluations_tests/test_eval_semantic_segmentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@

import numpy as np

from chainer import testing

from chainercv.evaluations import calc_semantic_segmentation_confusion
from chainercv.evaluations import calc_semantic_segmentation_iou
from chainercv.evaluations import eval_semantic_segmentation
from chainercv.utils import testing


@testing.parameterize(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@

import chainer
from chainer import testing
from chainer.testing import attr

from chainercv.experimental.links import PSPNetResNet101
from chainercv.experimental.links import PSPNetResNet50
from chainercv.utils import assert_is_semantic_segmentation_link
from chainercv.utils.testing import attr


@testing.parameterize(
Expand All @@ -33,6 +33,7 @@ def check_call(self):
self.assertEqual(y.shape, (2, self.n_class, 120, 160))

@attr.slow
@attr.pfnci_skip
def test_call_cpu(self):
self.check_call()

Expand All @@ -43,6 +44,7 @@ def test_call_gpu(self):
self.check_call()

@attr.slow
@attr.pfnci_skip
def test_predict_cpu(self):
assert_is_semantic_segmentation_link(self.link, self.n_class)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
import chainer
from chainer.datasets import TupleDataset
from chainer.iterators import SerialIterator
from chainer import testing
from chainer.testing import attr

from chainercv.extensions import DetectionVisReport
from chainercv.utils import generate_random_bbox
from chainercv.utils import testing

try:
import matplotlib # NOQA
Expand Down
Loading

0 comments on commit 927b7e6

Please sign in to comment.