mirror of
https://github.com/huggingface/pytorch-image-models.git
synced 2025-06-03 15:01:08 +08:00
Stricter check on pool_type for adaptive pooling module. Fix #2159
This commit is contained in:
parent
d6da4fb01e
commit
301d0bb21f
@ -134,6 +134,7 @@ class SelectAdaptivePool2d(nn.Module):
|
|||||||
super(SelectAdaptivePool2d, self).__init__()
|
super(SelectAdaptivePool2d, self).__init__()
|
||||||
assert input_fmt in ('NCHW', 'NHWC')
|
assert input_fmt in ('NCHW', 'NHWC')
|
||||||
self.pool_type = pool_type or '' # convert other falsy values to empty string for consistent TS typing
|
self.pool_type = pool_type or '' # convert other falsy values to empty string for consistent TS typing
|
||||||
|
pool_type = pool_type.lower()
|
||||||
if not pool_type:
|
if not pool_type:
|
||||||
self.pool = nn.Identity() # pass through
|
self.pool = nn.Identity() # pass through
|
||||||
self.flatten = nn.Flatten(1) if flatten else nn.Identity()
|
self.flatten = nn.Flatten(1) if flatten else nn.Identity()
|
||||||
@ -145,8 +146,10 @@ class SelectAdaptivePool2d(nn.Module):
|
|||||||
self.pool = FastAdaptiveAvgMaxPool(flatten, input_fmt=input_fmt)
|
self.pool = FastAdaptiveAvgMaxPool(flatten, input_fmt=input_fmt)
|
||||||
elif pool_type.endswith('max'):
|
elif pool_type.endswith('max'):
|
||||||
self.pool = FastAdaptiveMaxPool(flatten, input_fmt=input_fmt)
|
self.pool = FastAdaptiveMaxPool(flatten, input_fmt=input_fmt)
|
||||||
else:
|
elif pool_type == 'fast' or pool_type.endswith('avg'):
|
||||||
self.pool = FastAdaptiveAvgPool(flatten, input_fmt=input_fmt)
|
self.pool = FastAdaptiveAvgPool(flatten, input_fmt=input_fmt)
|
||||||
|
else:
|
||||||
|
assert False, 'Invalid pool type: %s' % pool_type
|
||||||
self.flatten = nn.Identity()
|
self.flatten = nn.Identity()
|
||||||
else:
|
else:
|
||||||
assert input_fmt == 'NCHW'
|
assert input_fmt == 'NCHW'
|
||||||
@ -156,8 +159,10 @@ class SelectAdaptivePool2d(nn.Module):
|
|||||||
self.pool = AdaptiveCatAvgMaxPool2d(output_size)
|
self.pool = AdaptiveCatAvgMaxPool2d(output_size)
|
||||||
elif pool_type == 'max':
|
elif pool_type == 'max':
|
||||||
self.pool = nn.AdaptiveMaxPool2d(output_size)
|
self.pool = nn.AdaptiveMaxPool2d(output_size)
|
||||||
else:
|
elif pool_type == 'avg':
|
||||||
self.pool = nn.AdaptiveAvgPool2d(output_size)
|
self.pool = nn.AdaptiveAvgPool2d(output_size)
|
||||||
|
else:
|
||||||
|
assert False, 'Invalid pool type: %s' % pool_type
|
||||||
self.flatten = nn.Flatten(1) if flatten else nn.Identity()
|
self.flatten = nn.Flatten(1) if flatten else nn.Identity()
|
||||||
|
|
||||||
def is_identity(self):
|
def is_identity(self):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user