models icon indicating copy to clipboard operation
models copied to clipboard

Total loss is NaN for object detection tf2.1

Open lamdawr opened this issue 6 years ago • 9 comments

System information

Have I written custom code (as opposed to using example directory): https://github.com/tensorflow/models/tree/master/official/vision/detection changed strategy to "mirrored" to run in GPU/CPU, reduced batch size to 1 to start with minimum and changed location to my custom tfrecord. all other code unchanged. reference for other files : https://github.com/tensorflow/models/issues/8119 OS Platform and Distribution (e.g., Linux Ubuntu 16.04): ubuntu 18.04.2 LTS bionic TensorFlow backend (yes / no): yes TensorFlow version: 2.1.0 Keras version: 2.3.1 Python version: 3.7.3 CUDA/cuDNN version: N/A GPU model and memory: N/A Describe the current behavior: total loss is Nan and Error occurred when finalizing GeneratorDataset iterator

logs: I0212 16:39:15.769866 139931759961920 distributed_executor.py:411] Training started Traceback (most recent call last): File "official/vision/detection/main.py", line 250, in app.run(main) File "/opt/conda/lib/python3.7/site-packages/absl/app.py", line 299, in run _run_main(main, args) File "/opt/conda/lib/python3.7/site-packages/absl/app.py", line 250, in _run_main sys.exit(main(argv)) File "official/vision/detection/main.py", line 245, in main run() File "official/vision/detection/main.py", line 239, in run callbacks=callbacks) File "official/vision/detection/main.py", line 136, in run_executor save_config=True) File "/home/user1/tf_2/models/official/modeling/training/distributed_executor.py", line 427, in train raise ValueError('total loss is NaN.') ValueError: total loss is NaN. 2020-02-12 16:52:12.019596: W tensorflow/core/kernels/data/cache_dataset_ops.cc:822] The calling iterator did not fully read the dataset being cached. In order to avoid unexpected truncation of the dataset, the partially cached contents of the dataset will be discarded. This can happen if you have an input pipeline similar to dataset.cache().take(k).repeat(). You should use dataset.take(k).cache().repeat() instead. 2020-02-12 16:52:12.399724: W tensorflow/core/kernels/data/generator_dataset_op.cc:103] Error occurred when finalizing GeneratorDataset iterator: Cancelled: Operation was cancelled

Describe the expected behavior Calling model train should start training

Code to reproduce the issue: same code available in https://github.com/tensorflow/models/tree/master/official/vision/detection except for running it locally with strategy as "mirrored" and config file : https://github.com/tensorflow/models/issues/8119

lamdawr avatar Feb 12 '20 17:02 lamdawr

If you restart the training from the same folder and restore the checkpoint, will the training go through? Or it consistently gets NaN. We do see some NaN issues and it has some randomness. @yeqingli

saberkun avatar Feb 13 '20 04:02 saberkun

Hi Hongkun,

Thanks for your reply. I reduced the learning rate and that helped. But I am yet to fully train a model. Still half way.

Lakshmi

On Wed, Feb 12, 2020, 10:37 PM Hongkun Yu [email protected] wrote:

If you restart the training from the same folder and restore the checkpoint, will the training go through? Or it consistently gets NaN. We do see some NaN issues and it has some randomness. @yeqingli https://github.com/yeqingli

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/tensorflow/models/issues/8131?email_source=notifications&email_token=ABZPWG72XCK4AK6QADK6W6TRCTE6ZA5CNFSM4KT6CGJ2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOELTLUBA#issuecomment-585546244, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABZPWG62D2BY7DB2JEW6EQLRCTE6ZANCNFSM4KT6CGJQ .

lamdawr avatar Feb 13 '20 04:02 lamdawr

How can check accuracy or iou of the models for v training ?

lamdawr avatar Feb 20 '20 01:02 lamdawr

Hi lamdawr,

I have same problem. In my case, "l2_regularization_loss" result was Nan. So total_loss also Nan.

Therefore, I temporary changed (official/vision/detection/modeling/retinanet_model.py line:111) total_loss = model_loss + l2_regularization_loss => total_loss = model_loss

loozy5331 avatar Mar 06 '20 06:03 loozy5331

Does the Object Detection API even work with TF2 (and Keras)?

haimat avatar Apr 06 '20 16:04 haimat

@haimat This issue is about official/vision/detection (https://github.com/tensorflow/models/tree/master/official/vision/detection) and not the object detection API in research that is (not yet) compatible with tf>=2.0. Object detection models in official is only compatible with new versions of tensorflow.

fellhorn avatar Apr 06 '20 22:04 fellhorn

@fellhorn Ahh, thanks for the clarification. Then that may be exactly what I am looking for. Unfortunately there is not much documentation (yet) on how to use official/vision/detection. Are there some more docs anywhere, or have you learned it by trial&error and looking at the code in the repo?

haimat avatar Apr 07 '20 07:04 haimat

Object Detection API works with TF 2.x now. The official/vision/detection is deprecating and we are actively consolidating the works into official/vision/beta now.

saberkun avatar Jan 15 '21 20:01 saberkun

Are you satisfied with the resolution of your issue? Yes No

google-ml-butler[bot] avatar Jan 15 '21 20:01 google-ml-butler[bot]