本文整理汇总了Python中tensorflow.sparse_transpose方法的典型用法代码示例。如果您正苦于以下问题:Python tensorflow.sparse_transpose方法的具体用法?Python tensorflow.sparse_transpose怎么用?Python tensorflow.sparse_transpose使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tensorflow
的用法示例。
在下文中一共展示了tensorflow.sparse_transpose方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testTranspose
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import sparse_transpose [as 别名]
def testTranspose(self):
with self.test_session(use_gpu=False):
np.random.seed(1618)
shapes = [np.random.randint(1, 10, size=rank) for rank in range(1, 6)]
for shape in shapes:
for dtype in [np.int32, np.int64, np.float32, np.float64]:
dn_input = np.random.randn(*shape).astype(dtype)
rank = tf.rank(dn_input).eval()
perm = np.random.choice(rank, rank, False)
sp_input, unused_a_nnz = _sparsify(dn_input)
sp_trans = tf.sparse_transpose(sp_input, perm=perm)
dn_trans = tf.sparse_tensor_to_dense(sp_trans).eval()
expected_trans = tf.transpose(dn_input, perm=perm).eval()
self.assertAllEqual(dn_trans, expected_trans)
示例2: decoded
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import sparse_transpose [as 别名]
def decoded(self) -> tf.Tensor:
if self.beam_width == 1:
decoded, _ = tf.nn.ctc_greedy_decoder(
inputs=self.logits, sequence_length=self.encoder.lengths,
merge_repeated=self.merge_repeated_outputs)
else:
decoded, _ = tf.nn.ctc_beam_search_decoder(
inputs=self.logits, sequence_length=self.encoder.lengths,
beam_width=self.beam_width,
merge_repeated=self.merge_repeated_outputs)
return tf.sparse_tensor_to_dense(
tf.sparse_transpose(decoded[0]),
default_value=END_TOKEN_INDEX)
示例3: get_transpose_op
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import sparse_transpose [as 别名]
def get_transpose_op(sparse_features=True):
if (sparse_features):
return tf.sparse_transpose
else:
return tf.transpose
示例4: _attn_r_n_m_h
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import sparse_transpose [as 别名]
def _attn_r_n_m_h(self):
h, r, n = self.heads, self.relations, self._nodes
attn_h_n_rm = self._attn_h_n_rm
attn_h_n_r_m = tf.sparse_reshape(attn_h_n_rm, [h, n, r, n])
attn_r_n_m_h = tf.sparse_transpose(attn_h_n_r_m, [2, 1, 3, 0])
return attn_r_n_m_h