自定义对象检测train.py-错误:块位于

时间:2019-05-25 18:20:34

标签: python python-3.x tensorflow image-recognition

我对tensorflow对象检测还很陌生。当前正在运行最新版本1.13.1。我的CUDA版本是10.0,cudnn版本也相应。我已经正确设置了模型设置,labelmap很好。但是当我开始训练时,它显示的是训练进度,而不是训练进度。

我尝试了不同的模型进行训练,还几次重新安装了tensorflow

这是我用于训练的命令:

python train.py --logtostderr --train_dir = Training_dir / --pipeline_config_path = Training / faster_rcnn_inception_v2_pets.config

这是我的.config文件:

model {
  ssd {
    num_classes: 1
    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: 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: 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: 1.0
    }
  }
  fine_tune_checkpoint: "D:/tensorflow/models-master/research/object_detection/ssd_mobilenet_v2_coco_2018_03_29/model.ckpt"
  fine_tune_checkpoint_type:  "detection"
  num_steps: 200000
  data_augmentation_options {
    random_horizontal_flip {
    }
  }
  data_augmentation_options {
    ssd_random_crop {
    }
  }
}

train_input_reader: {
  tf_record_input_reader {
    input_path: "D:/tensorflow/models-master/research/object_detection/Images/train.record"
  }
  label_map_path: "D:/tensorflow/models-master/research/object_detection/Training/labelmap.pbtxt"
}

eval_config: {
  num_examples: 8000

  max_evals: 10
}

eval_input_reader: {
  tf_record_input_reader {
    input_path: "D:/tensorflow/models-master/research/object_detection/Images/test.record"
  }
  label_map_path: "D:/tensorflow/models-master/research/object_detection/Training/labelmap.pbtxt"
  shuffle: false
  num_readers: 1
}

这是每次训练时日志的样子(缩短-完整日志在这里https://pastebin.com/raw/EtkkfiDX):

2019-05-04 15:49:49.681406: I tensorflow/core/common_runtime/bfc_allocator.cc:632] Chunk at 0000000715B7F200 of size 256
...
2019-05-04 15:49:49.915674: I tensorflow/core/common_runtime/bfc_allocator.cc:641] 2 Chunks of size 718848000 totalling 1.34GiB
2019-05-04 15:49:49.918760: I tensorflow/core/common_runtime/bfc_allocator.cc:645] Sum Total of in-use chunks: 1.77GiB
2019-05-04 15:49:49.921284: I tensorflow/core/common_runtime/bfc_allocator.cc:647] Stats:
Limit: 3006477107
InUse: 1902062848
MaxInUse: 1902062848
NumAllocs: 12819
MaxAllocSize: 718848000

2019-05-04 15:49:49.928506: W tensorflow/core/common_runtime/bfc_allocator.cc:271] ________________**********************************************************__________________
2019-05-04 15:49:49.931977: W tensorflow/core/framework/op_kernel.cc:1401] OP_REQUIRES failed at conv_ops.cc:446 : Resource exhausted: OOM when allocating tensor with shape[52,64,480,300] and type float on /job:localhost/replica:0/task:0/device:GPU:0 by allocator GPU_0_bfc
INFO:tensorflow:Error reported to Coordinator: OOM when allocating tensor with shape[52,64,480,300] and type float on /job:localhost/replica:0/task:0/device:GPU:0 by allocator GPU_0_bfc
[[node FirstStageFeatureExtractor/InceptionV2/InceptionV2/Conv2d_1a_7x7/separable_conv2d (defined at D:\tensorflow\models-master\research\slim\nets\inception_v2.py:117) ]]
Hint: If you want to see a list of allocated tensors when OOM happens, add report_tensor_allocations_upon_oom to RunOptions for current allocation info.

[[node BatchMultiClassNonMaxSuppression/map/while/MultiClassNonMaxSuppression/Reshape (defined at D:\tensorflow\models-master\research\object_detection\core\post_processing.py:136) ]]
Hint: If you want to see a list of allocated tensors when OOM happens, add report_tensor_allocations_upon_oom to RunOptions for current allocation info.

