models icon indicating copy to clipboard operation
models copied to clipboard

ResourceExhaustedError during retraining in Object detection API

Open Garima-Mishra opened this issue 9 years ago • 13 comments

I am trying to train the mobilenet v1 with pets data set. from tensorflow.python.client import device_lib device_lib.list_local_devices() gives following output name: GeForce GTX 750 Ti major: 5 minor: 0 memoryClockRate (GHz) 1.15 pciBusID 0000:03:00.0 Total memory: 1.95GiB Free memory: 1.93GiB

But when I run training. I get the error tensorflow/core/framework/op_kernel.cc:1158] Resource exhausted: OOM when allocating tensor with shape[24,128,75,75] INFO:tensorflow:Error reported to Coordinator: <class 'tensorflow.python.framework.errors_impl.ResourceExhaustedError'>, OOM when allocating tensor with shape[24,128,75,75]

Even tried with pascal dataset and other pre-trained models also. I was able to run call models for running the object detection tutorial. I followed the instruction given for running_locally.md One thing I observed that all of the GPU memory get exhausted before throwing the error. What is the minimum GPU memory required for training?

Garima-Mishra avatar Jun 26 '17 14:06 Garima-Mishra

Hi @Garima-Mishra - most of out models require much more than 2Gb of memory (usually between >10 Gb at training time). A few things you could do (besides get a new GPU):

  1. decrease the training resolution
  2. decrease the batch size

In each of these cases you may need to experiment a bit with hyperparameters like learning rate.

jch1 avatar Jun 27 '17 04:06 jch1

Hi, @jch1 Thanks for the quick response. Can I use multiple GPU's for training as I have two 8GB GPU as well? I will try with your suggestions of reducing batch size and resolution as well.

Garima-Mishra avatar Jun 27 '17 09:06 Garima-Mishra

Yes, you have to tweak the num_clones parameter (see the object_detection/train.py file).

jch1 avatar Jun 27 '17 17:06 jch1

simply tweaking the num_clones parameter (along with adjusting batch size) doesn't seem to get multi-GPU to work @jch1, see #1782

SimsGautam avatar Jun 27 '17 19:06 SimsGautam

I have the same issue running Faster-RCNN with Inception Resnet V2. I have been running the model on a GeForce GTX 1080 and a Tesla K80 (the GPU on the AWS P2 instances), respectively 8GB and 12GB of memory.

I've tried to change the resolution, down to 400:

image_resizer {
  keep_aspect_ratio_resizer {
    min_dimension: 400
    max_dimension: 400
  }
}

And change the batch_size, down to 8

second_stage_batch_size: 8

But I still have the same error.

tmattio avatar Jul 19 '17 13:07 tmattio

Actually, it's not exactly the same issue. Here is the error:

ResourceExhaustedError (see above for traceback): Ran out of GPU memory when allocating 0 bytes for 
         [[Node: Loss/RPNLoss/Loss_1/SoftmaxCrossEntropyWithLogits = SoftmaxCrossEntropyWithLogits[T=DT_FLOAT, _device="/job:localhost/replica:0/task:0/gpu:0"](Loss/RPNLoss/Loss_1/Reshape_2, Loss/RPNLoss/Loss_1/Reshape_3)]]
         [[Node: gradients/FirstStageFeatureExtractor/InceptionResnetV2/InceptionResnetV2/Repeat_1/block17_11/Conv2d_1x1/convolution_grad/tuple/control_dependency_1/_5227 = _Recv[client_terminated=false, recv_device="/job:localhost/replica:0/task:0/cpu:0", send_device="/job:localhost/replica:0/task:0/gpu:0", send_device_incarnation=1, tensor_name="edge_28924_gradients/FirstStageFeatureExtractor/InceptionResnetV2/InceptionResnetV2/Repeat_1/block17_11/Conv2d_1x1/convolution_grad/tuple/control_dependency_1", tensor_type=DT_FLOAT, _device="/job:localhost/replica:0/task:0/cpu:0"]()]]

The Ran out of GPU memory when allocating 0 bytes is interesting...

Any ideas?

tmattio avatar Jul 19 '17 14:07 tmattio

I am new to tensorflow and Machine Learning. Recently I am working on a model. My model is like below,

  1. Character level Embedding Vector -> Embedding lookup -> LSTM1

  2. Word level Embedding Vector->Embedding lookup -> LSTM2

  3. [LSTM1+LSTM2] -> single layer MLP-> softmax layer

  4. [LSTM1+LSTM2] -> Single layer MLP-> WGAN discriminator

while I'm working on this model I got the following error. I thought My batch is too big. Thus I tried to reduce the batch size from 20 to 10 but it doesn't work.

ResourceExhaustedError (see above for traceback): OOM when allocating tensor with shape[24760,100] [[Node: chars/bidirectional_rnn/bw/bw/while/bw/lstm_cell/split = Split[T=DT_FLOAT, num_split=4, _device="/job:localhost/replica:0/task:0/device:GPU:0"](gradients_2/Add_3/y, chars/bidirectional_rnn/bw/bw/while/bw/lstm_cell/BiasAdd)]] [[Node: bi-lstm/bidirectional_rnn/bw/bw/stack/_167 = _Recvclient_terminated=false, recv_device="/job:localhost/replica:0/task:0/device:CPU:0", send_device="/job:localhost/replica:0/task:0/device:GPU:0", send_device_incarnation=1, tensor_name="edge_636_bi-lstm/bidirectional_rnn/bw/bw/stack", tensor_type=DT_INT32, _device="/job:localhost/replica:0/task:0/device:CPU:0"]]

