Out Of Memory when training on Big Images
Out Of Memory when training on Big Images
Systeme Information
- OS Platform and Distribution: Linux Ubuntu 16.04 LTS
- TensorFlow installed from: pip tensorflow-gpu
- TensorFlow version: ('v1.2.0-rc2-21-g12f033d', '1.2.0')
- CUDA/cuDNN version: Cuda 8.0, Cudnn 5.1
- GPU model and memory: 8 Tesla K-80, Cores 2, Memory 7.5 G
Describe the Problem
I have successfully run the pets tutorial on this Google Compute Instance When I train a fasterrcnn resnet 101 on my dataset (VOC format, 47 classes, image_size: 1000/2000) with:
python object_detection/train.py --train_dir=data_xxxx --pipeline_config_path=data_xxxx/faster_rcnn_resnet101_pets.config
I get the following error at the beginning of the training:
2017-06-29 17:24:13.193833: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1030] Creating TensorFlow device (/gpu:7) -> (device: 7, name: Tesla K80, pci bus id: 0000:00:0b.0)
2017-06-29 17:24:15.414228: I tensorflow/core/common_runtime/simple_placer.cc:675] Ignoring device specification /device:GPU:0 for node 'prefetch_queue_Dequeue' because the input edge from 'prefetch_queue' is a reference connection and already has a device field set to /device:CPU:0
INFO:tensorflow:Restoring parameters from /home/ubuntu/models/data_xxxx/model.ckpt
INFO:tensorflow:Starting Session.
INFO:tensorflow:Saving checkpoint to path data_doliprane/model.ckpt
INFO:tensorflow:Starting Queues.
INFO:tensorflow:global_step/sec: 0
[1] 4359 killed python object_detection/train.py --train_dir=data_xxxx
I managed to avoid the oom on this dataset by resizing all the images and annotation files (divided the dimensions by 4).
I didn't modify the config file(just the number of class and the paths), therefore they should be resized at 600 1024, and the bug should not occur with the big images
Is there a way I can train on my images without having to shrink them? Are there some parameters I can tune to avoid this problem?
Do you know what component is hitting OOM (CPU or GPU)? If CPU bound, it might be worth trying to shrink the queue sizes a little bit. The default values we use for queue_capacity and min_after_dequeue are 20001000. Try shrinking them to 1000/500 or 500/250 and see if that solves your OOM problems.
The section in your new config will look like this:
train_input_reader: {
tf_record_input_reader {
input_path: "PATH_TO_BE_CONFIGURED/pet_train.record"
}
label_map_path: "PATH_TO_BE_CONFIGURED/pet_label_map.pbtxt"
queue_capacity: 500
min_after_dequeue: 250
}
Thank you very much for your answer @derekjchow. You have put me on the right track.
Indeed it is a RAM issue.
I monitored the RAM during the training and we were reaching out the 7.5G available.
Even with your modification it is still not working.
I resized the machine to 16CPU and 104G of RAM, and it worked. But the training is very greedy and use 84G of RAM at the beginning and is stable around 87G after some raising_pool_size_limit as it goes through the first iterations:
2017-06-30 10:29:21.269187: I tensorflow/core/common_runtime/gpu/pool_allocator.cc:247] PoolAllocator: After 2110 get requests, put_count=2063 evicted_count=1000 eviction_rate=0.484731 and unsatisfied allocation rate=0.507109
2017-06-30 10:29:21.269322: I tensorflow/core/common_runtime/gpu/pool_allocator.cc:259] Raising pool_size_limit_ from 256 to 281
I tried to modify the queue_capacity and min_after_dequeue to 500/250, 100/50 and even 2/1 but it doesn't seem to impact the RAM usage during the training.
Do you know which parameters I have to tweak to decrease the RAM usage?
Hello @derekjchow I have the same problem as @pjeambrun and I'm trying locally with 8-core 16GB. I also changed that parameters and nothing changed, even trying to train with 2 images one for each label. it is possible to manage the number of threads or the amount of RAM?
pls help..
same issue for me, any help would be awesome. As a comparaison running py faster rcnn does not require that much of RAM.
Same issue here, tried to resize images and queues, but my 32GB of RAM get consumed immediately. How to reduce the RAM usage? SSD with mobilenet should not require so much.
Hi @pjeambrun i'm dealing with the same issue... I don't find a way to limit the RAM and all rcnn consumes everything. Can you help us? I'm trying to retrain de object detector model with my own images, but i didn't find any solution. I monitored the ram while the train starts, but after 30 secs, the kernel kill the process. I also try to train the net with 1 image, and the same happens.. Probably the script is loading the whole net in RAM and this could be the problem.. isn't it?
I was trying to find something to limit the resources but I didn't find anything..
Hi again guys, we have found a solution changing the batch_size to one. By default this parameter is set to 32, so probably this needs too much RAM.
I don't understand why this is consuming this extremely amount of RAM, but you can change this and train a model in a normal environment.
If @pjeambrun knows something about that, we will appreciate any information.
Hi @mgparada nothing new on my side. I do also think that the problem is coming from the input reader but if you take a look at its config file there are no other relevant parameters for the RAM usage. For now the only solution I have is to manually reduce the image size and annotation files to make the training work on a smaller google compute instance.
I got a bit confused about whether people are training SSD or Faster R-CNN on this thread, but what I will say is that the batch_size in our API refers to batch size per worker, so in typical Faster R-CNN training scenarios where you resize an image so that it's smallest dimension is 600 pixels, the largest batch size possible is no greater than 1 or 2. With our default SSD configs, we resize to 300x300 or so, and in this case we train with a larger batch size, usually ranging between 16 and 32.
@jch1 for mobile net SSD even batch size 1 consumes way more RAM than it should. On my machine with 32 GB of RAM, those get consumed immediately (alongside 20GB of swap mem). There really should not be the need for so much CPU RAM when training on GPU...
@AndreaPisoni - I'm pretty surprised that this is happening as I don't see the same behavior when I train. Can you say what size you resized the images to?
It was the same with me, could anyone solve the problem please?
System: Ubuntu 16.04 64 bits Intel core i7 12 gb ram 2 gb gpu nvidia Pip intall Tensorflow
Sent from my Motorola XT1058 using FastHub
@jch1 Here, this is something I really do not understand. Why do I need to resize the input images if I already have a low-ish input size (300x300)? The pipeline should be:
- Take one image
- Perform a random crop of same size of input tensor
- Perform pre-processing on resized image
- Enqueue
I do not want to resize images "a priori" as the images have small objects inside of them. I assumed this was the pipeline, but maybe it is not? Do the images get enqueued at full res?
Hi @jch1, thank you for your answer.
An easy way to reproduce this issue:
Follow the Training an object detector using Cloud Machine Learning Engine (locally), but with bigger images, around 1400/1950 for instance.
This should consume more than 25G of RAM even with very low queue_capacity/min_after_dequeue parameters.
System Information: Google Compute Engine
- OS Platform and Distribution: Linux Ubuntu 16.04 LTS
- TensorFlow installed from: pip tensorflow-gpu
- TensorFlow version: ('v1.2.0-rc2-21-g12f033d', '1.2.0')
- CUDA/cuDNN version: Cuda 8.0, Cudnn 5.1
- GPU model and memory: 8 Tesla K-80, Cores 6, Memory 30 G
@pjeambrun so you're getting OOM even with batch size of 1?
BTW, jemalloc has a memory heap profiler. Could you try that and see where the memory goes?
Hi @drpngx,
The batch size is set to default as it is in the faster_rcnn_resnet101_pets.config:
train_config: {
batch_size: 1
optimizer {
momentum_optimizer: {
And the training is still consuming too much RAM:
- 25 G of RAM for an image size of 1400/1900
- 85 G of RAM for an image size of 2800/4000
I did these tests on a machine with a 100 G RAM limit.
When I launch the jemalloc heap profiling on the training with images of size 1400/1900, the whole 100 G of RAM are consumed during the initialization and the machine goes OOM.
MALLOC_CONF=prof_leak:true,lg_prof_sample:0,prof_final:true \
LD_PRELOAD=/usr/local/lib/libjemalloc.so.2 python object_detection/train.py --train_dir output_xxxx_jemalloc --pipeline_config_path data_xxxx/faster_rcnn_resnet101_pets.config
The output
INFO:tensorflow:Scale of 0 disables regularizer.
INFO:tensorflow:Scale of 0 disables regularizer.
INFO:tensorflow:Scale of 0 disables regularizer.
INFO:tensorflow:Scale of 0 disables regularizer.
INFO:tensorflow:Scale of 0 disables regularizer.
INFO:tensorflow:Scale of 0 disables regularizer.
INFO:tensorflow:Summary name Learning Rate is illegal; using Learning_Rate instead.
INFO:tensorflow:Summary name /clone_loss is illegal; using clone_loss instead.
/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/gradients_impl.py:93: UserWarning: Converting sparse IndexedSlices to a dense Tensor of unknown shape. This may consume a large amount of memory.
"Converting sparse IndexedSlices to a dense Tensor of unknown shape. "
May this have to do with the queue_capacity and min_after_dequeue parameters in https://github.com/tensorflow/models/blob/master/object_detection/protos/input_reader.proto ?
Hi guys, same issue here.
OS Platform and Distribution: Linux Ubuntu 16.04 LTS TensorFlow installed from: pip tensorflow-gpu TensorFlow version 1.3.0 CUDA/cuDNN version: Cuda 8.0, Cudnn 5.1 GPU model and memory: GeForce GTX 1080 Ti 1080, Memory 11 G
I run the training locally using Faster R-CNN resnet 101 starting from a pretrained network. My images are 1280 x 720 pixels. The training consumes all my 8 Gb of ram plus 5 Gb of my swap memory.
I tried already reducing the queue capacity and it did not work. train_input_reader: { tf_record_input_reader { input_path: "/home/alessandro/Tf_GoogleAPI/models/object_detection/data/checkout_train.record" } label_map_path: "/home/alessandro/Tf_GoogleAPI/models/object_detection/data/checkout_label_map.pbtxt" queue_capacity: 500 min_after_dequeue: 250 }
Here is the running of the first step
INFO:tensorflow:Scale of 0 disables regularizer. INFO:tensorflow:Scale of 0 disables regularizer. INFO:tensorflow:Scale of 0 disables regularizer. INFO:tensorflow:Scale of 0 disables regularizer. INFO:tensorflow:Scale of 0 disables regularizer. INFO:tensorflow:Summary name Learning Rate is illegal; using Learning_Rate instead. INFO:tensorflow:Summary name /clone_loss is illegal; using clone_loss instead. /home/alessandro/Tf_GoogleAPI/lib/python3.5/site-packages/tensorflow/python/ops/gradients_impl.py:95: UserWarning: Converting sparse IndexedSlices to a dense Tensor of unknown shape. This may consume a large amount of memory. "Converting sparse IndexedSlices to a dense Tensor of unknown shape. " 2017-08-23 11:44:44.463435: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.1 instructions, but these are available on your machine and could speed up CPU computations. 2017-08-23 11:44:44.463448: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.2 instructions, but these are available on your machine and could speed up CPU computations. 2017-08-23 11:44:44.463451: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use AVX instructions, but these are available on your machine and could speed up CPU computations. 2017-08-23 11:44:44.463453: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use AVX2 instructions, but these are available on your machine and could speed up CPU computations. 2017-08-23 11:44:44.463456: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use FMA instructions, but these are available on your machine and could speed up CPU computations. 2017-08-23 11:44:44.638905: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:893] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero 2017-08-23 11:44:44.640117: I tensorflow/core/common_runtime/gpu/gpu_device.cc:955] Found device 0 with properties: name: GeForce GTX 1080 Ti major: 6 minor: 1 memoryClockRate (GHz) 1.582 pciBusID 0000:01:00.0 Total memory: 10.91GiB Free memory: 10.49GiB 2017-08-23 11:44:44.751337: W tensorflow/stream_executor/cuda/cuda_driver.cc:523] A non-primary context 0x1435fa50 exists before initializing the StreamExecutor. We haven't verified StreamExecutor works with that. 2017-08-23 11:44:44.751608: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:893] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero 2017-08-23 11:44:44.751919: I tensorflow/core/common_runtime/gpu/gpu_device.cc:955] Found device 1 with properties: name: GeForce GTX 1080 Ti major: 6 minor: 1 memoryClockRate (GHz) 1.582 pciBusID 0000:02:00.0 Total memory: 10.91GiB Free memory: 10.76GiB 2017-08-23 11:44:44.752536: I tensorflow/core/common_runtime/gpu/gpu_device.cc:976] DMA: 0 1 2017-08-23 11:44:44.752542: I tensorflow/core/common_runtime/gpu/gpu_device.cc:986] 0: Y Y 2017-08-23 11:44:44.752545: I tensorflow/core/common_runtime/gpu/gpu_device.cc:986] 1: Y Y 2017-08-23 11:44:44.752549: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1045] Creating TensorFlow device (/gpu:0) -> (device: 0, name: GeForce GTX 1080 Ti, pci bus id: 0000:01:00.0) 2017-08-23 11:44:44.752552: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1045] Creating TensorFlow device (/gpu:1) -> (device: 1, name: GeForce GTX 1080 Ti, pci bus id: 0000:02:00.0) INFO:tensorflow:Restoring parameters from object_detection/models/checkout/model.ckpt-1672 2017-08-23 11:44:45.444359: I tensorflow/core/common_runtime/simple_placer.cc:697] Ignoring device specification /device:GPU:0 for node 'prefetch_queue_Dequeue' because the input edge from 'prefetch_queue' is a reference connection and already has a device field set to /device:CPU:0 INFO:tensorflow:Starting Session. INFO:tensorflow:Saving checkpoint to path object_detection/models/checkout/model.ckpt INFO:tensorflow:Starting Queues. INFO:tensorflow:global_step/sec: 0 INFO:tensorflow:Recording summary at step 1674. INFO:tensorflow:global step 1675: loss = 0.2660 (14.730 sec/step)
Any solution emerged so far except resizing images? If not what is then the image size "suggested"? Thank you for your help, AS
Only 8GB or ram here.
I haven't tried resizing the images yet, but I imagine resizing them all to the dimension specified in the image_resizer part of the model would do the trick. In my scenario :
image_resizer {
keep_aspect_ratio_resizer {
min_dimension: 600
max_dimension: 1024
}
}
I've been playing with very low settings for the queue
queue_capacity: 2
min_after_dequeue: 1
num_readers: 2
Would there be any side effects of doing that ? (besides the ability to shuffle the training samples).