我对tensorflow
还不熟悉,我正在尝试得到张量中最大值的索引。代码如下:
def select(input_layer):
shape = input_layer.get_shape().as_list()
rel = tf.nn.relu(input_layer)
print (rel)
redu = tf.reduce_sum(rel,3)
print (redu)
location2 = tf.argmax(redu, 1)
print (location2)
sess = tf.InteractiveSession()
I = tf.random_uniform([32, 3, 3, 5], minval = -541, maxval = 23, dtype = tf.float32)
matI, matO = sess.run([I, select(I, 3)])
print(matI, matO)
输出如下:
^{pr2}$由于argmax
函数中的维数=1,Tensor("ArgMax:0") = (32,3)
的形状。在应用argmax
之前,有没有什么方法可以在不做reshape
的情况下得到argmax
输出张量size=(32,)
?在
您可能不希望输出的大小为
(32,)
,因为当您沿着多个方向argmax
时,您通常希望得到所有缩减维度的最大坐标。在您的例子中,您需要一个大小为(32,2)
的输出。在您可以这样做一个二维
argmax
:相关问题 更多 >
编程相关推荐