Deciding on image size vs model size

username: Naif40
cooked: <p>I am trying to train a 3D resnet-18 \ resnet-34 \ resnet-50 model similar to the model in here:</p>
<aside class="onebox githubblob">
  <header class="source">
      <a href="https://github.com/kenshohara/3D-ResNets-PyTorch/blob/master/models/resnet.py" target="_blank" rel="nofollow noopener">github.com</a>
  </header>
  <article class="onebox-body">
    <h4><a href="https://github.com/kenshohara/3D-ResNets-PyTorch/blob/master/models/resnet.py" target="_blank" rel="nofollow noopener">kenshohara/3D-ResNets-PyTorch/blob/master/models/resnet.py</a></h4>
<pre><code class="lang-py">import math
from functools import partial

import torch
import torch.nn as nn
import torch.nn.functional as F


def get_inplanes():
    return [64, 128, 256, 512]


def conv3x3x3(in_planes, out_planes, stride=1):
    return nn.Conv3d(in_planes,
                     out_planes,
                     kernel_size=3,
                     stride=stride,
                     padding=1,
                     bias=False)

</code></pre>

  This file has been truncated. <a href="https://github.com/kenshohara/3D-ResNets-PyTorch/blob/master/models/resnet.py" target="_blank" rel="nofollow noopener">show original</a>

  </article>
  <div class="onebox-metadata">
    
    
  </div>
  <div style="clear: both"></div>
</aside>

<p>Yet I want to use the largest image I can fit in 8 - GB of GPU RAM (Nvidia RTX 2080).</p>
<p>it there a quick way to figure out this rather than just trying? I have tried images of size 64<em>64</em>64 and it worked. yet I just need to know what is the largest size I can do</p>
<p>thank you</p>

username: Naif40
cooked: <p><a class="mention" href="/u/ptrblck">@ptrblck</a> any idea peter? Thanks in Advanced</p>

username: ptrblck
cooked: <p>I don’t think there is a reliable way to estimate the memory usage properly.<br>
Especially, if you are using cudnn in the benchmark mode (via <code>torch.backends.cudnn.benchmark = True</code>), as cudnn will profile various algorithms for your use case and will select the fastest, which fits into your device. E.g. a faster algorithm might be picked, if you have enough memory left, and will be skipped, if not enough memory is available.<br>
This could mean that the memory usage won’t scale with the increase in input size as expected.</p>
<p>Of course you could try to calculate a theoretical memory usage, but I would just run some tests using different shapes to get the estimated memory usage.</p>

username: BTNug
cooked: <p>Hi <a class="mention" href="/u/naif40">@Naif40</a>, as explained by <a class="mention" href="/u/ptrblck">@ptrblck</a>, you could use <strong><a href="https://pypi.org/project/torch-summary/" rel="nofollow noopener">torchsummary</a></strong> for example, which will give you some estimate of gpu usage in MB.</p>
<p>Hence, you could multiply from your current image size (CMIIW, maybe what you mean is 64x64 or 3x64x64 with format <em>Channel x Height x Width</em>):</p>
<ul>
<li>i.e. 3x 64 x 64, let’s say the output of torchsummary is 1000mb</li>
<li>to know your limit is: 8000 / 1000 =  8. It could be used to increase your image size into: 3x181x181 (sqrt of 8 is ~2.82).</li>
</ul>
<p>But again, this is an estimation, and Pytorch should prevent you to use 100% of your gpu resources due to GUI utilization or other processes etc.<br>
So, use it with keeping those things in mind. Hope it helps, cheers~</p>