tensor with shape[24760,100] means 247600032/10241024 = 75.*** MB memory. I am running the code on a titan X(11 GB) gpu. What could go wrong. Why this type of error occured?

Extra info: the size of the LSTM1 is 100. for bidirectional LSTM it becomes 200. The size of the LSTM2 is 300. For Bidirectional LSTM it becomes 600.

Note : The error occurred after 32 epoch. My question is why after 32 epoch there is an error. Why not at the initial epoch.

sbmaruf avatar Dec 28 '17 13:12 sbmaruf

Hi, I have the same problem. I'm training a faster-RCNN for my costume dataset and I got the following error. Batch size is one and I use image_resizer to resize images. image_resizer { keep_aspect_ratio_resizer { min_dimension: 150 max_dimension: 300 } INFO:tensorflow:global step 4389: loss = 0.1126 (0.149 sec/step) 2018-04-11 12:29:38.587877: E tensorflow/core/common_runtime/bfc_allocator.cc:244] tried to allocate 0 bytes 2018-04-11 12:29:38.587989: W tensorflow/core/common_runtime/allocator_retry.cc:32] Request to allocate 0 bytes 2018-04-11 12:29:38.588018: E tensorflow/core/common_runtime/bfc_allocator.cc:244] tried to allocate 0 bytes 2018-04-11 12:29:38.588037: W tensorflow/core/common_runtime/allocator_retry.cc:32] Request to allocate 0 bytes 2018-04-11 12:29:38.588263: E tensorflow/core/common_runtime/bfc_allocator.cc:378] tried to deallocate nullptr 2018-04-11 12:29:38.588404: E tensorflow/core/common_runtime/bfc_allocator.cc:378] tried to deallocate nullptr 2018-04-11 12:29:38.593826: W tensorflow/core/framework/op_kernel.cc:1192] Resource exhausted: Ran out of GPU memory when allocating 0 bytes for [[Node: Loss/RPNLoss/Loss_1/SoftmaxCrossEntropyWithLogits = SoftmaxCrossEntropyWithLogits[T=DT_FLOAT, _device="/job:localhost/replica:0/task:0/device:GPU:0"](Loss/RPNLoss/Loss_1/Reshape_2, Loss/RPNLoss/Loss_1/Reshape_3)]]

MohammadMoradi avatar Apr 11 '18 08:04 MohammadMoradi

https://stackoverflow.com/questions/48007984/training-broke-with-resourceexausted-error

follow the answer.

sbmaruf avatar Apr 11 '18 09:04 sbmaruf

I have NVIDIA GeForce GTX 1060 6 GB and this error happens to me

It's not about GPU memory

I was training on Notebook with NVIDIA GeForce 940 MX 2 GB and it was working ok

anonym24 avatar Nov 06 '18 08:11 anonym24

I had the same issue even when my batch_size was already 1. I resized the image to 400x400 in the config file and then it ran without errors.

image_resizer {
      keep_aspect_ratio_resizer {
        min_dimension: 400
        max_dimension: 400
      }

JigyasaK avatar Jan 25 '19 12:01 JigyasaK

I will give you a link of issue that is similar to yours: #1817.

For guys who stuck into the same problem with a not-bad GPU, there are some ways that would handle it:

  1. reduce your batch_size in train_config block, as mentioned by https://github.com/tensorflow/models/issues/1766#issuecomment-311250580
  2. resize your images to a lower resolution , by doing the way like https://github.com/tensorflow/models/issues/1817#issuecomment-325851293
  3. warn the other one who uses the same GPU, add the following lines into object_detection/model_main.py
session_config = tf.ConfigProto()
session_config.gpu_options.per_process_gpu_memory_fraction = 0.5    # replace this field with whichever real number you prefer
                                                                    # also gives a workaround to specify RAM usage
config = tf.estimator.RunConfig(model_dir=FLAGS.model_dir, session_config=session_config)
  1. try the following snippet as mentioned by https://github.com/tensorflow/models/issues/1817#issuecomment-325988741
train_config: {
  batch_size: 1
  ...
  batch_queue_capacity: 150
  num_batch_queue_threads: 8
  prefetch_queue_capacity: 10
}
  1. or maybe you just forgot to reduce num_classes to fit your needs ; )

Hopefully at least one of these solutions would help

codingpy avatar Apr 01 '19 10:04 codingpy

Hi There, We are checking to see if you still need help on this, as this seems to be considerably old issue. Please update this issue with the latest information, code snippet to reproduce your issue and error you are seeing. If we don't hear from you in the next 7 days, this issue will be closed automatically. If you don't need help on this issue any more, please consider closing this.

tensorflowbutler avatar Jan 29 '20 23:01 tensorflowbutler