OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

torchvision models produce different outputs in eval mode when the batch size is different

  • Thread starter Thread starter Jake
  • Start date Start date
J

Jake

Guest
With torchvision models, I found that different batch sizes produce slightly different outputs, even in eval mode.

At the first time, I found with example of torchvision.models.efficientnet_v2_s.
And also tried more light model torchvision.models.vgg11. (And the difference is even more pronounced with efficientnet_v2_s model)

here is the code

Code:
model = torchvision.models.vgg11(weights = None).cuda()
model.eval()
model = model.features

inputs = torch.rand([128, 3, 128, 128]).cuda()

# small batch size
out1 = model(inputs[:2])

# largs batch size
out2 = model(inputs)[:2]

Can someone let me know the reason?

resnet : code output

efficientnet : enter image description here
<p>With torchvision models, I found that different batch sizes produce slightly different outputs, even in eval mode.</p>
<p>At the first time, I found with example of <code>torchvision.models.efficientnet_v2_s</code>.<br />
And also tried more light model <code>torchvision.models.vgg11</code>.
(And the difference is even more pronounced with efficientnet_v2_s model)</p>
<p>here is the code</p>
<pre><code>
model = torchvision.models.vgg11(weights = None).cuda()
model.eval()
model = model.features

inputs = torch.rand([128, 3, 128, 128]).cuda()

# small batch size
out1 = model(inputs[:2])

# largs batch size
out2 = model(inputs)[:2]


</code></pre>
<p>Can someone let me know the reason?</p>
<p>resnet :
<a href="https://i.sstatic.net/7lzUgPeK.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/7lzUgPeK.png" alt="code output" /></a></p>
<p>efficientnet :
<a href="https://i.sstatic.net/DdGlAQs4.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/DdGlAQs4.png" alt="enter image description here" /></a></p>
 

Latest posts

I
Replies
0
Views
1
impact christian
I
Top