Skip to content

Commit 3fc49a5

Browse files
authored
Merge pull request #122 from ekagra-ranjan/patch-1
Updated inceptionV4 to accept different sized images
2 parents 5012820 + e07fb68 commit 3fc49a5

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

pretrainedmodels/models/inceptionv4.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from __future__ import print_function, division, absolute_import
22
import torch
33
import torch.nn as nn
4+
import torch.nn.functional as F
45
import torch.utils.model_zoo as model_zoo
56
import os
67
import sys
@@ -294,11 +295,12 @@ def __init__(self, num_classes=1001):
294295
Inception_C(),
295296
Inception_C()
296297
)
297-
self.avg_pool = nn.AvgPool2d(8, count_include_pad=False)
298298
self.last_linear = nn.Linear(1536, num_classes)
299299

300300
def logits(self, features):
301-
x = self.avg_pool(features)
301+
#Allows image of any size to be processed
302+
adaptiveAvgPoolWidth = features.shape[2]
303+
x = F.avg_pool2d(features, kernel_size=adaptiveAvgPoolWidth)
302304
x = x.view(x.size(0), -1)
303305
x = self.last_linear(x)
304306
return x
@@ -353,4 +355,4 @@ def inceptionv4(num_classes=1000, pretrained='imagenet'):
353355
print('success')
354356

355357
# fail
356-
assert inceptionv4(num_classes=1001, pretrained='imagenet')
358+
assert inceptionv4(num_classes=1001, pretrained='imagenet')

0 commit comments

Comments
 (0)