Skip to content

Commit

Permalink
Merge 095a94d into ee78ff1
Browse files Browse the repository at this point in the history
  • Loading branch information
knorth55 committed Jul 16, 2019
2 parents ee78ff1 + 095a94d commit 3b3e6da
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 30 deletions.
14 changes: 8 additions & 6 deletions chainer/functions/pooling/roi_average_align_2d.py
Expand Up @@ -15,6 +15,7 @@
# \roi align operator described in Mask RCNN
# -----------------------------------------------------------------------------

import numbers
import numpy
import six

Expand Down Expand Up @@ -103,23 +104,24 @@ class ROIAverageAlign2D(function.Function):

def __init__(self, outsize, spatial_scale, sampling_ratio=None):
outh, outw = _pair(outsize)
if not (isinstance(outh, int) and outh > 0):
if not (isinstance(outh, numbers.Integral) and outh > 0):
raise TypeError(
'outsize[0] must be positive integer: {}, {}'
.format(type(outh), outh))
if not (isinstance(outw, int) and outw > 0):
if not (isinstance(outw, numbers.Integral) and outw > 0):
raise TypeError(
'outsize[1] must be positive integer: {}, {}'
.format(type(outw), outw))
if isinstance(spatial_scale, int):
if isinstance(spatial_scale, numbers.Integral):
spatial_scale = float(spatial_scale)
if not (isinstance(spatial_scale, float) and spatial_scale > 0):
if not (isinstance(spatial_scale, numbers.Real) and
spatial_scale > 0):
raise TypeError(
'spatial_scale must be a positive float number: {}, {}'
.format(type(spatial_scale), spatial_scale))
sampling_ratio = _pair(sampling_ratio)
if not all((isinstance(s, int) and s >= 1) or s is None
for s in sampling_ratio):
if not all((isinstance(s, numbers.Integral) and s >= 1) or
s is None for s in sampling_ratio):
raise TypeError(
'sampling_ratio must be integer >= 1 or a pair of it: {}'
.format(sampling_ratio))
Expand Down
10 changes: 6 additions & 4 deletions chainer/functions/pooling/roi_average_pooling_2d.py
Expand Up @@ -28,6 +28,7 @@
# Written by Ross Girshick
# -----------------------------------------------------------------------------

import numbers
import numpy
import six

Expand All @@ -51,17 +52,18 @@ class ROIAveragePooling2D(function.Function):

def __init__(self, outsize, spatial_scale):
outh, outw = _pair(outsize)
if not (isinstance(outh, int) and outh > 0):
if not (isinstance(outh, numbers.Integral) and outh > 0):
raise TypeError(
'outsize[0] must be positive integer: {}, {}'
.format(type(outh), outh))
if not (isinstance(outw, int) and outw > 0):
if not (isinstance(outw, numbers.Integral) and outw > 0):
raise TypeError(
'outsize[1] must be positive integer: {}, {}'
.format(type(outw), outw))
if isinstance(spatial_scale, int):
if isinstance(spatial_scale, numbers.Integral):
spatial_scale = float(spatial_scale)
if not (isinstance(spatial_scale, float) and spatial_scale > 0):
if not (isinstance(spatial_scale, numbers.Real) and
spatial_scale > 0):
raise TypeError(
'spatial_scale must be a positive float number: {}, {}'
.format(type(spatial_scale), spatial_scale))
Expand Down
16 changes: 9 additions & 7 deletions chainer/functions/pooling/roi_max_align_2d.py
Expand Up @@ -15,6 +15,7 @@
# \roi align operator described in Mask RCNN
# -----------------------------------------------------------------------------

import numbers
import numpy
import six

Expand Down Expand Up @@ -42,23 +43,24 @@ class ROIMaxAlign2D(function.Function):

def __init__(self, outsize, spatial_scale, sampling_ratio=None):
outh, outw = _pair(outsize)
if not (isinstance(outh, int) and outh > 0):
if not (isinstance(outh, numbers.Integral) and outh > 0):
raise TypeError(
'outsize[0] must be positive integer: {}, {}'
.format(type(outh), outh))
if not (isinstance(outw, int) and outw > 0):
if not (isinstance(outw, numbers.Integral) and outw > 0):
raise TypeError(
'outsize[1] must be positive integer: {}, {}'
.format(type(outw), outw))
if isinstance(spatial_scale, int):
if isinstance(spatial_scale, numbers.Integral):
spatial_scale = float(spatial_scale)
if not (isinstance(spatial_scale, float) and spatial_scale > 0):
if not (isinstance(spatial_scale, numbers.Real) and
spatial_scale > 0):
raise TypeError(
'spatial_scale must be a positive float number: {}, {}'
.format(type(spatial_scale), spatial_scale))
sampling_ratio = _pair(sampling_ratio)
if not all((isinstance(s, int) and s >= 1) or s is None
for s in sampling_ratio):
if not all((isinstance(s, numbers.Integral) and s >= 1) or
s is None for s in sampling_ratio):
raise TypeError(
'sampling_ratio must be integer >= 1 or a pair of it: {}'
.format(sampling_ratio))
Expand Down Expand Up @@ -317,8 +319,8 @@ def backward_cpu(self, inputs, gy):
roi_end_h = bottom_rois[n, 2] * spatial_scale
roi_end_w = bottom_rois[n, 3] * spatial_scale

