内存不足以进行对象检测训练

时间:2020-05-29 01:48:37

标签: python linux tensorflow

系统信息

  • 我是否编写了自定义代码(与使用TensorFlow中提供的股票示例脚本相反):
  • OS平台和发行版(例如Linux Ubuntu 16.04):Linux Ubuntu 16.04
  • 从(源或二进制)安装的TensorFlow:TensorFlow版本(Anaconda Venv):1.14
  • Python版本:2.7
  • Bazel版本(如果从源代码编译):CUDA / cuDNN版本:7.5 / 7.0
  • GPU型号和内存:GeForce GTX 1080 Ti
  • 要重现的确切命令:./run_model_main.sh

描述问题

我的内存不足问题 但我不知道为什么

vim run_model_main.sh

# From the tensorflow/models/research/ directory
PIPELINE_CONFIG_PATH=/home/withrobot/tfmodel/models/research/object_detection/num_config/ssd_mobilenet_v2_quantized_300x300_coco.config
MODEL_DIR=/home/withrobot/tfmodel/models/research/object_detection/num_train
SAMPLE_1_OF_N_EVAL_EXAMPLES=1
python model_main.py \
    --pipeline_config_path=${PIPELINE_CONFIG_PATH} \
    --model_dir=${MODEL_DIR} \
    --sample_1_of_n_eval_examples=${SAMPLE_1_OF_N_EVAL_EXAMPLES}\
    --alsologtostderr

ssd_mobilenet_v2_quantized_300x300_coco.config

# Quantized trained SSD with Mobilenet v2 on 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:98 
    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
      }
    }
    image_resizer {
      fixed_shape_resizer {
        height: 240
        width: 400
      }
    }
    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: 1
        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
            }
          }
          batch_norm {
            train: true,
            scale: true,
            center: true,
            decay: 0.9997,
            epsilon: 0.001,
          }
        }
      }
    }
    feature_extractor {
      type: 'ssd_mobilenet_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: 3
      }
      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.004
          decay_steps: 800720
          decay_factor: 0.95
        }
      }
      momentum_optimizer_value: 0.9
      decay: 0.9
      epsilon: 0.000001
    }
  }
  fine_tune_checkpoint:"/home/withrobot/tfmodel/models/research/object_detection/ssd_mobilenet_v2_quantized_300x300_coco_2019_01_03/model.ckpt"
  fine_tune_checkpoint_type: "classification"
  # 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 {
    random_horizontal_flip {
    }
  }
  data_augmentation_options {
    ssd_random_crop {
    }
  }
}

train_input_reader: {
  tf_record_input_reader {
    input_path: "/home/withrobot/tfmodel/models/research/object_detection/train.record"
  }
  label_map_path: "/home/withrobot/tfmodel/models/research/object_detection/num_config/labelmap.pbtxt"
}

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

eval_input_reader: {
  tf_record_input_reader {
    input_path: "/home/withrobot/tfmodel/models/research/object_detection/test.record"
  }
  label_map_path: "/home/withrobot/tfmodel/models/research/object_detection/num_config/labelmap.pbtxt"

  num_readers: 1
}

graph_rewriter {
  quantization {
    delay: 48000
    weight_bits: 8
    activation_bits: 8
  }
}

和错误

。 。 。

