當前位置: 首頁>>代碼示例>>Python>>正文


Python backend.dot方法代碼示例

本文整理匯總了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 
開發者ID:keunwoochoi,項目名稱:kapre,代碼行數:21,代碼來源:time_frequency.py

示例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 
開發者ID:danielegrattarola,項目名稱:spektral,代碼行數:21,代碼來源:global_pool.py

示例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 
開發者ID:danielegrattarola,項目名稱:spektral,代碼行數:19,代碼來源:graph_conv_skip.py

示例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 
開發者ID:xulabs,項目名稱:aitom,代碼行數:22,代碼來源:RigidTransformation3DImputation.py

示例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 
開發者ID:xulabs,項目名稱:aitom,代碼行數:22,代碼來源:RigidTransformation3DImputation.py

示例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 
開發者ID:materialsvirtuallab,項目名稱:megnet,代碼行數:18,代碼來源:set2set.py

示例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]) 
開發者ID:keunwoochoi,項目名稱:kapre,代碼行數:14,代碼來源:filterbank.py

示例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] 
開發者ID:deepchem,項目名稱:deepchem,代碼行數:32,代碼來源:layers.py

示例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 
開發者ID:deepchem,項目名稱:deepchem,代碼行數:15,代碼來源:layers.py

示例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 
開發者ID:danielegrattarola,項目名稱:spektral,代碼行數:10,代碼來源:base.py

示例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 
開發者ID:danielegrattarola,項目名稱:spektral,代碼行數:6,代碼來源:sag_pool.py

示例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)) 
開發者ID:danielegrattarola,項目名稱:spektral,代碼行數:4,代碼來源:topk_pool.py

示例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 
開發者ID:keiohta,項目名稱:tf2rl,代碼行數:14,代碼來源:noisy_dense.py

示例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! 
開發者ID:adalca,項目名稱:neuron,代碼行數:30,代碼來源:layers.py

示例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] 
開發者ID:tslearn-team,項目名稱:tslearn,代碼行數:9,代碼來源:shapelets.py


注:本文中的tensorflow.keras.backend.dot方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。