本文整理汇总了Python中tensorflow.keras.backend.dot方法的典型用法代码示例。如果您正苦于以下问题:Python backend.dot方法的具体用法?Python backend.dot怎么用?Python backend.dot使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tensorflow.keras.backend
的用法示例。
在下文中一共展示了backend.dot方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: call
# 需要导入模块: from tensorflow.keras import backend [as 别名]
# 或者: from tensorflow.keras.backend import dot [as 别名]
def call(self, x):
power_spectrogram = super(Melspectrogram, self).call(x)
# now, channels_first: (batch_sample, n_ch, n_freq, n_time)
# channels_last: (batch_sample, n_freq, n_time, n_ch)
if self.image_data_format == 'channels_first':
power_spectrogram = K.permute_dimensions(power_spectrogram, [0, 1, 3, 2])
else:
power_spectrogram = K.permute_dimensions(power_spectrogram, [0, 3, 2, 1])
# now, whatever image_data_format, (batch_sample, n_ch, n_time, n_freq)
output = K.dot(power_spectrogram, self.freq2mel)
if self.image_data_format == 'channels_first':
output = K.permute_dimensions(output, [0, 1, 3, 2])
else:
output = K.permute_dimensions(output, [0, 3, 2, 1])
if self.power_melgram != 2.0:
output = K.pow(K.sqrt(output), self.power_melgram)
if self.return_decibel_melgram:
output = backend_keras.amplitude_to_decibel(output)
return output
示例2: call
# 需要导入模块: from tensorflow.keras import backend [as 别名]
# 或者: from tensorflow.keras.backend import dot [as 别名]
def call(self, inputs):
if self.data_mode == 'disjoint':
X, I = inputs
if K.ndim(I) == 2:
I = I[:, 0]
else:
X = inputs
attn_coeff = K.dot(X, self.attn_kernel)
attn_coeff = K.squeeze(attn_coeff, -1)
attn_coeff = K.softmax(attn_coeff)
if self.data_mode == 'single':
output = K.dot(attn_coeff[None, ...], X)
elif self.data_mode == 'batch':
output = K.batch_dot(attn_coeff, X)
else:
output = attn_coeff[:, None] * X
output = tf.math.segment_sum(output, I)
return output
示例3: call
# 需要导入模块: from tensorflow.keras import backend [as 别名]
# 或者: from tensorflow.keras.backend import dot [as 别名]
def call(self, inputs):
features = inputs[0]
fltr = inputs[1]
# Convolution
output = K.dot(features, self.kernel_1)
output = ops.filter_dot(fltr, output)
# Skip connection
skip = K.dot(features, self.kernel_2)
output += skip
if self.use_bias:
output = K.bias_add(output, self.bias)
if self.activation is not None:
output = self.activation(output)
return output
示例4: _rotation_matrix_zyz
# 需要导入模块: from tensorflow.keras import backend [as 别名]
# 或者: from tensorflow.keras.backend import dot [as 别名]
def _rotation_matrix_zyz(self, params):
phi = params[0] * 2 * np.pi - np.pi; theta = params[1] * 2 * np.pi - np.pi; psi_t = params[2] * 2 * np.pi - np.pi;
loc_r = params[3:6] * 2 - 1
a1 = self._rotation_matrix_axis(2, psi_t) # first rotate about z axis for angle psi_t
a2 = self._rotation_matrix_axis(1, theta)
a3 = self._rotation_matrix_axis(2, phi)
rm = K.dot(K.dot(a3,a2),a1)
rm = tf.transpose(rm)
c = K.dot(-rm, K.expand_dims(loc_r))
rm = K.flatten(rm)
theta = K.concatenate([rm[:3], c[0], rm[3:6], c[1], rm[6:9], c[2]])
return theta
示例5: _mask_rotation_matrix_zyz
# 需要导入模块: from tensorflow.keras import backend [as 别名]
# 或者: from tensorflow.keras.backend import dot [as 别名]
def _mask_rotation_matrix_zyz(self, params):
phi = params[0] * 2 * np.pi - np.pi; theta = params[1] * 2 * np.pi - np.pi; psi_t = params[2] * 2 * np.pi - np.pi;
loc_r = params[3:6] * 0 # magnitude of Fourier transformation is translation-invariant
a1 = self._rotation_matrix_axis(2, psi_t)
a2 = self._rotation_matrix_axis(1, theta)
a3 = self._rotation_matrix_axis(2, phi)
rm = K.dot(K.dot(a3,a2),a1)
rm = tf.transpose(rm)
c = K.dot(-rm, K.expand_dims(loc_r))
rm = K.flatten(rm)
theta = K.concatenate([rm[:3], c[0], rm[3:6], c[1], rm[6:9], c[2]])
return theta
示例6: _lstm
# 需要导入模块: from tensorflow.keras import backend [as 别名]
# 或者: from tensorflow.keras.backend import dot [as 别名]
def _lstm(self, h, c):
# lstm implementation here
z = kb.dot(h, self.recurrent_kernel)
if self.use_bias:
z += self.recurrent_bias
z0 = z[:, :, :self.n_hidden]
z1 = z[:, :, self.n_hidden:2 * self.n_hidden]
z2 = z[:, :, 2 * self.n_hidden:3 * self.n_hidden]
z3 = z[:, :, 3 * self.n_hidden:]
i = self.recurrent_activation(z0)
f = self.recurrent_activation(z1)
# print(z.shape, f.shape, c.shape, z2.shape)
c = f * c + i * self.activation_lstm(z2)
o = self.recurrent_activation(z3)
h = o * self.activation_lstm(c)
return h, c
示例7: call
# 需要导入模块: from tensorflow.keras import backend [as 别名]
# 或者: from tensorflow.keras.backend import dot [as 别名]
def call(self, x):
# reshape so that the last axis is freq axis
if self.image_data_format == 'channels_first':
x = K.permute_dimensions(x, [0, 1, 3, 2])
else:
x = K.permute_dimensions(x, [0, 3, 2, 1])
output = K.dot(x, self.filterbank)
# reshape back
if self.image_data_format == 'channels_first':
return K.permute_dimensions(output, [0, 1, 3, 2])
else:
return K.permute_dimensions(output, [0, 3, 2, 1])
示例8: call
# 需要导入模块: from tensorflow.keras import backend [as 别名]
# 或者: from tensorflow.keras.backend import dot [as 别名]
def call(self, inputs):
"""Execute this layer on input tensors.
Parameters
----------
inputs: list
List of three tensors (x, h_tm1, c_tm1). h_tm1 means "h, t-1".
Returns
-------
list
Returns h, [h, c]
"""
x, h_tm1, c_tm1 = inputs
# Taken from Keras code [citation needed]
z = backend.dot(x, self.W) + backend.dot(h_tm1, self.U) + self.b
z0 = z[:, :self.output_dim]
z1 = z[:, self.output_dim:2 * self.output_dim]
z2 = z[:, 2 * self.output_dim:3 * self.output_dim]
z3 = z[:, 3 * self.output_dim:]
i = self.inner_activation_fn(z0)
f = self.inner_activation_fn(z1)
c = f * c_tm1 + i * self.activation_fn(z2)
o = self.inner_activation_fn(z3)
h = o * self.activation_fn(c)
return h, [h, c]
示例9: _cosine_dist
# 需要导入模块: from tensorflow.keras import backend [as 别名]
# 或者: from tensorflow.keras.backend import dot [as 别名]
def _cosine_dist(x, y):
"""Computes the inner product (cosine distance) between two tensors.
Parameters
----------
x: tf.Tensor
Input Tensor
y: tf.Tensor
Input Tensor
"""
denom = (backend.sqrt(backend.sum(tf.square(x)) * backend.sum(tf.square(y))) +
backend.epsilon())
return backend.dot(x, tf.transpose(y)) / denom
示例10: call
# 需要导入模块: from tensorflow.keras import backend [as 别名]
# 或者: from tensorflow.keras.backend import dot [as 别名]
def call(self, inputs):
if self.trainable_kernel:
output = K.dot(K.dot(inputs, self.kernel), K.transpose(inputs))
else:
output = K.dot(inputs, K.transpose(inputs))
if self.activation is not None:
output = self.activation(output)
return output
示例11: compute_scores
# 需要导入模块: from tensorflow.keras import backend [as 别名]
# 或者: from tensorflow.keras.backend import dot [as 别名]
def compute_scores(self, X, A, I):
scores = K.dot(X, self.kernel)
scores = ops.filter_dot(A, scores)
return scores
示例12: compute_scores
# 需要导入模块: from tensorflow.keras import backend [as 别名]
# 或者: from tensorflow.keras.backend import dot [as 别名]
def compute_scores(self, X, A, I):
return K.dot(X, K.l2_normalize(self.kernel))
示例13: call
# 需要导入模块: from tensorflow.keras import backend [as 别名]
# 或者: from tensorflow.keras.backend import dot [as 别名]
def call(self, inputs):
# Implement Eq.(9)
perturbed_kernel = self.kernel + \
self.sigma_kernel * K.random_uniform(shape=self.kernel_shape)
outputs = K.dot(inputs, perturbed_kernel)
if self.use_bias:
perturbed_bias = self.bias + \
self.sigma_bias * K.random_uniform(shape=self.bias_shape)
outputs = K.bias_add(outputs, perturbed_bias)
if self.activation is not None:
outputs = self.activation(outputs)
return outputs
示例14: build
# 需要导入模块: from tensorflow.keras import backend [as 别名]
# 或者: from tensorflow.keras.backend import dot [as 别名]
def build(self, input_shape):
# Create a trainable weight variable for this layer.
self.kernel = self.add_weight(name='mult-kernel',
shape=(np.prod(self.orig_input_shape),
self.output_len),
initializer=self.kernel_initializer,
trainable=True)
M = K.reshape(self.kernel, [-1, self.output_len]) # D x d
mt = K.transpose(M) # d x D
mtm_inv = tf.matrix_inverse(K.dot(mt, M)) # d x d
self.W = K.dot(mtm_inv, mt) # d x D
if self.use_bias:
self.bias = self.add_weight(name='bias-kernel',
shape=(self.output_len, ),
initializer=self.bias_initializer,
trainable=True)
# self.sigma_sq = self.add_weight(name='bias-kernel',
# shape=(1, ),
# initializer=self.initializer,
# trainable=True)
super(SpatiallySparse_Dense, self).build(input_shape) # Be sure to call this somewhere!
示例15: call
# 需要导入模块: from tensorflow.keras import backend [as 别名]
# 或者: from tensorflow.keras.backend import dot [as 别名]
def call(self, x, **kwargs):
# (x - y)^2 = x^2 + y^2 - 2 * x * y
x_sq = K.expand_dims(K.sum(x ** 2, axis=2), axis=-1)
y_sq = K.reshape(K.sum(self.kernel ** 2, axis=1),
(1, 1, self.n_shapelets))
xy = K.dot(x, K.transpose(self.kernel))
return (x_sq + y_sq - 2 * xy) / K.int_shape(self.kernel)[1]