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

test FCISResNet101 loss #784

Merged
merged 4 commits into from
Feb 14, 2019
Merged
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
10 changes: 5 additions & 5 deletions chainercv/experimental/links/model/fcis/fcis.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def n_class(self):
# Total number of classes including the background.
return self.head.n_class

def __call__(self, x, scale=1.):
def __call__(self, x, scales=None):
"""Forward FCIS.

Scaling paramter :obj:`scale` is used by RPN to determine the
Expand All @@ -112,8 +112,8 @@ def __call__(self, x, scale=1.):

Args:
x (~chainer.Variable): 4D image variable.
scale (float): Amount of scaling applied to the raw image
during preprocessing.
scales (tuple of floats): Amount of scaling applied to each input
image during preprocessing.

Returns:
Variable, Variable, Variable, array, array:
Expand All @@ -136,7 +136,7 @@ def __call__(self, x, scale=1.):
# Feature Extractor
rpn_features, roi_features = self.extractor(x)
rpn_locs, rpn_scores, rois, roi_indices, anchor = self.rpn(
rpn_features, img_size, scale)
rpn_features, img_size, scales)
roi_ag_seg_scores, roi_ag_locs, roi_cls_scores, rois, roi_indices = \
self.head(roi_features, rois, roi_indices, img_size)
return roi_ag_seg_scores, roi_ag_locs, roi_cls_scores, \
Expand Down Expand Up @@ -266,7 +266,7 @@ def predict(self, imgs):
img_var = chainer.Variable(self.xp.array(img[None]))
scale = img_var.shape[3] / size[1]
roi_ag_seg_scores, _, roi_cls_scores, bboxes, _ = \
self.__call__(img_var, scale)
self.__call__(img_var, scales=[scale])

# We are assuming that batch size is 1.
roi_ag_seg_score = chainer.cuda.to_cpu(roi_ag_seg_scores.array)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ def test_predict_gpu(self):
{'in_shape': (3, 300, 600), 'expected_shape': (3, 200, 400)},
{'in_shape': (3, 600, 900), 'expected_shape': (3, 200, 300)}
)
class TestFasterRCNNPrepare(unittest.TestCase):
class TestFCISPrepare(unittest.TestCase):

min_size = 200
max_size = 400
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,16 @@
import unittest

import chainer
from chainer.backends import cuda
from chainer import testing
from chainer.testing import attr

from chainercv.experimental.links import FCISResNet101
from chainercv.experimental.links.model.fcis import FCISTrainChain
from chainercv.utils import mask_to_bbox

from tests.experimental_tests.links_tests.model_tests.fcis_tests.test_fcis \
import _random_array


@testing.parameterize(
Expand Down Expand Up @@ -81,6 +87,49 @@ def test_call_gpu(self):
self.check_call()


class TestFCISResNet101Loss(unittest.TestCase):

B = 1
n_fg_class = 20
n_bbox = 3
n_anchor = 9
n_train_post_nms = 12
n_test_post_nms = 8

def setUp(self):
proposal_creator_params = {
'n_train_post_nms': self.n_train_post_nms,
'n_test_post_nms': self.n_test_post_nms,
}
self.model = FCISTrainChain(
FCISResNet101(
self.n_fg_class, pretrained_model=None, iter2=False,
proposal_creator_params=proposal_creator_params))

self.masks = np.random.randint(
0, 2, size=(1, self.n_bbox, 600, 800)).astype(np.bool)
self.labels = np.random.randint(
0, self.n_fg_class, size=(1, self.n_bbox)).astype(np.int32)
self.imgs = _random_array(np, (1, 3, 600, 800))
self.scale = np.array(1.)

def check_call(self, model, imgs, masks, labels, scale):
bboxes = mask_to_bbox(masks[0])[None]
loss = model(imgs, masks, labels, bboxes, scale)
self.assertEqual(loss.shape, ())

def test_call_cpu(self):
self.check_call(
self.model, self.imgs, self.masks, self.labels, self.scale)

@attr.gpu
def test_call_gpu(self):
self.model.to_gpu()
self.check_call(
self.model, cuda.to_gpu(self.imgs),
self.masks, self.labels, self.scale)


@testing.parameterize(*testing.product({
'n_fg_class': [None, 10, 20, 80],
'anchor_scales': [(8, 16, 32), (4, 8, 16, 32)],
Expand Down