当前位置: 首页>>代码示例>>Python>>正文


Python chainer.initializers方法代码示例

本文整理汇总了Python中chainer.initializers方法的典型用法代码示例。如果您正苦于以下问题:Python chainer.initializers方法的具体用法?Python chainer.initializers怎么用?Python chainer.initializers使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在chainer的用法示例。


在下文中一共展示了chainer.initializers方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: import chainer [as 别名]
# 或者: from chainer import initializers [as 别名]
def __init__(self, dtype=None):
        W = None
        bias = None
        if dtype is not None:
            self.dtype = dtype
            W = chainer.initializers.Normal(dtype=self.dtype)
            bias = chainer.initializers.Zero(dtype=self.dtype)
        super(ExampleModel, self).__init__()
        with self.init_scope():
            self.a = chainer.links.Linear(2, 3, initialW=W, initial_bias=bias)
            self.b = chainer.links.Linear(3, 4, initialW=W, initial_bias=bias)
            self.c = chainer.links.Linear(None, 5, initialW=W,
                                          initial_bias=bias) 
开发者ID:chainer,项目名称:chainer,代码行数:15,代码来源:test_communicator.py

示例2: __init__

# 需要导入模块: import chainer [as 别名]
# 或者: from chainer import initializers [as 别名]
def __init__(self, pretrained_model, n_layers, downsample_fb=False):
        super(ResNetLayers, self).__init__()

        if pretrained_model:
            # As a sampling process is time-consuming,
            # we employ a zero initializer for faster computation.
            conv_kwargs = {'initialW': constant.Zero()}
        else:
            # employ default initializers used in the original paper
            conv_kwargs = {'initialW': normal.HeNormal(scale=1.0)}

        kwargs = conv_kwargs.copy()
        kwargs['downsample_fb'] = downsample_fb

        if n_layers == 50:
            block = [3, 4, 6, 3]
        elif n_layers == 101:
            block = [3, 4, 23, 3]
        elif n_layers == 152:
            block = [3, 8, 36, 3]
        else:
            raise ValueError('The n_layers argument should be either 50, 101,'
                             ' or 152, but {} was given.'.format(n_layers))

        with self.init_scope():
            self.conv1 = Convolution2D(3, 64, 7, 2, 3, **conv_kwargs)
            self.bn1 = BatchNormalization(64)
            self.res2 = BuildingBlock(block[0], 64, 64, 256, 1, **kwargs)
            self.res3 = BuildingBlock(block[1], 256, 128, 512, 2, **kwargs)
            self.res4 = BuildingBlock(block[2], 512, 256, 1024, 2, **kwargs)
            self.res5 = BuildingBlock(block[3], 1024, 512, 2048, 2, **kwargs)
            self.fc6 = Linear(2048, 1000)

        if pretrained_model and pretrained_model.endswith('.caffemodel'):
            _retrieve(n_layers, 'ResNet-{}-model.npz'.format(n_layers),
                      pretrained_model, self)
        elif pretrained_model:
            npz.load_npz(pretrained_model, self) 
开发者ID:chainer,项目名称:chainer,代码行数:40,代码来源:resnet.py

示例3: zerograd

# 需要导入模块: import chainer [as 别名]
# 或者: from chainer import initializers [as 别名]
def zerograd(self):
        super(Parameter, self).zerograd()
        if not self.is_initialized:
            dtype = getattr(self.initializer, 'dtype', None)
            self._grad_initializer = initializers.Zero(dtype) 
开发者ID:chainer,项目名称:chainer,代码行数:7,代码来源:variable.py

示例4: initialize

# 需要导入模块: import chainer [as 别名]
# 或者: from chainer import initializers [as 别名]
def initialize(self, shape):
        """Initializes the uninitialized variable.

        Uninitialized variable is a variable created with the data array set to
        None. This method creates and initializes the data array. The shape of
        the variable can be left unknown until this method is called.

        Args:
            shape (tuple of int): Shape of the data array.

        """
        device = self._initial_device
        assert device is not None
        xp = device.xp

        data = initializers.generate_array(
            self.initializer, shape, xp, device=device)
        data = chainer.memory_layouts._transpose_array(data, None, self.layout)

        if self._grad_initializer is None:
            grad = None
        else:
            grad = initializers.generate_array(
                self._grad_initializer, shape, xp, device=device)
            grad = chainer.memory_layouts._transpose_array(
                grad, None, self.layout)

        self._set_array(data, layout_check=False)
        self._set_grad(grad, layout_check=False)

        # Convert the array for iDeep.
        # TODO(niboshi): This could be done in generate_array().
        if isinstance(self._initial_device, intel64.Intel64Device):
            self.to_intel64() 
开发者ID:chainer,项目名称:chainer,代码行数:36,代码来源:variable.py

示例5: __init__

