MCPcopy Create free account
hub / github.com/Sin3DM/Sin3DM / InceptionV3

Class InceptionV3

evaluation/inception.py:6–147  ·  view source on GitHub ↗

Pretrained InceptionV3 network returning feature maps

Source from the content-addressed store, hash-verified

4
5
6class InceptionV3(nn.Module):
7 """Pretrained InceptionV3 network returning feature maps"""
8
9 # Index of default block of inception to return,
10 # corresponds to output of final average pooling
11 DEFAULT_BLOCK_INDEX = 3
12
13 # Maps feature dimensionality to their output blocks indices
14 BLOCK_INDEX_BY_DIM = {
15 64: 0, # First max pooling features
16 192: 1, # Second max pooling featurs
17 768: 2, # Pre-aux classifier features
18 2048: 3 # Final average pooling features
19 }
20
21 def __init__(self,
22 output_blocks=[DEFAULT_BLOCK_INDEX],
23 resize_input=False,
24 normalize_input=True,
25 requires_grad=False):
26 """Build pretrained InceptionV3
27
28 Parameters
29 ----------
30 output_blocks : list of int
31 Indices of blocks to return features of. Possible values are:
32 - 0: corresponds to output of first max pooling
33 - 1: corresponds to output of second max pooling
34 - 2: corresponds to output which is fed to aux classifier
35 - 3: corresponds to output of final average pooling
36 resize_input : bool
37 If true, bilinearly resizes input to width and height 299 before
38 feeding input to model. As the network without fully connected
39 layers is fully convolutional, it should be able to handle inputs
40 of arbitrary size, so resizing might not be strictly needed
41 normalize_input : bool
42 If true, scales the input from range (0, 1) to the range the
43 pretrained Inception network expects, namely (-1, 1)
44 requires_grad : bool
45 If true, parameters of the model require gradient. Possibly useful
46 for finetuning the network
47 """
48 super(InceptionV3, self).__init__()
49
50 self.resize_input = resize_input
51 self.normalize_input = normalize_input
52 self.output_blocks = sorted(output_blocks)
53 self.last_needed_block = max(output_blocks)
54
55 assert self.last_needed_block <= 3, \
56 'Last possible output block index is 3'
57
58 self.blocks = nn.ModuleList()
59
60 inception = models.inception_v3(weights=models.Inception_V3_Weights.IMAGENET1K_V1)
61
62 # Block 0: input to maxpool1
63 block0 = [

Calls

no outgoing calls

Tested by

no test coverage detected