Training custom model crashes with "ERROR:tensorflow:Model diverged with loss = NaN."
System information
- What is the top-level directory of the model you are using: Object detection
- Have I written custom code (as opposed to using a stock example script provided in TensorFlow): no
- OS Platform and Distribution (e.g., Linux Ubuntu 16.04): Windows 10
- TensorFlow installed from (source or binary): binary
- TensorFlow version (use command below): 1.9.0
- Bazel version (if compiling from source): -
- CUDA/cuDNN version: CUDA 9.0 / cuDNN 7.0.5
- GPU model and memory: Nvidia GeForce GTX 1050 Ti
- Exact command to reproduce:
python model_main.py --model_dir=training/ --pipeline_config_path=training/ssd_inception_v2_coco.config --logtostderr
Describe the problem
The model_main.py script crashes before even one training step. Normally I'd say it's because of my GPU, but with the now deprecated train.py script it worked well. I'm training a custom model with the ssd_inception_v2_coco config file and the model as finetune checkpoint.
Source code / logs
`(tensorflow2) c:\tensorflow2\models\research\object_detection>python model_main.py --model_dir=training/ --pipeline_config_path=training/ssd_inception_v2_coco.config --eval_training_data --alsologtostderr C:\Users\Luca\Anaconda3\envs\tensorflow2\lib\importlib_bootstrap.py:222: RuntimeWarning: numpy.dtype size changed, may indicate binary incompatibility. Expected 96, got 88 return f(*args, **kwds) C:\Users\Luca\Anaconda3\envs\tensorflow2\lib\importlib_bootstrap.py:222: RuntimeWarning: numpy.dtype size changed, may indicate binary incompatibility. Expected 96, got 88 return f(*args, **kwds) C:\tensorflow2\models\research\object_detection\utils\visualization_utils.py:25: UserWarning: This call to matplotlib.use() has no effect because the backend has already been chosen; matplotlib.use() must be called before pylab, matplotlib.pyplot, or matplotlib.backends is imported for the first time.
The backend was originally set to 'TkAgg' by the following code:
File "model_main.py", line 26, in
import matplotlib; matplotlib.use('Agg') # pylint: disable=multiple-statements
WARNING:tensorflow:Estimator's model_fn (<function create_model_fn.
Same problem with me on windows. If I add follow commd
-num_train_steps=1 -num_eval_steps=1
it will stop working after Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 8799 MB memory)
When I'm adding the --num_train_steps=1 and --num_eval_steps=1 commands it crashes because of the following:
tensorflow.python.framework.errors_impl.NotFoundError: Failed to create a directory: training/export\Servo\temp-b'1532522498'; No such file or directory
As soon as I'm increasing the values of these commands it throws the same error I've mentioned above.
Any ideas? Thanks!
Same problem here
I am also running into this issue. I was able to execute the model_main.py script against the latest tensorflow cpu package and have it run through a large number of steps but when trying to leverage the tensorflow gpu I keep running into the error "model diverged with loss = NaN" I tried varying my batch size but that did not resolve the issue.
Hi guys, I end up using the old train.py from the legacy folder.
I mean, like this:
From models/research/object_detection
python ./legacy/train.py --pipeline_config_path=pipeline_config/ssd_mobilenet_v2_coco.config --train_dir=training/ --logtostderr
same problem while using model_main.py to train @jacano do you see duplicated training steps while using legacy train.py? i saw infos like this
INFO:tensorflow:Restoring parameters from /ChinaRS/code/tensorflow/ssd_resnet50_v1_fpn_shared_box_predictor_640x640_coco14_sync_2018_07_03/model.ckpt INFO:tensorflow:Running local_init_op. INFO:tensorflow:Running local_init_op. INFO:tensorflow:Done running local_init_op. INFO:tensorflow:Done running local_init_op. INFO:tensorflow:Starting Session. INFO:tensorflow:Starting Session. INFO:tensorflow:Saving checkpoint to path models\model.ckpt INFO:tensorflow:Saving checkpoint to path models\model.ckpt INFO:tensorflow:Starting Queues. INFO:tensorflow:Starting Queues. INFO:tensorflow:global_step/sec: 0 INFO:tensorflow:global_step/sec: 0 INFO:tensorflow:Recording summary at step 0. INFO:tensorflow:Recording summary at step 0. INFO:tensorflow:global step 1: loss = 2.2247 (14.886 sec/step) INFO:tensorflow:global step 1: loss = 2.2247 (14.886 sec/step)
Yes, I got duplicated lines yesterday, during a training session. Same as you.
I guess it has to do with the --logtostderr flag. Didn´t had time to investigate further, sorry.
I have the same problem with a very similar setup/task. I'm training for 1 class, using GPU GTX 1060 6GB. Command: python model_main.py --num_eval_steps=2000 --num_train_steps=50000 --alsologtostderr --pipeline_config_path=training/ssdlite_mobilenet_v2_coco.config --model_dir=training
Last week I was doing the same task with tensor flow cpu version, on the same system, and worked perfectly. Yesterday I've installed a GPU and found this problem.
I've changed --num_eval_steps=1 --num_train_steps=1 and didn't crash....
I've updated to the last version, set in my pipe_line_config_file initial_learning_rate: 0 , checked again labels and bounding boxes, and got the same result. With Cpu I don't have this behaviour.
Same problem here. With CPU works, with GPU prints the error.
I've switched to the legacy/train.py script for training, and legacy/eval.py for evaluation. It works with GPU, no problems. Same setup as commented earlier.
Relying on the legacy scripts is a workaround for this problem, but the main issue still persists. We shouldn't have to switch back to the legacy scripts when we want to train our model with a GPU.
Running the non-legacy script with -num_train_steps=1 -num_eval_steps=1 works after manually adding the Servo directory to the model dir. But adding more steps will crash with the error in the title.
This could be a Cuda related issue, but I'm not sure about that.
@Stukongeluk Yes, sure I agree with you. I just wanted to isolate possible problems related to dataset, framework setup, platform, pipeline config, etc, and meanwhile mention the workaround. I've seen problems reported similar to this in #4754 #3688
Yes, I've also found that behaviour with -num_train_steps=1 -num_eval_steps=1
Any news on this???
@xtianhb - the problem exists fro me even with the legacy script with batch size = 1. However no NAN loss errors with other batch sizes
hi all, OS windows 10 64bit python 3.6 tensorflow 1.10 cuda 9.0.x cudnn 7.0.x run pet data into same issue on GTX1050ti, use my cpu i5 run same dataset and config files it 's okie
looks like this is a bug with object detection api with pet dataset, please keep on track , let more developer know this issue!
more update -->> ERROR:tensorflow:Model diverged with loss = NaN.
using legacy train.py can work, while need to change object_detection/utils/variables_helper.py, change like this for import part #import logging #import re
#import tensorflow as tf
#slim = tf.contrib.slim import re import tensorflow as tf from tensorflow import logging as logging slim = tf.contrib.slim
resolve the output two same log output issue, now seems like okay, but still could not save jpg with log on windows10
I meet the same problem, -num_train_steps=1 -num_eval_steps=1 can work,but when i add the num_train_steps,-num_eval_steps, it got the same wrong.
@gloomyfish1998 have you deal the problem?