EfficientNet-PyTorch icon indicating copy to clipboard operation
EfficientNet-PyTorch copied to clipboard

out of memory

Open wangmingrun1314 opened this issue 5 years ago • 11 comments

I use this model(efficient b4) as backbone.However , it occupies a large memory when going on training.Anyone else meets this problem? But ,in fact,it's size <100MB.

wangmingrun1314 avatar Feb 19 '20 04:02 wangmingrun1314

I have the same problem with almost any efficientnet model I use with a pytorch implementation. It is meant to take up less space than say a ResNet50, and in terms of number of parameters it does, but on the GPU it takes up >10GB when a ResNet50 model only takes up around 1.5GB

adityarajagopal avatar Feb 28 '20 10:02 adityarajagopal

I am also having this issue. I can't even train b0 on a GTX 1080...

SinclairHudson avatar Mar 09 '20 13:03 SinclairHudson

I'm not sure why the memory blows up but a quick fix is to reduce the batch size.

anantzoid avatar Mar 14 '20 14:03 anantzoid

I was using efficientnet to train cifar100 which required the images to be upscaled from 32x32 to 224x224. In the beginning of my forward, I had def forward(x) : x = F.interploate(x ...) ..., but interpolate is inplace, so replacing it with just F.interploate fixed the memory problem.

adityarajagopal avatar Mar 14 '20 14:03 adityarajagopal

I have the same issue. It seems to me that efficientnet-b4 has way more memory usage than a resnet101

YupengGao avatar Oct 19 '20 21:10 YupengGao

Me too. According to the original paper, EfficientNet-B4 should have similar FLOPs with ResNet-50. While the practical used memory of the former is much larger than the latter. And it's not only about the memory but also the training time! I have to use 60 hours to train the same task using EfficientNet-B4, which using ResNet-50 only takes me 27 hours.

makecent avatar Nov 30 '20 06:11 makecent

I was able to train the b0, b1, and b2 versions on a GeForce RTX 2080 Ti GPU. I receive an out of memory error when I try to train b3 and higher on the GPU. I also cannot log a b3 or higher model to TensorBoard without getting an exception. Before I spend a lot of time trying to understand whether this is an issue with my code, I want to know whether others have been able to train a b3 or higher model. I am using a batch size of 32 and resizing images according to the value returned by EfficientNet.get_image_size method.

blazingcayenne avatar Jan 22 '21 14:01 blazingcayenne

i am recently using this implement of Efficientdet ---- https://github.com/zylo117/Yet-Another-EfficientDet-Pytorch.I havn't met any respect cuda runtime error so far.

wangmingrun1314 avatar Jan 27 '21 06:01 wangmingrun1314

Same problem here, while resnet 18 takes about 1.5 gb of memory, efficientnet-b0 takes more than 4 gb!!

efficient net has about 5M parameters while resnet 18 has about 11M.

Is there sth wrong here?

SiavashCS avatar Mar 24 '21 17:03 SiavashCS

Same issue here. My resnet50 takes about 2.5 GB when fine-tuning for my own dataset with batch size 2. But it blows up to 228 GB when switching to efficientnet-b7, 50 GB with efficientnet-b4. Only efficientnet-b2 fits for now.

sarahESL avatar Apr 11 '21 14:04 sarahESL

By following this colab example, I got rid of this problem by using a resizing transformation. The size can be obtained with EfficientNet.get_image_size(model_name)

anderflash avatar Jun 17 '21 14:06 anderflash