models icon indicating copy to clipboard operation
models copied to clipboard

[Object Detection] Nan in summary histogram for: FeatureExtractor/InceptionV2/Mixed_5c_2_Conv2d_5_3x3_s2_128/BatchNorm/moving_variance_1

Open 0xAdityaThakkar opened this issue 8 years ago • 9 comments

System information

  • What is the top-level directory of the model you are using: /dev/models/research/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): Linux Ubuntu 16.04
  • TensorFlow installed from (source or binary): Binary
  • TensorFlow version (use command below): v1.6.0-0-gd2e24b6039 1.6.0
  • CUDA/cuDNN version: V9.0.176
  • GPU model and memory: Nvidia Tesla K80 and Memory 11439MiB
  • Exact command to reproduce: python train.py --logtostderr --train_dir=ckpts/ --pipeline_config_path=ssd_inception_v2_coco_2017_11_17/pipeline.config

Problem Description

I am trying to perform object detection using pretrained SSD_Inception model and it works for initial 600 or so steps and then fails. Below is my config file and the log. Please let me know what I am doing wrong here.

Source code / logs

Logs

/home/ubuntu/.conda/envs/tf/lib/python3.6/site-packages/h5py/init.py:36: FutureWarning: Conversion of the second argument of issubdtype from float to np.floating is deprecated. In future, it will be treated as np.float64 == np.dtype(float).type. from ._conv import register_converters as _register_converters
WARNING:tensorflow:From /dev/models/research/object_detection/trainer.py:228: create_global_step (from tensorflow.contrib.framework.python.ops.variables) is deprecated and will be removed in a future vers ion. Instructions for updating: Please switch to tf.train.create_global_step INFO:tensorflow:depth of additional conv before box predictor: 0
INFO:tensorflow:depth of additional conv before box predictor: 0
INFO:tensorflow:depth of additional conv before box predictor: 0
INFO:tensorflow:depth of additional conv before box predictor: 0
INFO:tensorflow:depth of additional conv before box predictor: 0
INFO:tensorflow:depth of additional conv before box predictor: 0
INFO:tensorflow:Summary name /clone_loss is illegal; using clone_loss instead. WARNING:tensorflow:From /home/ubuntu/.conda/envs/tf/lib/python3.6/site-packages/tensorflow/contrib/slim/python/slim/learning.py:736: Supervisor.init (from tensorflow.python.training.supervisor) is deprecated and will be removed in a future version. Instructions for updating: Please switch to tf.train.MonitoredTrainingSession 2018-04-04 10:04:13.655765: I tensorflow/core/platform/cpu_feature_guard.cc:140] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA 2018-04-04 10:04:13.745905: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:898] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero 2018-04-04 10:04:13.746233: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1212] Found device 0 with properties: name: Tesla K80 major: 3 minor: 7 memoryClockRate(GHz): 0.8235 pciBusID: 0000:00:1e.0 totalMemory: 11.17GiB freeMemory: 11.10GiB 2018-04-04 10:04:13.746259: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1312] Adding visible gpu devices: 0 2018-04-04 10:04:14.036077: I tensorflow/core/common_runtime/gpu/gpu_device.cc:993] Creating TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 10764 MB memory) -> physical GPU (device: 0, name: Tesla K80, pci bus id: 0000:00:1e.0, compute capability: 3.7) INFO:tensorflow:Restoring parameters from ssd_inception_v2_coco_2017_11_17/model.ckpt INFO:tensorflow:Running local_init_op. INFO:tensorflow:Done running local_init_op. INFO:tensorflow:Starting Session. INFO:tensorflow:Saving checkpoint to path ckpts/model.ckpt INFO:tensorflow:Starting Queues. INFO:tensorflow:global_step/sec: 0 INFO:tensorflow:Recording summary at step 0. INFO:tensorflow:global step 1: loss = 0.5466 (12.392 sec/step) INFO:tensorflow:global step 2: loss = 29.3052 (0.285 sec/step) INFO:tensorflow:global step 3: loss = 31.8983 (0.183 sec/step) INFO:tensorflow:global step 4: loss = 31.7648 (0.161 sec/step) INFO:tensorflow:global step 5: loss = 30.0754 (0.157 sec/step) INFO:tensorflow:global step 6: loss = 31.2989 (0.152 sec/step) INFO:tensorflow:global step 7: loss = 30.9656 (0.149 sec/step) INFO:tensorflow:global step 8: loss = 30.6260 (0.148 sec/step) INFO:tensorflow:global step 9: loss = 29.4137 (0.150 sec/step) INFO:tensorflow:global step 10: loss = 0.5466 (0.149 sec/step) INFO:tensorflow:global step 11: loss = 0.5466 (0.148 sec/step) INFO:tensorflow:global step 12: loss = 0.5466 (0.150 sec/step) INFO:tensorflow:global step 13: loss = 28.8044 (0.145 sec/step) INFO:tensorflow:global step 14: loss = 0.5466 (0.151 sec/step) INFO:tensorflow:global step 15: loss = 0.5466 (0.163 sec/step) INFO:tensorflow:global step 16: loss = 29.9621 (0.161 sec/step) INFO:tensorflow:global step 17: loss = 0.5466 (0.171 sec/step) INFO:tensorflow:global step 18: loss = 0.5466 (0.160 sec/step) ................................................................... INFO:tensorflow:global step 594: loss = 25.1307 (0.163 sec/step)
INFO:tensorflow:global step 595: loss = 0.5466 (0.177 sec/step) INFO:tensorflow:global step 596: loss = 0.5466 (0.169 sec/step) INFO:tensorflow:global step 597: loss = 25.7400 (0.181 sec/step)
INFO:tensorflow:global step 598: loss = 0.5466 (0.171 sec/step) INFO:tensorflow:global step 599: loss = 24.5684 (0.173 sec/step)
INFO:tensorflow:global step 600: loss = 26.2431 (0.186 sec/step)
INFO:tensorflow:global step 601: loss = 25.2068 (0.163 sec/step)
INFO:tensorflow:global step 602: loss = 24.5252 (0.182 sec/step)
INFO:tensorflow:global step 603: loss = 23.8762 (0.185 sec/step)
INFO:tensorflow:global step 604: loss = 24.3052 (0.177 sec/step)
INFO:tensorflow:global step 605: loss = 0.5466 (0.190 sec/step) INFO:tensorflow:global step 606: loss = 24.9894 (0.168 sec/step)
INFO:tensorflow:global step 607: loss = 0.5466 (0.177 sec/step) INFO:tensorflow:global step 608: loss = 24.3691 (0.192 sec/step)
INFO:tensorflow:global step 609: loss = 26.1324 (0.191 sec/step)
INFO:tensorflow:global step 610: loss = 25.0762 (0.170 sec/step)
INFO:tensorflow:global step 611: loss = 0.5466 (0.171 sec/step) INFO:tensorflow:global step 612: loss = 0.5466 (0.172 sec/step) INFO:tensorflow:global step 613: loss = 24.9720 (0.182 sec/step)
INFO:tensorflow:global step 614: loss = 0.5466 (0.191 sec/step) INFO:tensorflow:global step 615: loss = 0.5466 (0.177 sec/step) INFO:tensorflow:global step 616: loss = 0.5466 (0.191 sec/step) INFO:tensorflow:global step 617: loss = 0.5466 (0.195 sec/step) INFO:tensorflow:global step 618: loss = 0.5466 (0.174 sec/step) INFO:tensorflow:global step 619: loss = 25.9182 (0.194 sec/step)
INFO:tensorflow:global step 620: loss = 0.5466 (0.172 sec/step) INFO:tensorflow:global step 621: loss = 0.5466 (0.191 sec/step) INFO:tensorflow:global step 622: loss = 25.2854 (0.331 sec/step)
INFO:tensorflow:Error reported to Coordinator: Nan in summary histogram for: FeatureExtractor/InceptionV2/Mixed_5c_2_Conv2d_5_3x3_s2_128/BatchNorm/moving_variance_1 [[Node: FeatureExtractor/InceptionV2/Mixed_5c_2_Conv2d_5_3x3_s2_128/BatchNorm/moving_variance_1 = HistogramSummary[T=DT_FLOAT, _device="/job:localhost/replica:0/task:0/device:CPU:0"](FeatureExtra ctor/InceptionV2/Mixed_5c_2_Conv2d_5_3x3_s2_128/BatchNorm/moving_variance_1/tag, FeatureExtractor/InceptionV2/Mixed_5c_2_Conv2d_5_3x3_s2_128/BatchNorm/moving_variance/read)]] [[Node: FeatureExtractor/InceptionV2/Mixed_3b/Branch_3/Conv2d_0b_1x1/weights/read/_63 = _Recvclient_terminated=false, recv_device="/job:localhost/replica:0/task:0/device:GPU:0", send_device="/jo b:localhost/replica:0/task:0/device:CPU:0", send_device_incarnation=1, tensor_name="edge_573_F...ights/read", tensor_type=DT_FLOAT, _device="/job:localhost/replica:0/task:0/device:GPU:0"]]

