models icon indicating copy to clipboard operation
models copied to clipboard

Struct2depth: NaNs in inf_norm

Open kesinger opened this issue 7 years ago • 10 comments

System information

What is the top-level directory of the model you are using: models/research/struct2depth Have I written custom code (as opposed to using a stock example script provided in TensorFlow): No (beyond fixing #5857 ) OS Platform and Distribution (e.g., Linux Ubuntu 16.04): Ubuntu 18.04 TensorFlow installed from (source or binary): Binary TensorFlow version (use command below):v1.12.0-0-ga6d8ffae09 1.12.0 Bazel version (if compiling from source): N/A CUDA/cuDNN version: libcudart.so.9.0.176 GPU model and memory: 1080Ti 11Gb Exact command to reproduce: python train.py --logtostderr --checkpoint_dir=ckpt --data_dir=/opt/bigdata/kitti_processed --architecture=resnet --imagenet_norm=true --joint_encoder=false --summary_freq=1 Describe the problem

Describe the problem clearly here. Be sure to convey here why it's a bug in TensorFlow or a feature request.

I am running into errors of the form "LossTensor is inf or nan : Tensor had NaN values". This appears to be from the inf_loss contribution: losses = tf.map_fn( get_losses, object_masks, dtype=tf.float32) self.inf_loss += tf.reduce_mean(losses)

In particular, losses will occasionally contain a nan value, as shown here: [array([ 0.92789054, 5.1210318 , 4.9717507 , 5.6173134 , 60.209503 , 33.976864 , 0. ], dtype=float32), array([ 0.92788905, 4.3226395 , 4.3226404 , 4.3226247 , 60.209442 , 33.97685 , nan], dtype=float32), array([ 0.9278935, 3.9967735, 3.8008199, 4.100856 , 60.20948 , 29.60478 , 29.60479 ], dtype=float32)]

(As I understand it, these are the losses for j=0,1,2 in the loop "for j in range(self.seq_length)" )

Note that the nan in the j=1 row is paired with a 0 in the j=0 row, this appears to be consistent behavior.

The only thing I've found that triggers this is if the object mask is particularly small, but there doesn't seem to be an absolute threshold.

kesinger avatar Jan 14 '19 15:01 kesinger

This issue is just me moving my comment from https://github.com/tensorflow/models/issues/5959 to its own issue.

kesinger avatar Jan 14 '19 15:01 kesinger

A similar-but-different issue with inf_loss is in the computation of approx_depth (and possibly other terms based on global_mean_depth_pred); if y_min=y_max, there will be a division-by-0.

Note that adding an offset does NOT appear to be sufficient to prevent NaNs, but does prevent Infs.

kesinger avatar Jan 14 '19 19:01 kesinger

Just cross-referencing https://github.com/tensorflow/tensorflow/issues/25395 here, which is the same problem in a different context.

kesinger avatar Jan 31 '19 21:01 kesinger

Quick update, I found that if one replaces tf.reduce_mean(spatial_err) by something like tf.reduce_mean(tf.concat([spatial_err, tf.zeros(1)], axis=0) then the nans disappear.

This is because tf.reduce_mean when called on an empty sequence returns NaN; whether it should or not is another question.

kesinger avatar Feb 11 '19 19:02 kesinger

@kesinger
I was also running into errors of the form "LossTensor is inf or nan : Tensor had NaN values". After reading this issue @6173 , I relized it was due to object ids wasn't consisted across frames, once you do that, this issue is resolved.

amanrajdce avatar Mar 03 '19 08:03 amanrajdce

@amanrajdce Is it possible for object ids to become inconsistent due to random scale/crop? The prepared dataset has seemingly consistent mask ids but still, NaN/inf problem appears at some point.

ramanishka avatar Mar 06 '19 12:03 ramanishka

@amanrajdce Is it possible for object ids to become inconsistent due to random scale/crop? The prepared dataset has seemingly consistent mask ids but still, NaN/inf problem appears at some point.

I don't think so. I have been able to get it working after making object ids consisted across frames. You may use alignment.py script in the repo

amanrajdce avatar Mar 08 '19 06:03 amanrajdce

@amanrajdce After making it consistent and double-checking the input data - it was crashing later at some point during training; since many things are randomized, it's hard to track down the problem though it is reproducible given the random seed and the particular set of masks.

@kesinger, @amanrajdce thanks for insights!

ramanishka avatar Mar 08 '19 06:03 ramanishka

@kesinger hello, have you solved this problem?? because I have the same problem with it, I try to fix it but still give an error

kadut99 avatar Mar 19 '19 02:03 kadut99

Hi There, We are checking to see if you still need help on this, as this seems to be an old issue. Please update this issue with the latest information, code snippet to reproduce your issue and error you are seeing. If we don't hear from you in the next 7 days, this issue will be closed automatically. If you don't need help on this issue any more, please consider closing this.

tensorflowbutler avatar Mar 18 '20 21:03 tensorflowbutler