Replace nanometer values ​​in tensor tensor

I am working on a convolutional neural network in a tensor stream, and I have a problem. The problem is that the input image that I read through tfrecords contains a certain number of nan values. The reason for this is the image representing the depth map, which has several infinite values ​​in it and in the process of encoding it into tfrecord, and then decoding to feed it to the network, these infinite values ​​become nan values.

Now, since in my situation replacing infinite values ​​in the original image before encoding it in tfrecors is not an option, can I replace the nan values ​​in the image tensor as an operation that I have to perform before I upload it to the network?

+6
source share
1 answer

The combination of tf.where and tf.is_nan should work:

import tensorflow as tf with tf.Session(): has_nans = tf.constant([float('NaN'), 1.]) print(tf.where(tf.is_nan(has_nans), tf.zeros_like(has_nans), has_nans).eval()) 

Printing (using TensorFlow 0.12.1):

 [ 0. 1.] 
+14
source

Source: https://habr.com/ru/post/1014704/


All Articles