Caused by op 'FeatureExtractor/InceptionV2/Mixed_5c_2_Conv2d_5_3x3_s2_128/BatchNorm/moving_variance_1', defined at: File "train.py", line 167, in tf.app.run() File "/home/ubuntu/.conda/envs/tf/lib/python3.6/site-packages/tensorflow/python/platform/app.py", line 126, in run _sys.exit(main(argv)) File "train.py", line 163, in main worker_job_name, is_chief, FLAGS.train_dir) File "/dev/models/research/object_detection/trainer.py", line 323, in train global_summaries.add(tf.summary.histogram(model_var.op.name, model_var)) File "/home/ubuntu/.conda/envs/tf/lib/python3.6/site-packages/tensorflow/python/summary/summary.py", line 193, in histogram tag=tag, values=values, name=scope) File "/home/ubuntu/.conda/envs/tf/lib/python3.6/site-packages/tensorflow/python/ops/gen_logging_ops.py", line 189, in _histogram_summary "HistogramSummary", tag=tag, values=values, name=name) File "/home/ubuntu/.conda/envs/tf/lib/python3.6/site-packages/tensorflow/python/framework/op_def_library.py", line 787, in _apply_op_helper op_def=op_def) File "/home/ubuntu/.conda/envs/tf/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 3271, in create_op op_def=op_def) File "/home/ubuntu/.conda/envs/tf/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 1650, in init self._traceback = self._graph._extract_stack() # pylint: disable=protected-access

