本文整理汇总了Python中tensorflow.keras.initializers.get方法的典型用法代码示例。如果您正苦于以下问题:Python initializers.get方法的具体用法?Python initializers.get怎么用?Python initializers.get使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tensorflow.keras.initializers
的用法示例。
在下文中一共展示了initializers.get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: build
# 需要导入模块: from tensorflow.keras import initializers [as 别名]
# 或者: from tensorflow.keras.initializers import get [as 别名]
def build(self, input_shape):
self.W_list = []
self.b_list = []
init = initializers.get(self.init)
prev_layer_size = self.n_embedding
for i, layer_size in enumerate(self.layer_sizes):
self.W_list.append(init([prev_layer_size, layer_size]))
self.b_list.append(backend.zeros(shape=[
layer_size,
]))
prev_layer_size = layer_size
self.W_list.append(init([prev_layer_size, self.n_outputs]))
self.b_list.append(backend.zeros(shape=[
self.n_outputs,
]))
self.built = True
示例2: __init__
# 需要导入模块: from tensorflow.keras import initializers [as 别名]
# 或者: from tensorflow.keras.initializers import get [as 别名]
def __init__(self,
ratio,
return_mask=False,
sigmoid_gating=False,
kernel_initializer='glorot_uniform',
kernel_regularizer=None,
kernel_constraint=None,
**kwargs):
super().__init__(**kwargs)
self.ratio = ratio
self.return_mask = return_mask
self.sigmoid_gating = sigmoid_gating
self.gating_op = K.sigmoid if self.sigmoid_gating else K.tanh
self.kernel_initializer = initializers.get(kernel_initializer)
self.kernel_regularizer = regularizers.get(kernel_regularizer)
self.kernel_constraint = constraints.get(kernel_constraint)
示例3: __init__
# 需要导入模块: from tensorflow.keras import initializers [as 别名]
# 或者: from tensorflow.keras.initializers import get [as 别名]
def __init__(self,
channels,
kernel_initializer='glorot_uniform',
bias_initializer='zeros',
kernel_regularizer=None,
bias_regularizer=None,
kernel_constraint=None,
bias_constraint=None,
**kwargs):
super().__init__(**kwargs)
self.channels = channels
self.kernel_initializer = initializers.get(kernel_initializer)
self.bias_initializer = initializers.get(bias_initializer)
self.kernel_regularizer = regularizers.get(kernel_regularizer)
self.bias_regularizer = regularizers.get(bias_regularizer)
self.kernel_constraint = constraints.get(kernel_constraint)
self.bias_constraint = constraints.get(bias_constraint)
示例4: __init__
# 需要导入模块: from tensorflow.keras import initializers [as 别名]
# 或者: from tensorflow.keras.initializers import get [as 别名]
def __init__(self,
k,
channels=None,
return_mask=False,
activation=None,
kernel_initializer='glorot_uniform',
kernel_regularizer=None,
kernel_constraint=None,
**kwargs):
super().__init__(**kwargs)
self.k = k
self.channels = channels
self.return_mask = return_mask
self.activation = activations.get(activation)
self.kernel_initializer = initializers.get(kernel_initializer)
self.kernel_regularizer = regularizers.get(kernel_regularizer)
self.kernel_constraint = constraints.get(kernel_constraint)
示例5: __init__
# 需要导入模块: from tensorflow.keras import initializers [as 别名]
# 或者: from tensorflow.keras.initializers import get [as 别名]
def __init__(self,
channels,
activation=None,
use_bias=True,
kernel_initializer='glorot_uniform',
bias_initializer='zeros',
kernel_regularizer=None,
bias_regularizer=None,
activity_regularizer=None,
kernel_constraint=None,
bias_constraint=None,
**kwargs):
super().__init__(activity_regularizer=activity_regularizer, **kwargs)
self.channels = channels
self.activation = activations.get(activation)
self.use_bias = use_bias
self.kernel_initializer = initializers.get(kernel_initializer)
self.bias_initializer = initializers.get(bias_initializer)
self.kernel_regularizer = regularizers.get(kernel_regularizer)
self.bias_regularizer = regularizers.get(bias_regularizer)
self.kernel_constraint = constraints.get(kernel_constraint)
self.bias_constraint = constraints.get(bias_constraint)
self.supports_masking = False
示例6: build
# 需要导入模块: from tensorflow.keras import initializers [as 别名]
# 或者: from tensorflow.keras.initializers import get [as 别名]
def build(self, input_shape):
# Create mean and count
# These are weights because just maintaining variables don't get saved with the model, and we'd like
# to have these numbers saved when we save the model.
# But we need to make sure that the weights are untrainable.
self.mean = self.add_weight(name='mean',
shape=input_shape[1:],
initializer='zeros',
trainable=False)
self.count = self.add_weight(name='count',
shape=[1],
initializer='zeros',
trainable=False)
# self.mean = K.zeros(input_shape[1:], name='mean')
# self.count = K.variable(0.0, name='count')
super(MeanStream, self).build(input_shape) # Be sure to call this somewhere!
示例7: call
# 需要导入模块: from tensorflow.keras import initializers [as 别名]
# 或者: from tensorflow.keras.initializers import get [as 别名]
def call(self, inputx):
if not inputx.dtype in [tf.complex64, tf.complex128]:
print('Warning: inputx is not complex. Converting.', file=sys.stderr)
# if inputx is float, this will assume 0 imag channel
inputx = tf.cast(inputx, tf.complex64)
# get the right fft
if self.ndims == 1:
fft = tf.fft
elif self.ndims == 2:
fft = tf.fft2d
else:
fft = tf.fft3d
perm_dims = [0, self.ndims + 1] + list(range(1, self.ndims + 1))
invert_perm_ndims = [0] + list(range(2, self.ndims + 2)) + [1]
perm_inputx = K.permute_dimensions(inputx, perm_dims) # [batch_size, nb_features, *vol_size]
fft_inputx = fft(perm_inputx)
return K.permute_dimensions(fft_inputx, invert_perm_ndims)
示例8: convert_sequence_vocab
# 需要导入模块: from tensorflow.keras import initializers [as 别名]
# 或者: from tensorflow.keras.initializers import get [as 别名]
def convert_sequence_vocab(self, sequence, sequence_lengths):
PFAM_TO_UNIREP_ENCODED = {encoding: UNIREP_VOCAB.get(aa, 23) for aa, encoding in PFAM_VOCAB.items()}
def to_uniprot_unirep(seq, seqlens):
new_seq = np.zeros_like(seq)
for pfam_encoding, unirep_encoding in PFAM_TO_UNIREP_ENCODED.items():
new_seq[seq == pfam_encoding] = unirep_encoding
# add start/stop
new_seq = np.pad(new_seq, [[0, 0], [1, 1]], mode='constant')
new_seq[:, 0] = UNIREP_VOCAB['<START>']
new_seq[np.arange(new_seq.shape[0]), seqlens + 1] = UNIREP_VOCAB['<STOP>']
return new_seq
new_sequence = tf.py_func(to_uniprot_unirep, [sequence, sequence_lengths], sequence.dtype)
new_sequence.set_shape([sequence.shape[0], sequence.shape[1] + 2])
return new_sequence
示例9: __init__
# 需要导入模块: from tensorflow.keras import initializers [as 别名]
# 或者: from tensorflow.keras.initializers import get [as 别名]
def __init__(self,
output_dim: int,
decomp_size: int,
use_bias: Optional[bool] = True,
activation: Optional[Text] = None,
kernel_initializer: Optional[Text] = 'glorot_uniform',
bias_initializer: Optional[Text] = 'zeros',
**kwargs) -> None:
# Allow specification of input_dim instead of input_shape,
# for compatability with Keras layers that support this
if 'input_shape' not in kwargs and 'input_dim' in kwargs:
kwargs['input_shape'] = (kwargs.pop('input_dim'),)
super(DenseDecomp, self).__init__(**kwargs)
self.output_dim = output_dim
self.decomp_size = decomp_size
self.use_bias = use_bias
self.activation = activations.get(activation)
self.kernel_initializer = initializers.get(kernel_initializer)
self.bias_initializer = initializers.get(bias_initializer)
示例10: __init__
# 需要导入模块: from tensorflow.keras import initializers [as 别名]
# 或者: from tensorflow.keras.initializers import get [as 别名]
def __init__(self,
exp_base: int,
num_nodes: int,
use_bias: Optional[bool] = True,
activation: Optional[Text] = None,
kernel_initializer: Optional[Text] = 'glorot_uniform',
bias_initializer: Optional[Text] = 'zeros',
**kwargs) -> None:
if 'input_shape' not in kwargs and 'input_dim' in kwargs:
kwargs['input_shape'] = (kwargs.pop('input_dim'),)
super(DenseCondenser, self).__init__(**kwargs)
self.exp_base = exp_base
self.num_nodes = num_nodes
self.nodes = []
self.use_bias = use_bias
self.activation = activations.get(activation)
self.kernel_initializer = initializers.get(kernel_initializer)
self.bias_initializer = initializers.get(bias_initializer)
示例11: __init__
# 需要导入模块: from tensorflow.keras import initializers [as 别名]
# 或者: from tensorflow.keras.initializers import get [as 别名]
def __init__(self,
activation: OptStrOrCallable = None,
use_bias: bool = True,
kernel_initializer: OptStrOrCallable = 'glorot_uniform',
bias_initializer: OptStrOrCallable = 'zeros',
kernel_regularizer: OptStrOrCallable = None,
bias_regularizer: OptStrOrCallable = None,
activity_regularizer: OptStrOrCallable = None,
kernel_constraint: OptStrOrCallable = None,
bias_constraint: OptStrOrCallable = None,
**kwargs):
if 'input_shape' not in kwargs and 'input_dim' in kwargs:
kwargs['input_shape'] = (kwargs.pop('input_dim'),)
self.activation = activations.get(activation) # noqa
self.use_bias = use_bias
self.kernel_initializer = initializers.get(kernel_initializer)
self.bias_initializer = initializers.get(bias_initializer)
self.kernel_regularizer = regularizers.get(kernel_regularizer)
self.bias_regularizer = regularizers.get(bias_regularizer)
self.activity_regularizer = regularizers.get(activity_regularizer)
self.kernel_constraint = constraints.get(kernel_constraint)
self.bias_constraint = constraints.get(bias_constraint)
super().__init__(**kwargs)
示例12: call
# 需要导入模块: from tensorflow.keras import initializers [as 别名]
# 或者: from tensorflow.keras.initializers import get [as 别名]
def call(self, inputs):
def brelu(x):
# get shape of X, we are interested in the last axis, which is constant
shape = K.int_shape(x)
# last axis
dim = shape[-1]
# half of the last axis (+1 if necessary)
dim2 = dim // 2
if dim % 2 != 0:
dim2 += 1
# multiplier will be a tensor of alternated +1 and -1
multiplier = K.ones((dim2,))
multiplier = K.stack([multiplier, -multiplier], axis=-1)
if dim % 2 != 0:
multiplier = multiplier[:-1]
# adjust multiplier shape to the shape of x
multiplier = K.reshape(multiplier, tuple(1 for _ in shape[:-1]) + (-1,))
return multiplier * tf.nn.relu(multiplier * x)
return Lambda(brelu)(inputs)
示例13: __init__
# 需要导入模块: from tensorflow.keras import initializers [as 别名]
# 或者: from tensorflow.keras.initializers import get [as 别名]
def __init__(self,
output_dim,
input_dim,
init_fn='glorot_uniform',
inner_init_fn='orthogonal',
activation_fn='tanh',
inner_activation_fn='hard_sigmoid',
**kwargs):
"""
Parameters
----------
output_dim: int
Dimensionality of output vectors.
input_dim: int
Dimensionality of input vectors.
init_fn: str
TensorFlow nitialization to use for W.
inner_init_fn: str
TensorFlow initialization to use for U.
activation_fn: str
TensorFlow activation to use for output.
inner_activation_fn: str
TensorFlow activation to use for inner steps.
"""
super(LSTMStep, self).__init__(**kwargs)
self.init = init_fn
self.inner_init = inner_init_fn
self.output_dim = output_dim
# No other forget biases supported right now.
self.activation = activation_fn
self.inner_activation = inner_activation_fn
self.activation_fn = activations.get(activation_fn)
self.inner_activation_fn = activations.get(inner_activation_fn)
self.input_dim = input_dim
示例14: __init__
# 需要导入模块: from tensorflow.keras import initializers [as 别名]
# 或者: from tensorflow.keras.initializers import get [as 别名]
def __init__(self,
filters,
kernel_size,
strides=1,
padding='valid',
dilation_rate=1,
kernel_initializer='glorot_uniform',
kernel_regularizer=None,
activity_regularizer=None,
kernel_constraint=None,
demod=True,
**kwargs):
super(Conv2DMod, self).__init__(**kwargs)
self.filters = filters
self.rank = 2
self.kernel_size = conv_utils.normalize_tuple(kernel_size, 2, 'kernel_size')
self.strides = conv_utils.normalize_tuple(strides, 2, 'strides')
self.padding = conv_utils.normalize_padding(padding)
self.dilation_rate = conv_utils.normalize_tuple(dilation_rate, 2, 'dilation_rate')
self.kernel_initializer = initializers.get(kernel_initializer)
self.kernel_regularizer = regularizers.get(kernel_regularizer)
self.activity_regularizer = regularizers.get(activity_regularizer)
self.kernel_constraint = constraints.get(kernel_constraint)
self.demod = demod
self.input_spec = [InputSpec(ndim = 4),
InputSpec(ndim = 2)]
示例15: deserialize_kwarg
# 需要导入模块: from tensorflow.keras import initializers [as 别名]
# 或者: from tensorflow.keras.initializers import get [as 别名]
def deserialize_kwarg(key, attr):
if key.endswith('_initializer'):
return initializers.get(attr)
if key.endswith('_regularizer'):
return regularizers.get(attr)
if key.endswith('_constraint'):
return constraints.get(attr)
if key == 'activation':
return activations.get(attr)