Caused by op 'FirstStageFeatureExtractor/InceptionV2/InceptionV2/Conv2d_1a_7x7/separable_conv2d', defined at:
File "train.py", line 184, in 
tf.app.run()
File "D:\Program Files\Anaconda3\envs\tensorflow\lib\site-packages\tensorflow\python\platform\app.py", line 125, in run
_sys.exit(main(argv))
File "D:\Program Files\Anaconda3\envs\tensorflow\lib\site-packages\tensorflow\python\util\deprecation.py", line 324, in new_func
return func(*args, **kwargs)
File "train.py", line 180, in main
graph_hook_fn=graph_rewriter_fn)
File "D:\tensorflow\models-master\research\object_detection\legacy\trainer.py", line 291, in train
clones = model_deploy.create_clones(deploy_config, model_fn, [input_queue])
File "D:\tensorflow\models-master\research\slim\deployment\model_deploy.py", line 193, in create_clones
outputs = model_fn(*args, **kwargs)
File "D:\tensorflow\models-master\research\object_detection\legacy\trainer.py", line 204, in _create_losses
prediction_dict = detection_model.predict(images, true_image_shapes)
File "D:\tensorflow\models-master\research\object_detection\meta_architectures\faster_rcnn_meta_arch.py", line 647, in predict
image_shape) = self._extract_rpn_feature_maps(preprocessed_inputs)
File "D:\tensorflow\models-master\research\object_detection\meta_architectures\faster_rcnn_meta_arch.py", line 978, in _extract_rpn_feature_maps
scope=self.first_stage_feature_extractor_scope))
File "D:\tensorflow\models-master\research\object_detection\meta_architectures\faster_rcnn_meta_arch.py", line 163, in extract_proposal_features
return self._extract_proposal_features(preprocessed_inputs, scope)
File "D:\tensorflow\models-master\research\object_detection\models\faster_rcnn_inception_v2_feature_extractor.py", line 138, in _extract_proposal_features
scope=scope)
File "D:\tensorflow\models-master\research\slim\nets\inception_v2.py", line 117, in inception_v2_base
scope=end_point)
File "D:\Program Files\Anaconda3\envs\tensorflow\lib\site-packages\tensorflow\contrib\framework\python\ops\arg_scope.py", line 182, in func_with_args
return func(*args, **current_args)
File "D:\Program Files\Anaconda3\envs\tensorflow\lib\site-packages\tensorflow\contrib\layers\python\layers\layers.py", line 2778, in separable_convolution2d
outputs = layer.apply(inputs)
File "D:\Program Files\Anaconda3\envs\tensorflow\lib\site-packages\tensorflow\python\keras\engine\base_layer.py", line 1227, in apply
return self.call(inputs, *args, **kwargs)
File "D:\Program Files\Anaconda3\envs\tensorflow\lib\site-packages\tensorflow\python\layers\base.py", line 530, in call
outputs = super(Layer, self).call(inputs, *args, **kwargs)
File "D:\Program Files\Anaconda3\envs\tensorflow\lib\site-packages\tensorflow\python\keras\engine\base_layer.py", line 554, in call
outputs = self.call(inputs, *args, **kwargs)
File "D:\Program Files\Anaconda3\envs\tensorflow\lib\site-packages\tensorflow\python\keras\layers\convolutional.py", line 1691, in call
data_format=conv_utils.convert_data_format(self.data_format, ndim=4))
File "D:\Program Files\Anaconda3\envs\tensorflow\lib\site-packages\tensorflow\python\ops\nn_impl.py", line 681, in separable_conv2d
name=name)
File "D:\Program Files\Anaconda3\envs\tensorflow\lib\site-packages\tensorflow\python\ops\gen_nn_ops.py", line 1113, in conv2d
data_format=data_format, dilations=dilations, name=name)
File "D:\Program Files\Anaconda3\envs\tensorflow\lib\site-packages\tensorflow\python\framework\op_def_library.py", line 788, in _apply_op_helper
op_def=op_def)
File "D:\Program Files\Anaconda3\envs\tensorflow\lib\site-packages\tensorflow\python\util\deprecation.py", line 507, in new_func
return func(*args, **kwargs)
File "D:\Program Files\Anaconda3\envs\tensorflow\lib\site-packages\tensorflow\python\framework\ops.py", line 3300, in create_op
op_def=op_def)
File "D:\Program Files\Anaconda3\envs\tensorflow\lib\site-packages\tensorflow\python\framework\ops.py", line 1801, in init
self._traceback = tf_stack.extract_stack()

ResourceExhaustedError (see above for traceback): OOM when allocating tensor with shape[52,64,480,300] and type float on /job:localhost/replica:0/task:0/device:GPU:0 by allocator GPU_0_bfc
[[node FirstStageFeatureExtractor/InceptionV2/InceptionV2/Conv2d_1a_7x7/separable_conv2d (defined at D:\tensorflow\models-master\research\slim\nets\inception_v2.py:117) ]]
Hint: If you want to see a list of allocated tensors when OOM happens, add report_tensor_allocations_upon_oom to RunOptions for current allocation info.

[[node BatchMultiClassNonMaxSuppression/map/while/MultiClassNonMaxSuppression/Reshape (defined at D:\tensorflow\models-master\research\object_detection\core\post_processing.py:136) ]]
Hint: If you want to see a list of allocated tensors when OOM happens, add report_tensor_allocations_upon_oom to RunOptions for current allocation info.

1 个答案:

答案 0 :(得分:0)

我可以通过使用“ batch_size”配置参数(batch_size:10对我有用)解决OOM问题。