InvalidArgumentError (see above for traceback): Nan in summary histogram for: FeatureExtractor/InceptionV2/Mixed_5c_2_Conv2d_5_3x3_s2_128/BatchNorm/moving_variance_1 [[Node: FeatureExtractor/InceptionV2/Mixed_5c_2_Conv2d_5_3x3_s2_128/BatchNorm/moving_variance_1 = HistogramSummary[T=DT_FLOAT, _device="/job:localhost/replica:0/task:0/device:CPU:0"](FeatureExtractor/InceptionV2/Mixed_5c_2_Conv2d_5_3x3_s2_128/BatchNorm/moving_variance_1/tag, FeatureExtractor/InceptionV2/Mixed_5c_2_Conv2d_5_3x3_s2_128/BatchNorm/moving_variance/read)]] [[Node: FeatureExtractor/InceptionV2/Mixed_3b/Branch_3/Conv2d_0b_1x1/weights/read/_63 = _Recvclient_terminated=false, recv_device="/job:localhost/replica:0/task:0/device:GPU:0", send_device="/job:localhost/replica:0/task:0/device:CPU:0", send_device_incarnation=1, tensor_name="edge_573_F...ights/read", tensor_type=DT_FLOAT, _device="/job:localhost/replica:0/task:0/device:GPU:0"]]

SSD_Model Configuration

# SSD with Inception v2 configuration for MSCOCO Dataset.
# Users should configure the fine_tune_checkpoint field in the train config as
# well as the label_map_path and input_path fields in the train_input_reader and
# eval_input_reader. Search for "PATH_TO_BE_CONFIGURED" to find the fields that
# should be configured.

model {
  ssd {
    num_classes: 5
    box_coder {
      faster_rcnn_box_coder {
        y_scale: 10.0
        x_scale: 10.0
        height_scale: 5.0
        width_scale: 5.0
      }
    }
    matcher {
      argmax_matcher {
        matched_threshold: 0.5
        unmatched_threshold: 0.5
        ignore_thresholds: false
        negatives_lower_than_unmatched: true
        force_match_for_each_row: true
      }
    }
    similarity_calculator {
      iou_similarity {
      }
    }
    anchor_generator {
      ssd_anchor_generator {
        num_layers: 6
        min_scale: 0.2
        max_scale: 0.95
        aspect_ratios: 1.0
        aspect_ratios: 2.0
        aspect_ratios: 0.5
        aspect_ratios: 3.0
        aspect_ratios: 0.3333
        reduce_boxes_in_lowest_layer: true
      }
    }
    image_resizer {
      fixed_shape_resizer {
        height: 300
        width: 300
      }
    }
    box_predictor {
      convolutional_box_predictor {
        min_depth: 0
        max_depth: 0
        num_layers_before_predictor: 0
        use_dropout: false
        dropout_keep_probability: 0.8
        kernel_size: 3
        box_code_size: 4
        apply_sigmoid_to_scores: false
        conv_hyperparams {
          activation: RELU_6,
          regularizer {
            l2_regularizer {
              weight: 0.00004
            }
          }
          initializer {
            truncated_normal_initializer {
              stddev: 0.03
              mean: 0.0
            }
          }
        }
      }
    }
    feature_extractor {
      type: 'ssd_inception_v2'
      min_depth: 16
      depth_multiplier: 1.0
      conv_hyperparams {
        activation: RELU_6,
        regularizer {
          l2_regularizer {
            weight: 0.00004
          }
        }
        initializer {
          truncated_normal_initializer {
            stddev: 0.03
            mean: 0.0
          }
        }
        batch_norm {
          train: true,
          scale: true,
          center: true,
          decay: 0.9997,
          epsilon: 0.001,
        }
      }
    }
    loss {
      classification_loss {
        weighted_sigmoid {
        }
      }
      localization_loss {
        weighted_smooth_l1 {
        }
      }
      hard_example_miner {
        num_hard_examples: 3000
        iou_threshold: 0.99
        loss_type: CLASSIFICATION
        max_negatives_per_positive: 3
        min_negatives_per_image: 0
      }
      classification_weight: 1.0
      localization_weight: 1.0
    }
    normalize_loss_by_num_matches: true
    post_processing {
      batch_non_max_suppression {
        score_threshold: 1e-8
        iou_threshold: 0.6
        max_detections_per_class: 100
        max_total_detections: 100
      }
      score_converter: SIGMOID
    }
  }
}

