tensorflow2.0中有pytorch的max运算吗?

问题描述 投票:0回答:2
overlap-> tensor([[0.0000, 0.0000, 0.0000,  ..., 0.6466, 0.7945, 0.5389]],
       device='cuda:0')

overlap_for_each_prior, object_for_each_prior = overlap.max(dim=0)  # (8732)

这个 .max(dim=0) 返回两个返回值。
Tensorflow 2.0有等价方法吗?

tensorflow pytorch
2个回答
0
投票

不,你必须使用

tf.math.argmax
。使用它,您还可以获得最大元素:

A = tf.constant([2, 20, 30, 3, 6])
maximum_index = tf.math.argmax(A)
A[maximum_index], maximum_index
# >>> 30, 2

0
投票

如果我正确理解你的问题,你可以使用

tf.math.reduce_max
功能:

A = tf.constant([[1, 2, 3, 4, 5], [6, 7, 8, 9, 10]])
print('tf->', tf.math.reduce_max(A, axis=d))

tf-> tf.Tensor([ 5 10], shape=(2,), dtype=int32)

A2 = torch.from_numpy(A.numpy())
print('torch', A2.amax(1))

torch-> 张量([ 5, 10], dtype=torch.int32)

© www.soinside.com 2019 - 2024. All rights reserved.