Python chainer.initializers.HeNormal() Examples
The following are 30
code examples of chainer.initializers.HeNormal().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
chainer.initializers
, or try the search function
.
Example #1
Source File: Resnet_with_loss.py From chainer-compiler with MIT License | 6 votes |
def __init__(self, in_size, ch, out_size, stride=2, groups=1): super(BottleNeckA, self).__init__() initialW = initializers.HeNormal() with self.init_scope(): self.conv1 = L.Convolution2D( in_size, ch, 1, stride, 0, initialW=initialW, nobias=True) self.bn1 = L.BatchNormalization(ch) self.conv2 = L.Convolution2D( ch, ch, 3, 1, 1, initialW=initialW, nobias=True, groups=groups) self.bn2 = L.BatchNormalization(ch) self.conv3 = L.Convolution2D( ch, out_size, 1, 1, 0, initialW=initialW, nobias=True) self.bn3 = L.BatchNormalization(out_size) self.conv4 = L.Convolution2D( in_size, out_size, 1, stride, 0, initialW=initialW, nobias=True) self.bn4 = L.BatchNormalization(out_size)
Example #2
Source File: resnet50.py From chainer with MIT License | 6 votes |
def __init__(self, in_size, ch, out_size, stride=2, groups=1): super(BottleNeckA, self).__init__() initialW = initializers.HeNormal() with self.init_scope(): self.conv1 = L.Convolution2D( in_size, ch, 1, stride, 0, initialW=initialW, nobias=True) self.bn1 = L.BatchNormalization(ch) self.conv2 = L.Convolution2D( ch, ch, 3, 1, 1, initialW=initialW, nobias=True, groups=groups) self.bn2 = L.BatchNormalization(ch) self.conv3 = L.Convolution2D( ch, out_size, 1, 1, 0, initialW=initialW, nobias=True) self.bn3 = L.BatchNormalization(out_size) self.conv4 = L.Convolution2D( in_size, out_size, 1, stride, 0, initialW=initialW, nobias=True) self.bn4 = L.BatchNormalization(out_size)
Example #3
Source File: simplified_dropconnect.py From chainer with MIT License | 6 votes |
def __init__(self, in_size, out_size, ratio=.5, nobias=False, initialW=None, initial_bias=None): super(SimplifiedDropconnect, self).__init__() self.out_size = out_size self.ratio = ratio if initialW is None: initialW = initializers.HeNormal(1. / numpy.sqrt(2)) with self.init_scope(): W_initializer = initializers._get_initializer(initialW) self.W = variable.Parameter(W_initializer) if in_size is not None: self._initialize_params(in_size) if nobias: self.b = None else: if initial_bias is None: initial_bias = initializers.Constant(0) bias_initializer = initializers._get_initializer(initial_bias) self.b = variable.Parameter(bias_initializer, out_size)
Example #4
Source File: alex.py From chainer-compiler with MIT License | 6 votes |
def __init__(self): chainer.Chain.__init__(self) self.dtype = np.float16 W = initializers.HeNormal(1 / np.sqrt(2), self.dtype) bias = initializers.Zero(self.dtype) with self.init_scope(): self.conv1 = L.Convolution2D(None, 96, 11, stride=4, initialW=W, initial_bias=bias) self.conv2 = L.Convolution2D(None, 256, 5, pad=2, initialW=W, initial_bias=bias) self.conv3 = L.Convolution2D(None, 384, 3, pad=1, initialW=W, initial_bias=bias) self.conv4 = L.Convolution2D(None, 384, 3, pad=1, initialW=W, initial_bias=bias) self.conv5 = L.Convolution2D(None, 256, 3, pad=1, initialW=W, initial_bias=bias) self.fc6 = L.Linear(None, 4096, initialW=W, initial_bias=bias) self.fc7 = L.Linear(None, 4096, initialW=W, initial_bias=bias) self.fc8 = L.Linear(None, 1000, initialW=W, initial_bias=bias)
Example #5
Source File: Resnet_with_loss.py From chainer-compiler with MIT License | 6 votes |
def __init__(self, in_size, ch, out_size, stride=2, groups=1): super(BottleNeckA, self).__init__() initialW = initializers.HeNormal() with self.init_scope(): self.conv1 = L.Convolution2D( in_size, ch, 1, stride, 0, initialW=initialW, nobias=True) self.bn1 = L.BatchNormalization(ch) self.conv2 = L.Convolution2D( ch, ch, 3, 1, 1, initialW=initialW, nobias=True, groups=groups) self.bn2 = L.BatchNormalization(ch) self.conv3 = L.Convolution2D( ch, out_size, 1, 1, 0, initialW=initialW, nobias=True) self.bn3 = L.BatchNormalization(out_size) self.conv4 = L.Convolution2D( in_size, out_size, 1, stride, 0, initialW=initialW, nobias=True) self.bn4 = L.BatchNormalization(out_size)
Example #6
Source File: resnet50.py From chainer-compiler with MIT License | 6 votes |
def __init__(self, in_size, ch, out_size, stride=2, groups=1): super(BottleNeckA, self).__init__() initialW = initializers.HeNormal() with self.init_scope(): self.conv1 = L.Convolution2D( in_size, ch, 1, stride, 0, initialW=initialW, nobias=True) self.bn1 = L.BatchNormalization(ch) self.conv2 = L.Convolution2D( ch, ch, 3, 1, 1, initialW=initialW, nobias=True, groups=groups) self.bn2 = L.BatchNormalization(ch) self.conv3 = L.Convolution2D( ch, out_size, 1, 1, 0, initialW=initialW, nobias=True) self.bn3 = L.BatchNormalization(out_size) self.conv4 = L.Convolution2D( in_size, out_size, 1, stride, 0, initialW=initialW, nobias=True) self.bn4 = L.BatchNormalization(out_size)
Example #7
Source File: resnet50.py From chainer with MIT License | 6 votes |
def __init__(self, in_size, ch, out_size, stride=2): super(BottleNeckA, self).__init__() initialW = initializers.HeNormal() with self.init_scope(): self.conv1 = L.Convolution2D( in_size, ch, 1, stride, 0, initialW=initialW, nobias=True) self.bn1 = L.BatchNormalization(ch) self.conv2 = L.Convolution2D( ch, ch, 3, 1, 1, initialW=initialW, nobias=True) self.bn2 = L.BatchNormalization(ch) self.conv3 = L.Convolution2D( ch, out_size, 1, 1, 0, initialW=initialW, nobias=True) self.bn3 = L.BatchNormalization(out_size) self.conv4 = L.Convolution2D( in_size, out_size, 1, stride, 0, initialW=initialW, nobias=True) self.bn4 = L.BatchNormalization(out_size)
Example #8
Source File: test_multiprocess_parallel_updater.py From chainer with MIT License | 5 votes |
def __init__(self, dtype=numpy.float32): super(SimpleNet, self).__init__() self.dtype = dtype W = initializers.HeNormal(1 / numpy.sqrt(2), self.dtype) bias = initializers.Zero(self.dtype) with self.init_scope(): self.conv = chainer.links.Convolution2D(2, 2, 3, initialW=W, initial_bias=bias) self.fc = chainer.links.Linear(18, 2, initialW=W, initial_bias=bias) self.train = True
Example #9
Source File: resnet50.py From chainer with MIT License | 5 votes |
def __init__(self): super(ResNet50_Nhwc, self).__init__() with self.init_scope(): self.conv1 = L.Convolution2D( 3, 64, 7, 2, 3, initialW=initializers.HeNormal()) self.bn1 = L.BatchNormalization(64) with chainer.using_config('compute_mode', 'cudnn_fast'): self.res2 = Block(3, 64, 64, 256, 1) self.res3 = Block(4, 256, 128, 512) self.res4 = Block(6, 512, 256, 1024) self.res5 = Block(3, 1024, 512, 2048) self.fc = L.Linear(2048, 1000)
Example #10
Source File: resnext50.py From chainer with MIT License | 5 votes |
def __init__(self, in_size, ch, groups=1): super(BottleNeckB, self).__init__() initialW = initializers.HeNormal() with self.init_scope(): self.conv1 = L.Convolution2D( in_size, ch, 1, 1, 0, initialW=initialW, nobias=True) self.bn1 = L.BatchNormalization(ch) self.conv2 = L.Convolution2D( ch, ch, 3, 1, 1, initialW=initialW, nobias=True, groups=groups) self.bn2 = L.BatchNormalization(ch) self.conv3 = L.Convolution2D( ch, in_size, 1, 1, 0, initialW=initialW, nobias=True) self.bn3 = L.BatchNormalization(in_size)
Example #11
Source File: resnext50.py From chainer with MIT License | 5 votes |
def __init__(self): super(ResNeXt50, self).__init__() with self.init_scope(): self.conv1 = L.Convolution2D( 3, 64, 7, 2, 3, initialW=initializers.HeNormal()) self.bn1 = L.BatchNormalization(64) self.res2 = Block(3, 64, 128, 256, 1, groups=32) self.res3 = Block(4, 256, 256, 512, groups=32) self.res4 = Block(6, 512, 512, 1024, groups=32) self.res5 = Block(3, 1024, 1024, 2048, groups=32) self.fc = L.Linear(2048, 1000)
Example #12
Source File: nin.py From chainer with MIT License | 5 votes |
def __init__(self): super(NIN, self).__init__() conv_init = I.HeNormal() # MSRA scaling with self.init_scope(): self.mlpconv1 = L.MLPConvolution2D( None, (96, 96, 96), 11, stride=4, conv_init=conv_init) self.mlpconv2 = L.MLPConvolution2D( None, (256, 256, 256), 5, pad=2, conv_init=conv_init) self.mlpconv3 = L.MLPConvolution2D( None, (384, 384, 384), 3, pad=1, conv_init=conv_init) self.mlpconv4 = L.MLPConvolution2D( None, (1024, 1024, 1000), 3, pad=1, conv_init=conv_init)
Example #13
Source File: resnet50.py From chainer with MIT License | 5 votes |
def __init__(self, in_size, ch): super(BottleNeckB, self).__init__() initialW = initializers.HeNormal() with self.init_scope(): self.conv1 = L.Convolution2D( in_size, ch, 1, 1, 0, initialW=initialW, nobias=True) self.bn1 = L.BatchNormalization(ch) self.conv2 = L.Convolution2D( ch, ch, 3, 1, 1, initialW=initialW, nobias=True) self.bn2 = L.BatchNormalization(ch) self.conv3 = L.Convolution2D( ch, in_size, 1, 1, 0, initialW=initialW, nobias=True) self.bn3 = L.BatchNormalization(in_size)
Example #14
Source File: mask_head.py From chainercv with MIT License | 5 votes |
def __init__(self, n_class, scales): super(MaskHead, self).__init__() initialW = HeNormal(1, fan_option='fan_out') with self.init_scope(): self.conv1 = Conv2DActiv(256, 3, pad=1, initialW=initialW) self.conv2 = Conv2DActiv(256, 3, pad=1, initialW=initialW) self.conv3 = Conv2DActiv(256, 3, pad=1, initialW=initialW) self.conv4 = Conv2DActiv(256, 3, pad=1, initialW=initialW) self.conv5 = L.Deconvolution2D( 256, 2, pad=0, stride=2, initialW=initialW) self.seg = L.Convolution2D(n_class, 1, pad=0, initialW=initialW) self._n_class = n_class self._scales = scales
Example #15
Source File: test_optimizers_by_linear_model.py From chainer with MIT License | 5 votes |
def __init__(self, optimizer, dtype, use_placeholder): self.dtype = dtype weight = initializers.HeNormal(1 / numpy.sqrt(2), dtype) bias = initializers.Constant(0, dtype) in_size = None if use_placeholder else self.UNIT_NUM self.model = L.Linear(in_size, 2, initialW=weight, initial_bias=bias) self.optimizer = optimizer # true parameters self.w = numpy.random.uniform( -1, 1, (self.UNIT_NUM, 1)).astype(dtype) self.b = numpy.random.uniform(-1, 1, (1, )).astype(dtype)
Example #16
Source File: depthwise_convolution_2d.py From chainer with MIT License | 5 votes |
def __init__(self, in_channels, channel_multiplier, ksize, stride=1, pad=0, nobias=False, initialW=None, initial_bias=None): super(DepthwiseConvolution2D, self).__init__() self.ksize = ksize self.stride = _pair(stride) self.pad = _pair(pad) self.channel_multiplier = channel_multiplier self.nobias = nobias if initialW is None: initialW = initializers.HeNormal(1. / numpy.sqrt(2)) with self.init_scope(): W_initializer = initializers._get_initializer(initialW) self.W = variable.Parameter(W_initializer) if nobias: self.b = None else: if initial_bias is None: initial_bias = initializers.Constant(0) bias_initializer = initializers._get_initializer(initial_bias) self.b = variable.Parameter(bias_initializer) if in_channels is not None: self._initialize_params(in_channels)
Example #17
Source File: se_resnet.py From chainercv with MIT License | 5 votes |
def __init__(self, n_layer, n_class=None, pretrained_model=None, mean=None, initialW=None, fc_kwargs={}): blocks = self._blocks[n_layer] param, path = utils.prepare_pretrained_model( {'n_class': n_class, 'mean': mean}, pretrained_model, self._models[n_layer], {'n_class': 1000, 'mean': _imagenet_mean}) self.mean = param['mean'] if initialW is None: initialW = initializers.HeNormal(scale=1., fan_option='fan_out') if 'initialW' not in fc_kwargs: fc_kwargs['initialW'] = initializers.Normal(scale=0.01) if pretrained_model: # As a sampling process is time-consuming, # we employ a zero initializer for faster computation. initialW = initializers.constant.Zero() fc_kwargs['initialW'] = initializers.constant.Zero() kwargs = { 'initialW': initialW, 'stride_first': True, 'add_seblock': True} super(SEResNet, self).__init__() with self.init_scope(): self.conv1 = Conv2DBNActiv(None, 64, 7, 2, 3, nobias=True, initialW=initialW) self.pool1 = lambda x: F.max_pooling_2d(x, ksize=3, stride=2) self.res2 = ResBlock(blocks[0], None, 64, 256, 1, **kwargs) self.res3 = ResBlock(blocks[1], None, 128, 512, 2, **kwargs) self.res4 = ResBlock(blocks[2], None, 256, 1024, 2, **kwargs) self.res5 = ResBlock(blocks[3], None, 512, 2048, 2, **kwargs) self.pool5 = lambda x: F.average(x, axis=(2, 3)) self.fc6 = L.Linear(None, param['n_class'], **fc_kwargs) self.prob = F.softmax if path: chainer.serializers.load_npz(path, self)
Example #18
Source File: se_resnext.py From chainercv with MIT License | 5 votes |
def __init__(self, n_layer, n_class=None, pretrained_model=None, mean=None, initialW=None, fc_kwargs={}): blocks = self._blocks[n_layer] param, path = utils.prepare_pretrained_model( {'n_class': n_class, 'mean': mean}, pretrained_model, self._models[n_layer], {'n_class': 1000, 'mean': _imagenet_mean}) self.mean = param['mean'] if initialW is None: initialW = initializers.HeNormal(scale=1., fan_option='fan_out') if 'initialW' not in fc_kwargs: fc_kwargs['initialW'] = initializers.Normal(scale=0.01) if pretrained_model: # As a sampling process is time-consuming, # we employ a zero initializer for faster computation. initialW = initializers.constant.Zero() fc_kwargs['initialW'] = initializers.constant.Zero() kwargs = { 'groups': 32, 'initialW': initialW, 'stride_first': False, 'add_seblock': True} super(SEResNeXt, self).__init__() with self.init_scope(): self.conv1 = Conv2DBNActiv(None, 64, 7, 2, 3, nobias=True, initialW=initialW) self.pool1 = lambda x: F.max_pooling_2d(x, ksize=3, stride=2) self.res2 = ResBlock(blocks[0], None, 128, 256, 1, **kwargs) self.res3 = ResBlock(blocks[1], None, 256, 512, 2, **kwargs) self.res4 = ResBlock(blocks[2], None, 512, 1024, 2, **kwargs) self.res5 = ResBlock(blocks[3], None, 1024, 2048, 2, **kwargs) self.pool5 = lambda x: F.average(x, axis=(2, 3)) self.fc6 = L.Linear(None, param['n_class'], **fc_kwargs) self.prob = F.softmax if path: chainer.serializers.load_npz(path, self)
Example #19
Source File: rnn_cells.py From knmt with GNU General Public License v3.0 | 5 votes |
def create_initializer(init_type, scale=None, fillvalue=None): if init_type == 'identity': return initializers.Identity() if scale is None else initializers.Identity(scale=scale) if init_type == 'constant': return initializers.Constant(fillvalue) if init_type == 'zero': return initializers.Zero() if init_type == 'one': return initializers.One() if init_type == 'normal': return initializers.Normal() if scale is None else initializers.Normal(scale) if init_type == 'glorotNormal': return initializers.GlorotNormal() if scale is None else initializers.GlorotNormal(scale) if init_type == 'heNormal': return initializers.HeNormal() if scale is None else initializers.HeNormal(scale) if init_type == 'orthogonal': return initializers.Orthogonal( scale) if scale is None else initializers.Orthogonal(scale) if init_type == 'uniform': return initializers.Uniform( scale) if scale is None else initializers.Uniform(scale) if init_type == 'leCunUniform': return initializers.LeCunUniform( scale) if scale is None else initializers.LeCunUniform(scale) if init_type == 'glorotUniform': return initializers.GlorotUniform( scale) if scale is None else initializers.GlorotUniform(scale) if init_type == 'heUniform': return initializers.HeUniform( scale) if scale is None else initializers.HeUniform(scale) raise ValueError("Unknown initializer type: {0}".format(init_type))
Example #20
Source File: resnet50.py From chainer with MIT License | 5 votes |
def __init__(self): super(ResNet50, self).__init__() with self.init_scope(): self.conv1 = L.Convolution2D( 3, 64, 7, 2, 3, initialW=initializers.HeNormal()) self.bn1 = L.BatchNormalization(64) self.res2 = Block(3, 64, 64, 256, 1) self.res3 = Block(4, 256, 128, 512) self.res4 = Block(6, 512, 256, 1024) self.res5 = Block(3, 1024, 512, 2048) self.fc = L.Linear(2048, 1000)
Example #21
Source File: resnet50.py From chainer with MIT License | 5 votes |
def __init__(self, in_size, ch, groups=1): super(BottleNeckB, self).__init__() initialW = initializers.HeNormal() with self.init_scope(): self.conv1 = L.Convolution2D( in_size, ch, 1, 1, 0, initialW=initialW, nobias=True) self.bn1 = L.BatchNormalization(ch) self.conv2 = L.Convolution2D( ch, ch, 3, 1, 1, initialW=initialW, nobias=True, groups=groups) self.bn2 = L.BatchNormalization(ch) self.conv3 = L.Convolution2D( ch, in_size, 1, 1, 0, initialW=initialW, nobias=True) self.bn3 = L.BatchNormalization(in_size)
Example #22
Source File: nin.py From chainer with MIT License | 5 votes |
def __init__(self): super(NIN, self).__init__() conv_init = I.HeNormal() # MSRA scaling with self.init_scope(): self.mlpconv1 = L.MLPConvolution2D( None, (96, 96, 96), 11, stride=4, conv_init=conv_init) self.mlpconv2 = L.MLPConvolution2D( None, (256, 256, 256), 5, pad=2, conv_init=conv_init) self.mlpconv3 = L.MLPConvolution2D( None, (384, 384, 384), 3, pad=1, conv_init=conv_init) self.mlpconv4 = L.MLPConvolution2D( None, (1024, 1024, 1000), 3, pad=1, conv_init=conv_init)
Example #23
Source File: resnet50.py From chainer-compiler with MIT License | 5 votes |
def __init__(self, compute_accuracy=False): super(ResNet50, self).__init__() self.compute_accuracy = compute_accuracy with self.init_scope(): self.conv1 = L.Convolution2D( 3, 64, 7, 2, 3, initialW=initializers.HeNormal()) self.bn1 = L.BatchNormalization(64) self.res2 = Block(3, 64, 64, 256, 1) self.res3 = Block(4, 256, 128, 512) self.res4 = Block(6, 512, 256, 1024) self.res5 = Block(3, 1024, 512, 2048) self.fc = L.Linear(2048, 1000)
Example #24
Source File: nin.py From chainer-compiler with MIT License | 5 votes |
def __init__(self, compute_accuracy=False): super(NIN, self).__init__() self.compute_accuracy = compute_accuracy conv_init = I.HeNormal() # MSRA scaling with self.init_scope(): self.mlpconv1 = L.MLPConvolution2D( None, (96, 96, 96), 11, stride=4, conv_init=conv_init) self.mlpconv2 = L.MLPConvolution2D( None, (256, 256, 256), 5, pad=2, conv_init=conv_init) self.mlpconv3 = L.MLPConvolution2D( None, (384, 384, 384), 3, pad=1, conv_init=conv_init) self.mlpconv4 = L.MLPConvolution2D( None, (1024, 1024, 1000), 3, pad=1, conv_init=conv_init)
Example #25
Source File: Resnet_with_loss.py From chainer-compiler with MIT License | 5 votes |
def __init__(self): super(ResNet50, self).__init__() with self.init_scope(): self.conv1 = L.Convolution2D( 3, 64, 7, 2, 3, initialW=initializers.HeNormal()) self.bn1 = L.BatchNormalization(64) self.res2 = Block(3, 64, 64, 256, 1) self.res3 = Block(4, 256, 128, 512) self.res4 = Block(6, 512, 256, 1024) self.res5 = Block(3, 1024, 512, 2048) self.fc = L.Linear(2048, 1000)
Example #26
Source File: Resnet_with_loss.py From chainer-compiler with MIT License | 5 votes |
def __init__(self, in_size, ch, groups=1): super(BottleNeckB, self).__init__() initialW = initializers.HeNormal() with self.init_scope(): self.conv1 = L.Convolution2D( in_size, ch, 1, 1, 0, initialW=initialW, nobias=True) self.bn1 = L.BatchNormalization(ch) self.conv2 = L.Convolution2D( ch, ch, 3, 1, 1, initialW=initialW, nobias=True, groups=groups) self.bn2 = L.BatchNormalization(ch) self.conv3 = L.Convolution2D( ch, in_size, 1, 1, 0, initialW=initialW, nobias=True) self.bn3 = L.BatchNormalization(in_size)
Example #27
Source File: resblock.py From chainer-compiler with MIT License | 5 votes |
def main(): np.random.seed(314) model = ResBlock(3, None, 64, 256, 1, initialW=initializers.HeNormal(scale=1., fan_option='fan_out'), stride_first=False) v = np.random.rand(2, 64, 56, 56).astype(np.float32) testtools.generate_testcase(model, [v])
Example #28
Source File: Resnet_with_loss.py From chainer-compiler with MIT License | 5 votes |
def __init__(self): super(ResNet50, self).__init__() with self.init_scope(): self.conv1 = L.Convolution2D( 3, 64, 7, 2, 3, initialW=initializers.HeNormal()) self.bn1 = L.BatchNormalization(64) self.res2 = Block(3, 64, 64, 256, 1) self.res3 = Block(4, 256, 128, 512) self.res4 = Block(6, 512, 256, 1024) self.res5 = Block(3, 1024, 512, 2048) self.fc = L.Linear(2048, 1000)
Example #29
Source File: Resnet_with_loss.py From chainer-compiler with MIT License | 5 votes |
def __init__(self, in_size, ch, groups=1): super(BottleNeckB, self).__init__() initialW = initializers.HeNormal() with self.init_scope(): self.conv1 = L.Convolution2D( in_size, ch, 1, 1, 0, initialW=initialW, nobias=True) self.bn1 = L.BatchNormalization(ch) self.conv2 = L.Convolution2D( ch, ch, 3, 1, 1, initialW=initialW, nobias=True, groups=groups) self.bn2 = L.BatchNormalization(ch) self.conv3 = L.Convolution2D( ch, in_size, 1, 1, 0, initialW=initialW, nobias=True) self.bn3 = L.BatchNormalization(in_size)
Example #30
Source File: conv.py From nips17-adversarial-attack with MIT License | 5 votes |
def __init__(self, depth, ksize, stride=1, pad=0, initialW=I.HeNormal()): super(ConvBnRelu, self).__init__() with self.init_scope(): self.conv = L.Convolution2D(None, depth, ksize=ksize, stride=stride, pad=pad, initialW=initialW, nobias=True) self.bn = L.BatchNormalization(depth, decay=0.9997, eps=0.001, use_gamma=False)