tensorflow / tensorflow/models

Object Detection API - EfficientDet D2 - suddenly get OOM on some thousandths iteration!

Open
#10,159 0 comments 0 reactions 3 assignees View on GitHub

@pkulzc is already working on this.

Since Aug 4, 2021.

models:research:odapi type:support
Dominant language
Python
Stars
77.7k
Forks
44.8k
PR merge metrics
No merged PRs in 30d

Description

Train EfficientDet D2 on my own dataset with 10 labels.
I started to get OOM on some thousandths iteration. Last time is was on 54600 iteration!
I made many changes in pipeline.config, to matched the model on my dataset specifications. But the issue of suddenly OOM starts after adding more aspect_ratios.

Train the models on GPU 3090 with docker.
Resize images before convert them to tfrecord.
Batch Size: 8 (max for this GPU)

System Description:

  • Linux Ubuntu 20.04
  • GeForce 3090
  • TF2 - 2.4.3

Configuration (pipeline.config):
model {
ssd {
num_classes: 10
image_resizer {
keep_aspect_ratio_resizer {
min_dimension: 768
max_dimension: 768
pad_to_max_dimension: true
}
}
feature_extractor {
type: "ssd_efficientnet-b2_bifpn_keras"
conv_hyperparams {
regularizer {
l2_regularizer {
weight: 4e-05
}
}
initializer {
truncated_normal_initializer {
mean: 0.0
stddev: 0.03
}
}
activation: SWISH
batch_norm {
decay: 0.99
scale: true
epsilon: 0.001
}
force_use_bias: true
}
bifpn {
min_level: 3
max_level: 7
num_iterations: 5
num_filters: 112
}
}
box_coder {
faster_rcnn_box_coder {
y_scale: 1.0
x_scale: 1.0
height_scale: 1.0
width_scale: 1.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
use_matmul_gather: true
}
}
similarity_calculator {
iou_similarity {
}
}
box_predictor {
weight_shared_convolutional_box_predictor {
conv_hyperparams {
regularizer {
l2_regularizer {
weight: 4e-05
}
}
initializer {
random_normal_initializer {
mean: 0.0
stddev: 0.01
}
}
activation: SWISH
batch_norm {
decay: 0.99
scale: true
epsilon: 0.001
}
force_use_bias: true
}
depth: 112
num_layers_before_predictor: 3
kernel_size: 3
class_prediction_bias_init: -4.6
use_depthwise: true
}
}
anchor_generator {
multiscale_anchor_generator {
min_level: 3
max_level: 7
anchor_scale: 4.0
aspect_ratios: 0.25
aspect_ratios: 0.5
aspect_ratios: 0.7
aspect_ratios: 0.85
aspect_ratios: 0.1
aspect_ratios: 1.5
aspect_ratios: 2.0
scales_per_octave: 3
}
}
post_processing {
batch_non_max_suppression {
score_threshold: 1e-08
iou_threshold: 0.5
max_detections_per_class: 100
max_total_detections: 100
}
score_converter: SIGMOID
}
normalize_loss_by_num_matches: true
loss {
localization_loss {
weighted_smooth_l1 {
}
}
classification_loss {
weighted_sigmoid_focal {
gamma: 3.0
alpha: 0.15
}
}
classification_weight: 1.0
localization_weight: 1.0
}
encode_background_as_zeros: true
normalize_loc_loss_by_codesize: true
inplace_batchnorm_update: true
freeze_batchnorm: false
add_background_class: false
}
}
train_config {
batch_size: 8
data_augmentation_options {
random_horizontal_flip {
}
}
data_augmentation_options {
random_scale_crop_and_pad_to_square {
output_size: 768
scale_min: 0.10000000149011612
scale_max: 2.0
}
}
sync_replicas: true
optimizer {
momentum_optimizer {
learning_rate {
cosine_decay_learning_rate {
learning_rate_base: 0.002412
total_steps: 300000
warmup_learning_rate: 0.0000301500021059532
warmup_steps: 2500
}
}
momentum_optimizer_value: 0.9
}
use_moving_average: false
}
fine_tune_checkpoint: "local_path/efficientdet_d2_coco17_tpu-32/checkpoint/ckpt-0"
num_steps: 300000
startup_delay_steps: 0.0
replicas_to_aggregate: 8
max_number_of_boxes: 100
unpad_groundtruth_tensors: false
fine_tune_checkpoint_type: "detection"
use_bfloat16: false
fine_tune_checkpoint_version: V2
}
train_input_reader {
label_map_path: "path_to_workspace/training/annotations/label_map.pbtxt"
tf_record_input_reader {
input_path: "path_to_workspace/training/annotations/train.record"
}
}
eval_config {
metrics_set: "coco_detection_metrics"
use_moving_averages: false
include_metrics_per_category: true
batch_size: 1
}
eval_input_reader {
label_map_path: "path_to_workspace/training/annotations/label_map.pbtxt"
shuffle: false
num_epochs: 1
tf_record_input_reader {
input_path: "/home/tensorflow/models/research/workspace_L/training/annotations/test.record"
}
}

