Torch.Min in tensorflow

时间:2016-09-22 21:50:45

标签: tensorflow torch

在火炬中有一个名为torch.Min的模块,它可以在网络的不同分支上应用最小操作。

  

nn.Min

tensorflow中有类似的东西吗? (张量流中的noob)

1 个答案:

答案 0 :(得分:1)

我想你想要tf.reduce_min。要找到[10, 3, 5, 4]的最小值:

import tensorflow as tf


def one_dim_graph():
  input_tensor = tf.constant([10, 3, 5, 4])
  tensor_min = tf.reduce_min(input_tensor)
  return input_tensor, tensor_min


def run():
  in_one, g_one = one_dim_graph()

  with tf.Session() as sess:
    sess.run(tf.initialize_all_variables())

    out_one = sess.run([g_one])
    print in_one
    print out_one


run()

这会给你min:

Tensor("Const_74:0", shape=(4,), dtype=int32)
[3]

您还可以在多维张量中使用此功能,并缩小所有尺寸或沿某个尺寸缩小。因此,例如,找到min:

[[1, 4, 3, 10],
 [6, 5, 2, 12],
 [9, 7, 8, 11]]

我们可以找到:

  • 总分钟[1]tf.reduce_min(input_tensor)
  • [1, 4, 2, 10]
  • 的列式分钟tf.reduce_min(input_tensor, reduction_indices=0)
  • 行{min} [1, 2, 7] tf.reduce_min(input_tensor, reduction_indices=1)