Forward function. Args: mlvl_feats (tuple[Tensor]): Features from the upstream network, each is a 4D-tensor with shape (N, C, H, W). img_metas (list[dict]): List of image information. Returns: all_cls_scores (Tenso
(self, mlvl_feats, img_metas)
| 1267 | nn.init.constant_(m[-1].bias.data[2:], 0.0) |
| 1268 | |
| 1269 | def forward(self, mlvl_feats, img_metas): |
| 1270 | """Forward function. |
| 1271 | |
| 1272 | Args: |
| 1273 | mlvl_feats (tuple[Tensor]): Features from the upstream |
| 1274 | network, each is a 4D-tensor with shape |
| 1275 | (N, C, H, W). |
| 1276 | img_metas (list[dict]): List of image information. |
| 1277 | |
| 1278 | Returns: |
| 1279 | all_cls_scores (Tensor): Outputs from the classification head, \ |
| 1280 | shape [nb_dec, bs, num_query, cls_out_channels]. Note \ |
| 1281 | cls_out_channels should includes background. |
| 1282 | all_bbox_preds (Tensor): Sigmoid outputs from the regression \ |
| 1283 | head with normalized coordinate format (cx, cy, w, h). \ |
| 1284 | Shape [nb_dec, bs, num_query, 4]. |
| 1285 | enc_outputs_class (Tensor): The score of each point on encode \ |
| 1286 | feature map, has shape (N, h*w, num_class). Only when \ |
| 1287 | as_two_stage is True it would be returned, otherwise \ |
| 1288 | `None` would be returned. |
| 1289 | enc_outputs_coord (Tensor): The proposal generate from the \ |
| 1290 | encode feature map, has shape (N, h*w, 4). Only when \ |
| 1291 | as_two_stage is True it would be returned, otherwise \ |
| 1292 | `None` would be returned. |
| 1293 | """ |
| 1294 | |
| 1295 | batch_size = mlvl_feats[0].size(0) |
| 1296 | input_img_h, input_img_w = img_metas[0]['batch_input_shape'] |
| 1297 | img_masks = mlvl_feats[0].new_ones( |
| 1298 | (batch_size, input_img_h, input_img_w)) |
| 1299 | for img_id in range(batch_size): |
| 1300 | img_h, img_w = img_metas[img_id]['img_shape'] |
| 1301 | img_masks[img_id, :img_h, :img_w] = 0 |
| 1302 | |
| 1303 | mlvl_masks = [] |
| 1304 | mlvl_positional_encodings = [] |
| 1305 | for feat in mlvl_feats: |
| 1306 | mlvl_masks.append( |
| 1307 | F.interpolate(img_masks[None], |
| 1308 | size=feat.shape[-2:]).to(torch.bool).squeeze(0)) |
| 1309 | mlvl_positional_encodings.append( |
| 1310 | self.positional_encoding(mlvl_masks[-1])) |
| 1311 | |
| 1312 | query_embeds = None |
| 1313 | if not self.as_two_stage: |
| 1314 | query_embeds = self.query_embedding.weight |
| 1315 | hs, init_reference, inter_references, \ |
| 1316 | enc_outputs_class, enc_outputs_coord = self.transformer( |
| 1317 | mlvl_feats, |
| 1318 | mlvl_masks, |
| 1319 | query_embeds, |
| 1320 | mlvl_positional_encodings, |
| 1321 | reg_branches=self.reg_branches if self.with_box_refine else None, # noqa:E501 |
| 1322 | cls_branches=self.cls_branches if self.as_two_stage else None, # noqa:E501 |
| 1323 | smpl_branches=self.smpl_branches if self.with_box_refine else None # noqa: E501 |
| 1324 | ) |
| 1325 | hs = hs.permute(0, 2, 1, 3) |
| 1326 | outputs_classes = [] |
nothing calls this directly
no test coverage detected