Last OOM Error message:

INFO:tensorflow:Step 54600 per-step time 1.096s loss=0.116
I0726 09:22:30.466438 140430122673984 model_lib_v2.py:702] Step 54600 per-step time 1.096s loss=0.116

Traceback (most recent call last):
File "model_main_tf2.py", line 132, in
tf.compat.v1.app.run()
File "/usr/local/lib/python3.8/dist-packages/tensorflow/python/platform/app.py", line 40, in run
_run(main=main, argv=argv, flags_parser=_parse_flags_tolerate_undef)
File "/usr/local/lib/python3.8/dist-packages/absl/app.py", line 300, in run
_run_main(main, args)
File "/usr/local/lib/python3.8/dist-packages/absl/app.py", line 251, in _run_main
sys.exit(main(argv))
File "model_main_tf2.py", line 123, in main
model_lib_v2.train_loop(
File "/home/tensorflow/.local/lib/python3.8/site-packages/object_detection/model_lib_v2.py", line 690, in train_loop
loss = _dist_train_step(train_input_iter)
File "/usr/local/lib/python3.8/dist-packages/tensorflow/python/eager/def_function.py", line 828, in call
result = self._call(*args, **kwds)
File "/usr/local/lib/python3.8/dist-packages/tensorflow/python/eager/def_function.py", line 855, in _call
return self._stateless_fn(*args, **kwds) # pylint: disable=not-callable
File "/usr/local/lib/python3.8/dist-packages/tensorflow/python/eager/function.py", line 2942, in call
return graph_function._call_flat(
File "/usr/local/lib/python3.8/dist-packages/tensorflow/python/eager/function.py", line 1918, in _call_flat
return self._build_call_outputs(self._inference_function.call(
File "/usr/local/lib/python3.8/dist-packages/tensorflow/python/eager/function.py", line 555, in call
outputs = execute.execute(
File "/usr/local/lib/python3.8/dist-packages/tensorflow/python/eager/execute.py", line 59, in quick_execute
tensors = pywrap_tfe.TFE_Py_Execute(ctx._handle, device_name, op_name,
tensorflow.python.framework.errors_impl.ResourceExhaustedError: 2 root error(s) found.
(0) Resource exhausted: OOM when allocating tensor with shape[100,257796] and type float on /job:localhost/replica:0/task:0/device:GPU:0 by allocator GPU_0_bfc
[[node Loss/Compare_7/IOU/Intersection/Minimum_1 (defined at home/tensorflow/.local/lib/python3.8/site-packages/object_detection/core/box_list_ops.py:257) ]]
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.

 [[train_input_images/write_summary/summary_cond/pivot_t/_64/_375]]

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) Resource exhausted: OOM when allocating tensor with shape[100,257796] and type float on /job:localhost/replica:0/task:0/device:GPU:0 by allocator GPU_0_bfc
[[node Loss/Compare_7/IOU/Intersection/Minimum_1 (defined at home/tensorflow/.local/lib/python3.8/site-packages/object_detection/core/box_list_ops.py:257) ]]
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.

0 successful operations.
0 derived errors ignored. [Op:__inference__dist_train_step_85689]

Errors may have originated from an input operation.
Input Source operations connected to node Loss/Compare_7/IOU/Intersection/Minimum_1:
Loss/Compare_7/IOU/Intersection/split (defined at home/tensorflow/.local/lib/python3.8/site-packages/object_detection/core/box_list_ops.py:250)

Input Source operations connected to node Loss/Compare_7/IOU/Intersection/Minimum_1:
Loss/Compare_7/IOU/Intersection/split (defined at home/tensorflow/.local/lib/python3.8/site-packages/object_detection/core/box_list_ops.py:250)

Function call stack:
_dist_train_step -> _dist_train_step

Any ideas why it happens ????
Thank you and sorry if it is too long.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.