Replace nan values in tensorflow tensor

后端 未结 4 2156
说谎
说谎 2021-01-04 00:02

I\'m working on a convolutional neural network in tensorflow and I have a problem. The problem is the input image I read through tfrecords contains a certain number of nan v

4条回答
  •  甜味超标
    2021-01-04 00:36

    A much easier approach, compatible with TF2.0, is to just use tf.clip_by_value, which mirrors np.clip and removes NaNs (see here):

    no_nans = tf.clip_by_value(has_nans, -1e12, 1e12)
    

    Some caveats: 1) this also removes infs 2) Depending on your application you may need to set the clip value to a high value to avoid losing info.

提交回复
热议问题