tf.argmax is returning a random high value , outside the valid dimension range

时间:2017-08-04 12:20:20

标签: tensorflow deep-learning

I have the following piece of code, where I have a tensor of dimensions (150,240,240).

Now from these 150 slices, I want to construct one slice (of size 240 by 240) by comparing all 150 slices across each of the values in the 240 by 240 matrix. I use tf.argmax for that . It usually goes right. But in some cases in the result, one of the values is really huge and random like 4294967390. How is that possible ? It should have returned a value between 0 and 149 for every dimension. Following is my code for doing that .

Note in the code below dimension of the variable result - (20,150,240,240)

for i in range(0, 20):
denominator = tf.reduce_logsumexp(result[i, :, :, :], axis=0)
if i == 0:
    stackofArrs = tf.argmax(tf.exp(result[i, :, :, :]-denominator), axis=0)
else:
    stackofArrs = tf.concat([stackofArrs, tf.argmax(tf.exp(result[i, :, :, :]-denominator), axis=0)], axis=0)

I thought if the logsumexp operation is causing any overflow ? But even in that case argmax shouldn't return a crazy value like this right ?

1 个答案:

答案 0 :(得分:2)

tf.argmax will output out of range values if it is applied on a tensor containing NaN or Inf values. You should make sure those are not present before applying the tf.argmax