def forward(self, x):
     W = x[1]
     b = None
     if len(x) == 3:
         b = x[2]
     func = conv2d_module.Convolution2D(
         W.shape[1], W.shape[0], W.shape[2:],
         stride=self.stride, pad=self.pad, use_cudnn=self.use_cudnn,
         initialW=W, initial_bias=b)
     self.func = func
     if any(isinstance(i, cuda.ndarray) for i in x):
         func.to_gpu()
     return func.forward(x[:1])
Ejemplo n.º 2
0
 def __init__(self, in_channels, out1, proj3, out3, proj5, out5, proj_pool):
     self.f = function_set.FunctionSet(
         conv1=convolution_2d.Convolution2D(in_channels, out1, 1),
         proj3=convolution_2d.Convolution2D(in_channels, proj3, 1),
         conv3=convolution_2d.Convolution2D(proj3, out3, 3, pad=1),
         proj5=convolution_2d.Convolution2D(in_channels, proj5, 1),
         conv5=convolution_2d.Convolution2D(proj5, out5, 5, pad=2),
         projp=convolution_2d.Convolution2D(in_channels, proj_pool, 1),
     )
Ejemplo n.º 3
0
    def __init__(self, in_channels, out1, proj3, out3, proj33, out33,
                 pooltype, proj_pool=None, stride=1):
        if out1 > 0:
            assert stride == 1
            assert proj_pool is not None

        self.f = function_set.FunctionSet(
            proj3=convolution_2d.Convolution2D(
                in_channels, proj3, 1, nobias=True),
            conv3=convolution_2d.Convolution2D(
                proj3, out3, 3, pad=1, stride=stride, nobias=True),
            proj33=convolution_2d.Convolution2D(
                in_channels, proj33, 1, nobias=True),
            conv33a=convolution_2d.Convolution2D(
                proj33, out33, 3, pad=1, nobias=True),
            conv33b=convolution_2d.Convolution2D(
                out33, out33, 3, pad=1, stride=stride, nobias=True),
            proj3n=batch_normalization.BatchNormalization(proj3),
            conv3n=batch_normalization.BatchNormalization(out3),
            proj33n=batch_normalization.BatchNormalization(proj33),
            conv33an=batch_normalization.BatchNormalization(out33),
            conv33bn=batch_normalization.BatchNormalization(out33),
        )

        if out1 > 0:
            self.f.conv1 = convolution_2d.Convolution2D(
                in_channels, out1, 1, stride=stride, nobias=True)
            self.f.conv1n = batch_normalization.BatchNormalization(out1)
        self.out1 = out1

        if proj_pool is not None:
            self.f.poolp = convolution_2d.Convolution2D(
                in_channels, proj_pool, 1, nobias=True)
            self.f.poolpn = batch_normalization.BatchNormalization(proj_pool)
        self.proj_pool = proj_pool

        if pooltype == 'max':
            self.f.pool = pooling_2d.MaxPooling2D(3, stride=stride, pad=1)
        elif pooltype == 'avg':
            self.f.pool = pooling_2d.AveragePooling2D(3, stride=stride, pad=1)
        else:
            raise NotImplementedError()