示例#1
0
def test_max_pool_invalid(
        device, x_shape, ksize, stride, pad, cover_all, float_dtype):
    with pytest.raises(chainerx.DimensionError):
        chainerx.max_pool(
            **_create_max_pool_args(
                chainerx, device, x_shape, ksize, stride, pad, cover_all,
                float_dtype))
示例#2
0
def test_max_pool_invalid(
        device, x_shape, ksize, stride, pad, cover_all, float_dtype):
    x = numpy.random.uniform(-1, 1, x_shape).astype(float_dtype)
    x = chainerx.array(x)
    with pytest.raises(chainerx.DimensionError):
        chainerx.max_pool(
            x, ksize=ksize, stride=stride, pad=pad, cover_all=cover_all)
示例#3
0
def test_max_pool_invalid(device, x_shape, ksize, stride, pad, cover_all,
                          float_dtype):
    x = numpy.random.uniform(-1, 1, x_shape).astype(float_dtype)
    x = chainerx.array(x)
    with pytest.raises(chainerx.DimensionError):
        chainerx.max_pool(x,
                          ksize=ksize,
                          stride=stride,
                          pad=pad,
                          cover_all=cover_all)
示例#4
0
 def forward_chainerx(self, x):
     # TODO(sonots): Support return_indices in ChainerX
     if self.return_indices:
         return chainer.Fallback
     if x[0].device.backend.name == 'cuda':
         # TODO(sonots): Support more ndim in ChainerX
         if self.ndim not in [2, 3]:
             return chainer.Fallback
     return chainerx.max_pool(x[0], self.ksize, self.stride, self.pad,
                              self.cover_all),
示例#5
0
 def forward_chainerx(self, x):
     # TODO(sonots): Support return_indices in ChainerX
     if self.return_indices:
         return chainer.Fallback
     if x[0].device.backend.name == 'cuda':
         # TODO(sonots): Support more ndim in ChainerX
         if self.ndim not in [2, 3]:
             return chainer.Fallback
     return chainerx.max_pool(x[0], self.ksize, self.stride, self.pad,
                              self.cover_all),
示例#6
0
 def chainerx_max_pool():
     y = chainerx.max_pool(**create_args(chainerx))
     # In the case of CUDA, we get huge negative numbers instead of -inf
     # around boundaries.
     # Align them to chainer (native) results.
     if device.backend.name == 'cuda':
         y = chainerx.to_numpy(y)
         y[y < -3.e+34] = -float('inf')
         y = chainerx.array(y)
     return y
示例#7
0
 def chainerx_max_pool():
     y = chainerx.max_pool(**create_args(chainerx))
     # In the case of CUDA, we get huge negative numbers instead of -inf
     # around boundaries.
     # Align them to chainer (native) results.
     if device.backend.name == 'cuda':
         y = chainerx.to_numpy(y)
         y[y < -3.e+34] = -float('inf')
         y = chainerx.array(y)
     return y
示例#8
0
    def __call__(self, x):
        h = self.bn1(self.conv1(x))
        h = chx.max_pool(chx.maximum(0, h), 3, stride=2)
        h = self.res2(h)
        h = self.res3(h)
        h = self.res4(h)
        h = self.res5(h)
        h = chx.average_pool(h, 7, stride=1)
        h = self.fc(h)

        return h
示例#9
0
    def __call__(self, x):
        h = self.bn1(self.conv1(x))
        h = chx.max_pool(chx.maximum(0, h), 3, stride=2)
        h = self.res2(h)
        h = self.res3(h)
        h = self.res4(h)
        h = self.res5(h)
        h = chx.average_pool(h, 7, stride=1)
        h = self.fc(h)

        return h
示例#10
0
    def forward_chainerx(self, inputs):
        x, = inputs
        y = chainerx.max_pool(
            x, ksize=self.ksize, stride=self.stride, pad=self.pad,
            cover_all=self.cover_all)

        # This function can return -inf (or huge negative numbers in case of
        # CUDA) around boundaries.
        # Convert them to finite numbers in order to properly calculate numeric
        # gradients.
        y = chainerx.maximum(y, -1e4)
        return y,
示例#11
0
    def forward_chainerx(self, inputs):
        x, = inputs
        y = chainerx.max_pool(x,
                              ksize=self.ksize,
                              stride=self.stride,
                              pad=self.pad,
                              cover_all=self.cover_all)

        # This function can return -inf (or huge negative numbers in case of
        # CUDA) around boundaries.
        # Convert them to finite numbers in order to properly calculate numeric
        # gradients.
        y = chainerx.maximum(y, -1e4)
        return y,
示例#12
0
    def forward_chainerx(self, x):
        ndim = self.ndim
        ksize = self.ksize
        stride = self.stride
        pad = self.pad
        cover_all = self.cover_all

        # TODO(sonots): Support return_indices in ChainerX
        if self.return_indices:
            return chainer.Fallback
        if x[0].device.backend.name == 'cuda':
            # TODO(sonots): Support more ndim in ChainerX
            if ndim not in [2, 3]:
                return chainer.Fallback
        y = chainerx.max_pool(x[0], ksize, stride, pad, cover_all)
        return y,
示例#13
0
 def forward_chainerx(self, x):
     # TODO(sonots): Support return_indices in ChainerX
     if self.return_indices:
         return chainer.Fallback
     return chainerx.max_pool(x[0], (self.kh, self.kw), (self.sy, self.sx),
                              (self.ph, self.pw), self.cover_all),
示例#14
0
def test_max_pool_invalid(device, x_shape, ksize, stride, pad, cover_all,
                          float_dtype):
    with pytest.raises(chainerx.DimensionError):
        chainerx.max_pool(
            **_create_max_pool_args(chainerx, device, x_shape, ksize, stride,
                                    pad, cover_all, float_dtype))
示例#15
0
 def forward_chainerx(self, x):
     # TODO(sonots): Support return_indices in ChainerX
     if self.return_indices:
         return chainer.Fallback
     return chainerx.max_pool(x[0], (self.kh, self.kw), (self.sy, self.sx),
                              (self.ph, self.pw), self.cover_all),