本文整理汇总了Python中keras.initializers.RandomNormal方法的典型用法代码示例。如果您正苦于以下问题:Python initializers.RandomNormal方法的具体用法?Python initializers.RandomNormal怎么用?Python initializers.RandomNormal使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类keras.initializers
的用法示例。
在下文中一共展示了initializers.RandomNormal方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: build
# 需要导入模块: from keras import initializers [as 别名]
# 或者: from keras.initializers import RandomNormal [as 别名]
def build(self, input_shape):
assert len(input_shape) >= 2
input_dim = input_shape[-1]
self.kernel = self.add_weight(shape=(input_dim, self.units),
initializer=self.kernel_initializer,
name='kernel',
regularizer=self.kernel_regularizer,
constraint=self.kernel_constraint)
if self.use_bias:
self.bias = self.add_weight(shape=(self.units,),
initializer=self.bias_initializer,
name='bias',
regularizer=self.bias_regularizer,
constraint=self.bias_constraint)
else:
self.bias = None
self.u = self.add_weight(shape=tuple([1, self.kernel.shape.as_list()[-1]]),
initializer=initializers.RandomNormal(0, 1),
name='sn',
trainable=False)
self.input_spec = InputSpec(min_ndim=2, axes={-1: input_dim})
self.built = True
示例2: atl_img_model
# 需要导入模块: from keras import initializers [as 别名]
# 或者: from keras.initializers import RandomNormal [as 别名]
def atl_img_model(vol_shape, mult=1.0, src=None, atl_layer_name='img_params'):
"""
atlas model with flow representation
idea: starting with some (probably rough) atlas (like a ball or average shape),
the output atlas is this input ball plus a
"""
# get a new layer (std)
if src is None:
src = Input(shape=[*vol_shape, 1], name='input_atlas')
# get the velocity field
v_layer = LocalParamWithInput(shape=[*vol_shape, 1],
mult=mult,
name=atl_layer_name,
my_initializer=RandomNormal(mean=0.0, stddev=1e-7))
v = v_layer(src) # this is so memory-wasteful...
return keras.models.Model(src, v)
示例3: __conv_init
# 需要导入模块: from keras import initializers [as 别名]
# 或者: from keras.initializers import RandomNormal [as 别名]
def __conv_init(a):
print("conv_init", a)
k = RandomNormal(0, 0.02)(a) # for convolution kernel
k.conv_weight = True
return k
示例4: upscale_ps
# 需要导入模块: from keras import initializers [as 别名]
# 或者: from keras.initializers import RandomNormal [as 别名]
def upscale_ps(filters, use_norm=True):
def block(x):
x = Conv2D(filters*4, kernel_size=3, use_bias=False, kernel_initializer=RandomNormal(0, 0.02), padding='same' )(x)
x = LeakyReLU(0.1)(x)
x = PixelShuffler()(x)
return x
return block
示例5: cvpr2018_net
# 需要导入模块: from keras import initializers [as 别名]
# 或者: from keras.initializers import RandomNormal [as 别名]
def cvpr2018_net(vol_size, enc_nf, dec_nf, full_size=True, indexing='ij'):
"""
unet architecture for voxelmorph models presented in the CVPR 2018 paper.
You may need to modify this code (e.g., number of layers) to suit your project needs.
:param vol_size: volume size. e.g. (256, 256, 256)
:param enc_nf: list of encoder filters. right now it needs to be 1x4.
e.g. [16,32,32,32]
:param dec_nf: list of decoder filters. right now it must be 1x6 (like voxelmorph-1) or 1x7 (voxelmorph-2)
:return: the keras model
"""
ndims = len(vol_size)
assert ndims in [1, 2, 3], "ndims should be one of 1, 2, or 3. found: %d" % ndims
# get the core model
unet_model = unet_core(vol_size, enc_nf, dec_nf, full_size=full_size)
[src, tgt] = unet_model.inputs
x = unet_model.output
# transform the results into a flow field.
Conv = getattr(KL, 'Conv%dD' % ndims)
flow = Conv(ndims, kernel_size=3, padding='same', name='flow',
kernel_initializer=RandomNormal(mean=0.0, stddev=1e-5))(x)
# warp the source with the flow
y = nrn_layers.SpatialTransformer(interp_method='linear', indexing=indexing)([src, flow])
# prepare model
model = Model(inputs=[src, tgt], outputs=[y, flow])
return model
示例6: __init__
# 需要导入模块: from keras import initializers [as 别名]
# 或者: from keras.initializers import RandomNormal [as 别名]
def __init__(self, shape, my_initializer='RandomNormal', mult=1.0, **kwargs):
self.shape=shape
self.initializer = my_initializer
self.biasmult = mult
super(LocalParamWithInput, self).__init__(**kwargs)
示例7: build
# 需要导入模块: from keras import initializers [as 别名]
# 或者: from keras.initializers import RandomNormal [as 别名]
def build(self, input_shape):
# Create a trainable weight variable for this layer.
self.i_embedding = self.add_weight(
shape=(self.input_dim_i, self.rank),
initializer=RandomNormal(mean=0.0, stddev=1 / np.sqrt(self.rank)),
name='i_embedding',
regularizer=self.embeddings_regularizer
)
self.j_embedding = self.add_weight(
shape=(self.input_dim_j, self.rank),
initializer=RandomNormal(mean=0.0, stddev=1 / np.sqrt(self.rank)),
name='j_embedding',
regularizer=self.embeddings_regularizer
)
if self.use_bias:
self.i_bias = self.add_weight(
shape=(self.input_dim_i, 1),
initializer='zeros',
name='i_bias'
)
self.j_bias = self.add_weight(
shape=(self.input_dim_j, 1),
initializer='zeros',
name='j_bias'
)
self.constant = self.add_weight(
shape=(1, 1),
initializer='zeros',
name='constant',
)
self.built = True
super(KerasMatrixFactorizer, self).build(input_shape)
示例8: test_normal
# 需要导入模块: from keras import initializers [as 别名]
# 或者: from keras.initializers import RandomNormal [as 别名]
def test_normal(tensor_shape):
_runner(initializers.RandomNormal(mean=0, stddev=1), tensor_shape,
target_mean=0., target_std=1)
示例9: __init__
# 需要导入模块: from keras import initializers [as 别名]
# 或者: from keras.initializers import RandomNormal [as 别名]
def __init__(self, filters, init_normal_stddev=0.01, **kwargs):
"""Init"""
self.filters = filters
super(ConvOffset2D, self).__init__(
self.filters * 2, (3, 3), padding='same', use_bias=False,
# TODO gradients are near zero if init is zeros
kernel_initializer='zeros',
# kernel_initializer=RandomNormal(0, init_normal_stddev),
**kwargs
)
示例10: __init__
# 需要导入模块: from keras import initializers [as 别名]
# 或者: from keras.initializers import RandomNormal [as 别名]
def __init__(self, *args, **kwargs):
logger.debug("Initializing %s: (args: %s, kwargs: %s",
self.__class__.__name__, args, kwargs)
self.configfile = kwargs.get("configfile", None)
self.lowmem = self.config.get("lowmem", False)
kwargs["input_shape"] = (self.config["input_size"], self.config["input_size"], 3)
kwargs["encoder_dim"] = 512 if self.lowmem else self.config["nodes"]
self.kernel_initializer = RandomNormal(0, 0.02)
super().__init__(*args, **kwargs)
logger.debug("Initialized %s", self.__class__.__name__)
示例11: __init__
# 需要导入模块: from keras import initializers [as 别名]
# 或者: from keras.initializers import RandomNormal [as 别名]
def __init__(self, *args, **kwargs):
logger.debug("Initializing %s: (args: %s, kwargs: %s",
self.__class__.__name__, args, kwargs)
kwargs["input_shape"] = (64, 64, 3)
kwargs["encoder_dim"] = 1024
self.kernel_initializer = RandomNormal(0, 0.02)
super().__init__(*args, **kwargs)
logger.debug("Initialized %s", self.__class__.__name__)
示例12: __init__
# 需要导入模块: from keras import initializers [as 别名]
# 或者: from keras.initializers import RandomNormal [as 别名]
def __init__(self, *args, **kwargs):
logger.debug("Initializing %s: (args: %s, kwargs: %s",
self.__class__.__name__, args, kwargs)
self.configfile = kwargs.get("configfile", None)
self.check_input_output()
self.dense_width, self.upscalers_no = self.get_dense_width_upscalers_numbers()
kwargs["input_shape"] = (self.config["input_size"], self.config["input_size"], 3)
self.kernel_initializer = RandomNormal(0, 0.02)
super().__init__(*args, **kwargs)
logger.debug("Initialized %s", self.__class__.__name__)
示例13: __init__
# 需要导入模块: from keras import initializers [as 别名]
# 或者: from keras.initializers import RandomNormal [as 别名]
def __init__(self, *args, **kwargs):
logger.debug("Initializing %s: (args: %s, kwargs: %s",
self.__class__.__name__, args, kwargs)
self.configfile = kwargs.get("configfile", None)
kwargs["input_shape"] = (128, 128, 3)
kwargs["encoder_dim"] = 512 if self.config["lowmem"] else 1024
self.kernel_initializer = RandomNormal(0, 0.02)
super().__init__(*args, **kwargs)
logger.debug("Initialized %s", self.__class__.__name__)
示例14: wcrn3D
# 需要导入模块: from keras import initializers [as 别名]
# 或者: from keras.initializers import RandomNormal [as 别名]
def wcrn3D(band, ncla1):
input1 = Input(shape=(5,5,band))
# define network
conv0x = Conv2D(64,kernel_size=(1,1,7),padding='valid',
kernel_initializer=RandomNormal(mean=0.0, stddev=0.01))
conv0 = Conv2D(64,kernel_size=(3,3,1),padding='valid',
kernel_initializer=RandomNormal(mean=0.0, stddev=0.01))
bn11 = BatchNormalization(axis=-1,momentum=0.9,epsilon=0.001,center=True,scale=True,
beta_initializer='zeros',gamma_initializer='ones',
moving_mean_initializer='zeros',
moving_variance_initializer='ones')
conv11 = Conv2D(128,kernel_size=(1,1),padding='same',
kernel_initializer=RandomNormal(mean=0.0, stddev=0.01))
conv12 = Conv2D(128,kernel_size=(1,1),padding='same',
kernel_initializer=RandomNormal(mean=0.0, stddev=0.01))
fc1 = Dense(ncla1,activation='softmax',name='output1',
kernel_initializer=RandomNormal(mean=0.0, stddev=0.01))
# x1
x1 = conv0(input1)
x1x = conv0x(input1)
x1 = MaxPooling2D(pool_size=(3,3))(x1)
x1x = MaxPooling2D(pool_size=(5,5))(x1x)
x1 = concatenate([x1,x1x],axis=-1)
x11 = bn11(x1)
x11 = Activation('relu')(x11)
x11 = conv11(x11)
x11 = Activation('relu')(x11)
x11 = conv12(x11)
x1 = Add()([x1,x11])
x1 = Flatten()(x1)
pre1 = fc1(x1)
model1 = Model(inputs=input1, outputs=pre1)
return model1
示例15: wcrn
# 需要导入模块: from keras import initializers [as 别名]
# 或者: from keras.initializers import RandomNormal [as 别名]
def wcrn(band, ncla1):
input1 = Input(shape=(5,5,band))
# define network
conv0x = Conv2D(64,kernel_size=(1,1),padding='valid',
kernel_initializer=RandomNormal(mean=0.0, stddev=0.01))
conv0 = Conv2D(64,kernel_size=(3,3),padding='valid',
kernel_initializer=RandomNormal(mean=0.0, stddev=0.01))
bn11 = BatchNormalization(axis=-1,momentum=0.9,epsilon=0.001,center=True,scale=True,
beta_initializer='zeros',gamma_initializer='ones',
moving_mean_initializer='zeros',
moving_variance_initializer='ones')
conv11 = Conv2D(128,kernel_size=(1,1),padding='same',
kernel_initializer=RandomNormal(mean=0.0, stddev=0.01))
conv12 = Conv2D(128,kernel_size=(1,1),padding='same',
kernel_initializer=RandomNormal(mean=0.0, stddev=0.01))
#
fc1 = Dense(ncla1,activation='softmax',name='output1',
kernel_initializer=RandomNormal(mean=0.0, stddev=0.01))
# x1
x1 = conv0(input1)
x1x = conv0x(input1)
x1 = MaxPooling2D(pool_size=(3,3))(x1)
x1x = MaxPooling2D(pool_size=(5,5))(x1x)
x1 = concatenate([x1,x1x],axis=-1)
x11 = bn11(x1)
x11 = Activation('relu')(x11)
x11 = conv11(x11)
x11 = Activation('relu')(x11)
x11 = conv12(x11)
x1 = Add()([x1,x11])
x1 = Flatten()(x1)
pre1 = fc1(x1)
model1 = Model(inputs=input1, outputs=pre1)
return model1