I0529 10:13:47.591280 139777032922880 quantize.py:298] Skipping quant after FeatureExtractor/MobilenetV2/expanded_conv_14/depthwise/add_fold
    INFO:tensorflow:Skipping quant after FeatureExtractor/MobilenetV2/expanded_conv_15/expand/add_fold
    I0529 10:13:47.591808 139777032922880 quantize.py:298] Skipping quant after FeatureExtractor/MobilenetV2/expanded_conv_15/expand/add_fold
    INFO:tensorflow:Skipping quant after FeatureExtractor/MobilenetV2/expanded_conv_15/depthwise/add_fold
    I0529 10:13:47.592128 139777032922880 quantize.py:298] Skipping quant after FeatureExtractor/MobilenetV2/expanded_conv_15/depthwise/add_fold
    INFO:tensorflow:Skipping quant after FeatureExtractor/MobilenetV2/expanded_conv_16/expand/add_fold
    I0529 10:13:47.592664 139777032922880 quantize.py:298] Skipping quant after FeatureExtractor/MobilenetV2/expanded_conv_16/expand/add_fold
    INFO:tensorflow:Skipping quant after FeatureExtractor/MobilenetV2/expanded_conv_16/depthwise/add_fold
    I0529 10:13:47.592971 139777032922880 quantize.py:298] Skipping quant after FeatureExtractor/MobilenetV2/expanded_conv_16/depthwise/add_fold
    INFO:tensorflow:Skipping quant after FeatureExtractor/MobilenetV2/Conv_1/add_fold
    I0529 10:13:47.593499 139777032922880 quantize.py:298] Skipping quant after FeatureExtractor/MobilenetV2/Conv_1/add_fold
    INFO:tensorflow:Skipping quant after FeatureExtractor/MobilenetV2/layer_19_1_Conv2d_2_1x1_256/add_fold
    I0529 10:13:47.593796 139777032922880 quantize.py:298] Skipping quant after FeatureExtractor/MobilenetV2/layer_19_1_Conv2d_2_1x1_256/add_fold
    INFO:tensorflow:Skipping quant after FeatureExtractor/MobilenetV2/layer_19_2_Conv2d_2_3x3_s2_512/add_fold
    I0529 10:13:47.594093 139777032922880 quantize.py:298] Skipping quant after FeatureExtractor/MobilenetV2/layer_19_2_Conv2d_2_3x3_s2_512/add_fold
    INFO:tensorflow:Skipping quant after FeatureExtractor/MobilenetV2/layer_19_1_Conv2d_3_1x1_128/add_fold
    I0529 10:13:47.594383 139777032922880 quantize.py:298] Skipping quant after FeatureExtractor/MobilenetV2/layer_19_1_Conv2d_3_1x1_128/add_fold
    INFO:tensorflow:Skipping quant after FeatureExtractor/MobilenetV2/layer_19_2_Conv2d_3_3x3_s2_256/add_fold
    I0529 10:13:47.594671 139777032922880 quantize.py:298] Skipping quant after FeatureExtractor/MobilenetV2/layer_19_2_Conv2d_3_3x3_s2_256/add_fold
    INFO:tensorflow:Skipping quant after FeatureExtractor/MobilenetV2/layer_19_1_Conv2d_4_1x1_128/add_fold
    I0529 10:13:47.594960 139777032922880 quantize.py:298] Skipping quant after FeatureExtractor/MobilenetV2/layer_19_1_Conv2d_4_1x1_128/add_fold
    INFO:tensorflow:Skipping quant after FeatureExtractor/MobilenetV2/layer_19_2_Conv2d_4_3x3_s2_256/add_fold
    I0529 10:13:47.595252 139777032922880 quantize.py:298] Skipping quant after FeatureExtractor/MobilenetV2/layer_19_2_Conv2d_4_3x3_s2_256/add_fold
    INFO:tensorflow:Skipping quant after FeatureExtractor/MobilenetV2/layer_19_1_Conv2d_5_1x1_64/add_fold
    I0529 10:13:47.595541 139777032922880 quantize.py:298] Skipping quant after FeatureExtractor/MobilenetV2/layer_19_1_Conv2d_5_1x1_64/add_fold
    INFO:tensorflow:Skipping quant after FeatureExtractor/MobilenetV2/layer_19_2_Conv2d_5_3x3_s2_128/add_fold
    I0529 10:13:47.595832 139777032922880 quantize.py:298] Skipping quant after FeatureExtractor/MobilenetV2/layer_19_2_Conv2d_5_3x3_s2_128/add_fold
    WARNING:tensorflow:From /home/withrobot/anaconda2/envs/tf114/lib/python2.7/site-packages/tensorflow/python/training/rmsprop.py:119: calling __init__ (from tensorflow.python.ops.init_ops) with dtype is deprecated and will be removed in a future version.
    Instructions for updating:
    Call initializer instance with the dtype argument instead of passing it to the constructor
    W0529 10:13:53.572329 139777032922880 deprecation.py:506] From /home/withrobot/anaconda2/envs/tf114/lib/python2.7/site-packages/tensorflow/python/training/rmsprop.py:119: calling __init__ (from tensorflow.python.ops.init_ops) with dtype is deprecated and will be removed in a future version.
    Instructions for updating:
    Call initializer instance with the dtype argument instead of passing it to the constructor
    INFO:tensorflow:Done calling model_fn.
    I0529 10:13:58.459552 139777032922880 estimator.py:1147] Done calling model_fn.
    INFO:tensorflow:Create CheckpointSaverHook.
    I0529 10:13:58.460464 139777032922880 basic_session_run_hooks.py:541] Create CheckpointSaverHook.
    INFO:tensorflow:Graph was finalized.
    I0529 10:14:02.831330 139777032922880 monitored_session.py:240] Graph was finalized.
    2020-05-29 10:14:02.831547: I tensorflow/core/platform/cpu_feature_guard.cc:142] Your CPU supports instructions that this TensorFlow binary was not compiled to use: SSE4.1 SSE4.2 AVX AVX2 FMA
    2020-05-29 10:14:02.865813: I tensorflow/core/platform/profile_utils/cpu_utils.cc:94] CPU Frequency: 4200000000 Hz
    2020-05-29 10:14:02.866757: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x5633ee49a6f0 executing computations on platform Host. Devices:
    2020-05-29 10:14:02.866992: I tensorflow/compiler/xla/service/service.cc:175]   StreamExecutor device (0): <undefined>, <undefined>
    2020-05-29 10:14:02.867481: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:1005] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
    2020-05-29 10:14:02.868152: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1640] Found device 0 with properties: 
    name: GeForce GTX 1080 Ti major: 6 minor: 1 memoryClockRate(GHz): 1.582
    pciBusID: 0000:01:00.0
    2020-05-29 10:14:02.868190: I tensorflow/stream_executor/platform/default/dso_loader.cc:42] Successfully opened dynamic library libcudart.so.10.1
    2020-05-29 10:14:02.868204: I tensorflow/stream_executor/platform/default/dso_loader.cc:42] Successfully opened dynamic library libcublas.so.10
    2020-05-29 10:14:02.868219: I tensorflow/stream_executor/platform/default/dso_loader.cc:42] Successfully opened dynamic library libcufft.so.10
    2020-05-29 10:14:02.868233: I tensorflow/stream_executor/platform/default/dso_loader.cc:42] Successfully opened dynamic library libcurand.so.10
    2020-05-29 10:14:02.868247: I tensorflow/stream_executor/platform/default/dso_loader.cc:42] Successfully opened dynamic library libcusolver.so.10
    2020-05-29 10:14:02.868259: I tensorflow/stream_executor/platform/default/dso_loader.cc:42] Successfully opened dynamic library libcusparse.so.10
    2020-05-29 10:14:02.868269: I tensorflow/stream_executor/platform/default/dso_loader.cc:42] Successfully opened dynamic library libcudnn.so.7
    2020-05-29 10:14:02.868311: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:1005] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
    2020-05-29 10:14:02.869045: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:1005] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
    2020-05-29 10:14:02.869680: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1763] Adding visible gpu devices: 0
    2020-05-29 10:14:02.870041: I tensorflow/stream_executor/platform/default/dso_loader.cc:42] Successfully opened dynamic library libcudart.so.10.1
    2020-05-29 10:14:02.944055: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1181] Device interconnect StreamExecutor with strength 1 edge matrix:
    2020-05-29 10:14:02.944098: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1187]      0 
    2020-05-29 10:14:02.944120: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1200] 0:   N 
    2020-05-29 10:14:02.944400: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:1005] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
    2020-05-29 10:14:02.947981: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:1005] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
    2020-05-29 10:14:02.949314: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:1005] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
    2020-05-29 10:14:02.950519: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1326] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 10334 MB memory) -> physical GPU (device: 0, name: GeForce GTX 1080 Ti, pci bus id: 0000:01:00.0, compute capability: 6.1)
    2020-05-29 10:14:02.952886: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x5633ec64a290 executing computations on platform CUDA. Devices:
    2020-05-29 10:14:02.952911: I tensorflow/compiler/xla/service/service.cc:175]   StreamExecutor device (0): GeForce GTX 1080 Ti, Compute Capability 6.1
    WARNING:tensorflow:From /home/withrobot/anaconda2/envs/tf114/lib/python2.7/site-packages/tensorflow/python/training/saver.py:1276: checkpoint_exists (from tensorflow.python.training.checkpoint_management) is deprecated and will be removed in a future version.
    Instructions for updating:
    Use standard file APIs to check for files with this prefix.
    W0529 10:14:02.954296 139777032922880 deprecation.py:323] From /home/withrobot/anaconda2/envs/tf114/lib/python2.7/site-packages/tensorflow/python/training/saver.py:1276: checkpoint_exists (from tensorflow.python.training.checkpoint_management) is deprecated and will be removed in a future version.
    Instructions for updating:
    Use standard file APIs to check for files with this prefix.
    INFO:tensorflow:Restoring parameters from /home/withrobot/tfmodel/models/research/object_detection/num_train/model.ckpt-0
    I0529 10:14:02.955209 139777032922880 saver.py:1280] Restoring parameters from /home/withrobot/tfmodel/models/research/object_detection/num_train/model.ckpt-0
    WARNING:tensorflow:From /home/withrobot/anaconda2/envs/tf114/lib/python2.7/site-packages/tensorflow/python/training/saver.py:1066: get_checkpoint_mtimes (from tensorflow.python.training.checkpoint_management) is deprecated and will be removed in a future version.
    Instructions for updating:
    Use standard file utilities to get mtimes.
    W0529 10:14:06.819551 139777032922880 deprecation.py:323] From /home/withrobot/anaconda2/envs/tf114/lib/python2.7/site-packages/tensorflow/python/training/saver.py:1066: get_checkpoint_mtimes (from tensorflow.python.training.checkpoint_management) is deprecated and will be removed in a future version.
    Instructions for updating:
    Use standard file utilities to get mtimes.
    2020-05-29 10:14:08.107750: W tensorflow/compiler/jit/mark_for_compilation_pass.cc:1412] (One-time warning): Not using XLA:CPU for cluster because envvar TF_XLA_FLAGS=--tf_xla_cpu_global_jit was not set.  If you want XLA:CPU, either set that envvar, or use experimental_jit_scope to enable XLA:CPU.  To confirm that XLA is active, pass --vmodule=xla_compilation_cache=1 (as a proper command-line flag, not via TF_XLA_FLAGS) or set the envvar XLA_FLAGS=--xla_hlo_profile.
    INFO:tensorflow:Running local_init_op.
    I0529 10:14:08.286267 139777032922880 session_manager.py:500] Running local_init_op.
    INFO:tensorflow:Done running local_init_op.
    I0529 10:14:08.654845 139777032922880 session_manager.py:502] Done running local_init_op.
    INFO:tensorflow:Saving checkpoints for 0 into /home/withrobot/tfmodel/models/research/object_detection/num_train/model.ckpt.
    I0529 10:14:21.281554 139777032922880 basic_session_run_hooks.py:606] Saving checkpoints for 0 into /home/withrobot/tfmodel/models/research/object_detection/num_train/model.ckpt.
    2020-05-29 10:14:34.514452: I tensorflow/stream_executor/platform/default/dso_loader.cc:42] Successfully opened dynamic library libcudnn.so.7
    INFO:tensorflow:loss = 316.98434, step = 0
    I0529 10:14:38.529766 139777032922880 basic_session_run_hooks.py:262] loss = 316.98434, step = 0
    2020-05-29 10:14:40.683977: E tensorflow/stream_executor/cuda/cuda_driver.cc:890] failed to alloc 8589934592 bytes on host: CUDA_ERROR_OUT_OF_MEMORY: out of memory
    2020-05-29 10:14:40.684276: W ./tensorflow/core/common_runtime/gpu/gpu_host_allocator.h:44] could not allocate pinned host memory of size: 8589934592
    2020-05-29 10:14:40.684398: E tensorflow/stream_executor/cuda/cuda_driver.cc:890] failed to alloc 7730940928 bytes on host: CUDA_ERROR_OUT_OF_MEMORY: out of memory
    2020-05-29 10:14:40.684456: W ./tensorflow/core/common_runtime/gpu/gpu_host_allocator.h:44] could not allocate pinned host memory of size: 7730940928
    ./run_model_main.sh: line 9:  3736 Killed                  python model_main.py --pipeline_config_path=${PIPELINE_CONFIG_PATH} --model_dir=${MODEL_DIR} --sample_1_of_n_eval_examples=${SAMPLE_1_OF_N_EVAL_EXAMPLES} --alsologtostderr

问题:

  1. 我将批处理大小设置为1且gpu_option.allow_growth = true,但是为什么我的内存不足问题?
  2. 如何解决这个问题?

0 个答案:

没有答案