Applies network layers and ops on input image(s) x. Args: x: input image or batch of images. Shape: [batch,3,300,300]. Return: Depending on phase: test: Variable(tensor) of output class label predictions, confidenc
(self, x)
| 48 | self.detect = Detect(num_classes, 0, 200, 0.01, 0.45) |
| 49 | |
| 50 | def forward(self, x): |
| 51 | """Applies network layers and ops on input image(s) x. |
| 52 | |
| 53 | Args: |
| 54 | x: input image or batch of images. Shape: [batch,3,300,300]. |
| 55 | |
| 56 | Return: |
| 57 | Depending on phase: |
| 58 | test: |
| 59 | Variable(tensor) of output class label predictions, |
| 60 | confidence score, and corresponding location predictions for |
| 61 | each object detected. Shape: [batch,topk,7] |
| 62 | |
| 63 | train: |
| 64 | list of concat outputs from: |
| 65 | 1: confidence layers, Shape: [batch*num_priors,num_classes] |
| 66 | 2: localization layers, Shape: [batch,num_priors*4] |
| 67 | 3: priorbox layers, Shape: [2,num_priors*4] |
| 68 | """ |
| 69 | sources = list() |
| 70 | loc = list() |
| 71 | conf = list() |
| 72 | |
| 73 | # apply vgg up to conv4_3 relu |
| 74 | for k in range(23): |
| 75 | x = self.vgg[k](x) |
| 76 | |
| 77 | s = self.L2Norm(x) |
| 78 | sources.append(s) |
| 79 | |
| 80 | # apply vgg up to fc7 |
| 81 | for k in range(23, len(self.vgg)): |
| 82 | x = self.vgg[k](x) |
| 83 | sources.append(x) |
| 84 | |
| 85 | # apply extra layers and cache source layer outputs |
| 86 | for k, v in enumerate(self.extras): |
| 87 | x = F.relu(v(x), inplace=True) |
| 88 | if k % 2 == 1: |
| 89 | sources.append(x) |
| 90 | |
| 91 | # apply multibox head to source layers |
| 92 | for (x, l, c) in zip(sources, self.loc, self.conf): |
| 93 | loc.append(l(x).permute(0, 2, 3, 1).contiguous()) |
| 94 | conf.append(c(x).permute(0, 2, 3, 1).contiguous()) |
| 95 | |
| 96 | loc = torch.cat([o.view(o.size(0), -1) for o in loc], 1) |
| 97 | conf = torch.cat([o.view(o.size(0), -1) for o in conf], 1) |
| 98 | if self.phase == "test": |
| 99 | output = self.detect( |
| 100 | loc.view(loc.size(0), -1, 4), # loc preds |
| 101 | self.softmax(conf.view(conf.size(0), -1, |
| 102 | self.num_classes)), # conf preds |
| 103 | self.priors.type(type(x.data)) # default boxes |
| 104 | ) |
| 105 | else: |
| 106 | output = ( |
| 107 | loc.view(loc.size(0), -1, 4), |