train_config: {
  batch_size: 1
  optimizer {
    rms_prop_optimizer: {
      learning_rate: {
        exponential_decay_learning_rate {
          initial_learning_rate: 0.000004
          decay_steps: 800720
          decay_factor: 0.95
        }
      }
      momentum_optimizer_value: 0.9
      decay: 0.9
      epsilon: 1.0
    }
  }
  fine_tune_checkpoint: "ssd_inception_v2_coco_2017_11_17/model.ckpt"
  from_detection_checkpoint: true
  # Note: The below line limits the training process to 200K steps, which we
  # empirically found to be sufficient enough to train the pets dataset. This
  # effectively bypasses the learning rate schedule (the learning rate will
  # never decay). Remove the below line to train indefinitely.
  num_steps: 200000
  data_augmentation_options {
    ssd_random_crop {
    }
  }
  batch_queue_capacity: 5
  num_batch_queue_threads: 8
  prefetch_queue_capacity: 5
}

train_input_reader: {
  tf_record_input_reader {
    input_path: "data/receipt_train.record"
  }
  label_map_path: "data/receipt_label_map.pbtxt"
  queue_capacity: 2
  min_after_dequeue: 1
}

eval_config: {
  num_examples: 8000
  # Note: The below line limits the evaluation process to 10 evaluations.
  # Remove the below line to evaluate indefinitely.
  max_evals: 10
}

eval_input_reader: {
  tf_record_input_reader {
    input_path: "data/receipt_val.record"
  }
  label_map_path: "data/receipt_label_map.pbtxt"
  shuffle: false
  num_readers: 1
  queue_capacity: 2
  min_after_dequeue: 1
}

I've tried faster_rnn with inception and it worked, but this SSD is failing. What also concern me is the fluctuations in loss. I don't think this is normal.

Thanks in advance!!!

0xAdityaThakkar avatar Apr 04 '18 10:04 0xAdityaThakkar

Adding @jch1 for comment.

bitfort avatar Apr 06 '18 20:04 bitfort

The large loss fluctuation may be due to the small batch size set in the config file. batch_size: 1 How much CPU RAM do you have? Are you running out of RAM and swap file during training?

stevefielding avatar Apr 06 '18 22:04 stevefielding

Another option is to check with stack overflow (e.g. https://stackoverflow.com/questions/tagged/tensorflow )

bitfort avatar Apr 10 '18 19:04 bitfort

Increasing the batch size did solved the NaN problem. However the process is killed after 1768 steps and I think this has to do with CPU RAM and Swap. Anyways thanks for the help!!

One more question about fine tuning. Is it a good idea to continue model training from the latest model checkpoint saved as fine_tune_checkpoint parameter in configuration file?

0xAdityaThakkar avatar Apr 19 '18 07:04 0xAdityaThakkar

I ran into the NaN problem using http://download.tensorflow.org/models/object_detection/ssd_inception_v2_coco_2018_01_28.tar.gz to train on my images. I had the batch_size set to 1 initially. But after reading this I set it back to 24. I still got that NaN exception. I bumped batch_size to 50 and started running out of memory on my 8Gb machine. Is there a commit that fixes anything related to this thread?

Note that I'm seeing this fail on Unbuntu 16.04.3. But it seems to work on my (slow) Windows laptop.

jim-meyer avatar Jul 03 '18 16:07 jim-meyer

I have a similar issue, working with CPU and batch size 24 worked Ok, then switching to Gpu from the same point gave this error. I'm working with ssdlite_mobilenet_v2. Raising batch size gives error like: could not allocate pinned host memory of size, and after a while nan loss error.

xtianhb avatar Aug 05 '18 22:08 xtianhb

same problem here too. I used batch size of 1 because I only have 1080 ti gpu. It loaded the pascal voc model okay but gave me NAN loss since step 2 and crashed eventually. I am on ubuntu. Any solution?

yxt132 avatar May 08 '19 03:05 yxt132

I am facing the same issue too on ssdlite_mobilenet_v2. changed batch size but did not worked.

kshitijqwerty avatar May 22 '19 07:05 kshitijqwerty

Did anyone find any solution?

siddas27 avatar Nov 20 '19 10:11 siddas27