# 需要导入模块: import chainer [as 别名]
# 或者: from chainer import initializers [as 别名]
def __init__(self, pretrained_model='auto', n_layers=16):
        super(VGGLayers, self).__init__()
        if pretrained_model:
            # As a sampling process is time-consuming,
            # we employ a zero initializer for faster computation.
            init = constant.Zero()
            kwargs = {'initialW': init, 'initial_bias': init}
        else:
            # employ default initializers used in the original paper
            kwargs = {
                'initialW': normal.Normal(0.01),
                'initial_bias': constant.Zero(),
            }

        if n_layers not in [16, 19]:
            raise ValueError(
                'The n_layers argument should be either 16 or 19, '
                'but {} was given.'.format(n_layers)
            )

        with self.init_scope():
            self.conv1_1 = Convolution2D(3, 64, 3, 1, 1, **kwargs)
            self.conv1_2 = Convolution2D(64, 64, 3, 1, 1, **kwargs)
            self.conv2_1 = Convolution2D(64, 128, 3, 1, 1, **kwargs)
            self.conv2_2 = Convolution2D(128, 128, 3, 1, 1, **kwargs)
            self.conv3_1 = Convolution2D(128, 256, 3, 1, 1, **kwargs)
            self.conv3_2 = Convolution2D(256, 256, 3, 1, 1, **kwargs)
            self.conv3_3 = Convolution2D(256, 256, 3, 1, 1, **kwargs)
            self.conv4_1 = Convolution2D(256, 512, 3, 1, 1, **kwargs)
            self.conv4_2 = Convolution2D(512, 512, 3, 1, 1, **kwargs)
            self.conv4_3 = Convolution2D(512, 512, 3, 1, 1, **kwargs)
            self.conv5_1 = Convolution2D(512, 512, 3, 1, 1, **kwargs)
            self.conv5_2 = Convolution2D(512, 512, 3, 1, 1, **kwargs)
            self.conv5_3 = Convolution2D(512, 512, 3, 1, 1, **kwargs)
            self.fc6 = Linear(512 * 7 * 7, 4096, **kwargs)
            self.fc7 = Linear(4096, 4096, **kwargs)
            self.fc8 = Linear(4096, 1000, **kwargs)
            if n_layers == 19:
                self.conv3_4 = Convolution2D(256, 256, 3, 1, 1, **kwargs)
                self.conv4_4 = Convolution2D(512, 512, 3, 1, 1, **kwargs)
                self.conv5_4 = Convolution2D(512, 512, 3, 1, 1, **kwargs)

        if pretrained_model == 'auto':
            if n_layers == 16:
                _retrieve(
                    'VGG_ILSVRC_16_layers.npz',
                    'https://www.robots.ox.ac.uk/%7Evgg/software/very_deep/'
                    'caffe/VGG_ILSVRC_16_layers.caffemodel',
                    self)
            else:
                _retrieve(
                    'VGG_ILSVRC_19_layers.npz',
                    'http://www.robots.ox.ac.uk/%7Evgg/software/very_deep/'
                    'caffe/VGG_ILSVRC_19_layers.caffemodel',
                    self)
        elif pretrained_model:
            npz.load_npz(pretrained_model, self) 
开发者ID:chainer,项目名称:chainer,代码行数:59,代码来源:vgg.py

示例6: __init__

# 需要导入模块: import chainer [as 别名]
# 或者: from chainer import initializers [as 别名]
def __init__(self, pretrained_model='auto'):
        super(GoogLeNet, self).__init__()

        if pretrained_model:
            # As a sampling process is time-consuming,
            # we employ a zero initializer for faster computation.
            kwargs = {'initialW': constant.Zero()}
        else:
            # employ default initializers used in BVLC. For more detail, see
            # https://github.com/chainer/chainer/pull/2424#discussion_r109642209
            kwargs = {'initialW': uniform.LeCunUniform(scale=1.0)}

        with self.init_scope():
            self.conv1 = Convolution2D(3, 64, 7, stride=2, pad=3, **kwargs)
            self.conv2_reduce = Convolution2D(64, 64, 1, **kwargs)
            self.conv2 = Convolution2D(64, 192, 3, stride=1, pad=1, **kwargs)
            self.inc3a = Inception(192, 64, 96, 128, 16, 32, 32)
            self.inc3b = Inception(256, 128, 128, 192, 32, 96, 64)
            self.inc4a = Inception(480, 192, 96, 208, 16, 48, 64)
            self.inc4b = Inception(512, 160, 112, 224, 24, 64, 64)
            self.inc4c = Inception(512, 128, 128, 256, 24, 64, 64)
            self.inc4d = Inception(512, 112, 144, 288, 32, 64, 64)
            self.inc4e = Inception(528, 256, 160, 320, 32, 128, 128)
            self.inc5a = Inception(832, 256, 160, 320, 32, 128, 128)
            self.inc5b = Inception(832, 384, 192, 384, 48, 128, 128)
            self.loss3_fc = Linear(1024, 1000, **kwargs)

            self.loss1_conv = Convolution2D(512, 128, 1, **kwargs)
            self.loss1_fc1 = Linear(2048, 1024, **kwargs)
            self.loss1_fc2 = Linear(1024, 1000, **kwargs)

            self.loss2_conv = Convolution2D(528, 128, 1, **kwargs)
            self.loss2_fc1 = Linear(2048, 1024, **kwargs)
            self.loss2_fc2 = Linear(1024, 1000, **kwargs)

        if pretrained_model == 'auto':
            _retrieve(
                'bvlc_googlenet.npz',
                'http://dl.caffe.berkeleyvision.org/bvlc_googlenet.caffemodel',
                self)
        elif pretrained_model:
            npz.load_npz(pretrained_model, self) 
开发者ID:chainer,项目名称:chainer,代码行数:44,代码来源:googlenet.py

示例7: __init__

# 需要导入模块: import chainer [as 别名]
# 或者: from chainer import initializers [as 别名]
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) 
开发者ID:chainer,项目名称:chainercv,代码行数:51,代码来源:vgg16.py


注:本文中的chainer.initializers方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。