Ejemplo n.º 1
0
def create_srcnn():
    """
    waifu2xのSRCNNというモデルを参考に作ってみる
    """
    return chainer.Sequential(
        Conv2DActiv(in_channels=None, out_channels=32, ksize=3,
                    activ=lambda x: F.leaky_relu(x, 0.1), pad=1),
        Conv2DActiv(in_channels=None, out_channels=32, ksize=3,
                    activ=lambda x: F.leaky_relu(x, 0.1), pad=1),
        Conv2DActiv(in_channels=None, out_channels=64, ksize=3,
                    activ=lambda x: F.leaky_relu(x, 0.1), pad=1),
        Conv2DActiv(in_channels=None, out_channels=64, ksize=3,
                    activ=lambda x: F.leaky_relu(x, 0.1), pad=1),
        Conv2DActiv(in_channels=None, out_channels=128, ksize=3,
                    activ=lambda x: F.leaky_relu(x, 0.1), pad=1),
        Conv2DActiv(in_channels=None, out_channels=128, ksize=3,
                    activ=lambda x: F.leaky_relu(x, 0.1), pad=1),
        L.Convolution2D(in_channels=None, out_channels=3, ksize=3, pad=1)
    )
Ejemplo n.º 2
0
    def __init__(self,
                 n_class=None,
                 pretrained_model=None,
                 mean=None,
                 initialW=None,
                 initial_bias=None):
        param, path = utils.prepare_pretrained_model(
            {
                'n_class': n_class,
                'mean': mean
            }, pretrained_model, self._models, {
                'n_class': 1000,
                'mean': _imagenet_mean
            })
        self.mean = param['mean']

        if initialW is None:
            # Employ default initializers used in the original paper.
            initialW = normal.Normal(0.01)
        if pretrained_model:
            # As a sampling process is time-consuming,
            # we employ a zero initializer for faster computation.
            initialW = constant.Zero()
        kwargs = {'initialW': initialW, 'initial_bias': initial_bias}

        super(VGG16, self).__init__()
        with self.init_scope():
            self.conv1_1 = Conv2DActiv(None, 64, 3, 1, 1, **kwargs)
            self.conv1_2 = Conv2DActiv(None, 64, 3, 1, 1, **kwargs)
            self.pool1 = _max_pooling_2d
            self.conv2_1 = Conv2DActiv(None, 128, 3, 1, 1, **kwargs)
            self.conv2_2 = Conv2DActiv(None, 128, 3, 1, 1, **kwargs)
            self.pool2 = _max_pooling_2d
            self.conv3_1 = Conv2DActiv(None, 256, 3, 1, 1, **kwargs)
            self.conv3_2 = Conv2DActiv(None, 256, 3, 1, 1, **kwargs)
            self.conv3_3 = Conv2DActiv(None, 256, 3, 1, 1, **kwargs)
            self.pool3 = _max_pooling_2d
            self.conv4_1 = Conv2DActiv(None, 512, 3, 1, 1, **kwargs)
            self.conv4_2 = Conv2DActiv(None, 512, 3, 1, 1, **kwargs)
            self.conv4_3 = Conv2DActiv(None, 512, 3, 1, 1, **kwargs)
            self.pool4 = _max_pooling_2d
            self.conv5_1 = Conv2DActiv(None, 512, 3, 1, 1, **kwargs)
            self.conv5_2 = Conv2DActiv(None, 512, 3, 1, 1, **kwargs)
            self.conv5_3 = Conv2DActiv(None, 512, 3, 1, 1, **kwargs)
            self.pool5 = _max_pooling_2d
            self.fc6 = Linear(None, 4096, **kwargs)
            self.fc6_relu = relu
            self.fc6_dropout = dropout
            self.fc7 = Linear(None, 4096, **kwargs)
            self.fc7_relu = relu
            self.fc7_dropout = dropout
            self.fc8 = Linear(None, param['n_class'], **kwargs)
            self.prob = softmax

        if path:
            chainer.serializers.load_npz(path, self)