roi_width = max(roi_end_w - roi_start_w, 1.)
roi_height = max(roi_end_h - roi_start_h, 1.)
roi_width = max(roi_end_w - roi_start_w, 1.)
bin_size_h = roi_height / pooled_height
bin_size_w = roi_width / pooled_width

Expand Down
10 changes: 6 additions & 4 deletions chainer/functions/pooling/roi_max_pooling_2d.py
Expand Up @@ -28,6 +28,7 @@
# Written by Ross Girshick
# -----------------------------------------------------------------------------

import numbers
import numpy
import six

Expand All @@ -52,17 +53,18 @@ class ROIMaxPooling2D(function.Function):

def __init__(self, outsize, spatial_scale):
outh, outw = _pair(outsize)
if not (isinstance(outh, int) and outh > 0):
if not (isinstance(outh, numbers.Integral) and outh > 0):
raise TypeError(
'outsize[0] must be positive integer: {}, {}'
.format(type(outh), outh))
if not (isinstance(outw, int) and outw > 0):
if not (isinstance(outw, numbers.Integral) and outw > 0):
raise TypeError(
'outsize[1] must be positive integer: {}, {}'
.format(type(outw), outw))
if isinstance(spatial_scale, int):
if isinstance(spatial_scale, numbers.Integral):
spatial_scale = float(spatial_scale)
if not (isinstance(spatial_scale, float) and spatial_scale > 0):
if not (isinstance(spatial_scale, numbers.Real) and
spatial_scale > 0):
raise TypeError(
'spatial_scale must be a positive float number: {}, {}'
.format(type(spatial_scale), spatial_scale))
Expand Down
Expand Up @@ -18,9 +18,18 @@ def _pair(x):


@testing.parameterize(*testing.product({
'sampling_ratio': [None, 1, 2, (None, 3), (1, 2)],
'outsize': [5, 7, (5, 7)],
'spatial_scale': [0.6, 1.0, 2.0],
'sampling_ratio': [
None, 1, 2, (None, 3), (1, 2),
numpy.int32(1), (None, numpy.int32(3)),
(numpy.int32(1), numpy.int32(2)),
],
'outsize': [
5, 7, (5, 7),
numpy.int32(5), (numpy.int32(5), numpy.int32(7)),
],
'spatial_scale': [
0.6, 1.0, 2.0, numpy.float32(0.6), numpy.int32(2),
],
}))
class TestROIAlign2D(unittest.TestCase):

Expand Down
Expand Up @@ -19,8 +19,10 @@ def _pair(x):

@testing.parameterize(*testing.product({
'dtype': [numpy.float32, numpy.float64],
'outsize': [5, 7, (5, 7)],
'spatial_scale': [0.6, 1.0, 2.0],
'outsize': [
5, 7, (5, 7), numpy.int32(5),
(numpy.int32(5), numpy.int32(7))],
'spatial_scale': [0.6, 1.0, 2.0, numpy.float32(0.6), numpy.int32(2)],
}))
class TestROIAveragePooling2D(unittest.TestCase):

Expand Down
Expand Up @@ -18,9 +18,18 @@ def _pair(x):


@testing.parameterize(*testing.product({
'sampling_ratio': [None, 1, 2, (None, 3), (1, 2)],
'outsize': [5, 7, (5, 7)],
'spatial_scale': [0.6, 1.0, 2.0],
'sampling_ratio': [
None, 1, 2, (None, 3), (1, 2),
numpy.int32(1), (None, numpy.int32(3)),
(numpy.int32(1), numpy.int32(2)),
],
'outsize': [
5, 7, (5, 7),
numpy.int32(5), (numpy.int32(5), numpy.int32(7)),
],
'spatial_scale': [
0.6, 1.0, 2.0, numpy.float32(0.6), numpy.int32(2),
],
}))
class TestROIMaxAlign2D(unittest.TestCase):

Expand Down
Expand Up @@ -18,7 +18,11 @@ def _pair(x):

@testing.parameterize(*testing.product({
'dtype': [numpy.float32, numpy.float64],
'outsize': [5, 7, (5, 7)],
'outsize': [
5, 7, (5, 7), numpy.int32(5),
(numpy.int32(5), numpy.int32(7))],
'spatial_scale': [
0.6, 1.0, 2, numpy.float32(0.6), numpy.int32(2)],
}))
class TestROIMaxPooling2D(unittest.TestCase):

Expand Down

0 comments on commit 3b3e6da

Please sign in to comment.