def forward(self, x, out_feat_keys=None): """Forward an image `x` through the network and return the asked output features. Args: x: input image. out_feat_keys: a list/tuple with the feature names of the features that the function should return. By default the last feature of the network is returned. Return: out_feats: If multiple output features were asked then `out_feats` is a list with the asked output features placed in the same order as in `out_feat_keys`. If a single output feature was asked then `out_feats` is that output feature (and not a list). """ out_feat_keys, max_out_feat = parse_out_keys_arg( out_feat_keys, self.all_feat_names) out_feats = [None] * len(out_feat_keys) feat = x for f in range(max_out_feat + 1): feat = self._feature_blocks[f](feat) key = self.all_feat_names[f] if key in out_feat_keys: out_feats[out_feat_keys.index(key)] = feat return out_feats
def forward(self, x, out_feat_keys=None): out_feat_keys, max_out_feat = parse_out_keys_arg( out_feat_keys, self.all_feat_names) out_feats = [None] * len(out_feat_keys) feat = x for f in range(max_out_feat + 1): feat = self._feature_blocks[f](feat) key = self.all_feat_names[f] if key in out_feat_keys: out_feats[out_feat_keys.index(key)] = feat return out_feats
def forward(self, x, out_feat_keys=None): """Forward an image `x` through the network and return the asked output features. Args: x: input image. out_feat_keys: a list/tuple with the feature names of the features that the function should return. By default the last feature of the network is returned. Return: out_feats: If multiple output features were asked then `out_feats` is a list with the asked output features placed in the same order as in `out_feat_keys`. If a single output feature was asked then `out_feats` is that output feature (and not a list). """ out_feat_keys, max_out_feat = parse_out_keys_arg( out_feat_keys, self.all_feat_names) # pool5, 12 out_feats = [[]] * len(out_feat_keys) x_size = x.size() if len(x_size) == 5: #unsupervise learning B, T, C, H, W = x_size x = x.transpose(0, 1) for i in range(T): feat = x[i] for f in range(max_out_feat + 1): feat = self._feature_blocks[f](feat) key = self.all_feat_names[f] if key in out_feat_keys: out_feats[out_feat_keys.index(key)].append(feat) for key in out_feat_keys: out_feats[out_feat_keys.index(key)] = torch.cat( out_feats[out_feat_keys.index(key)], 1) return out_feats else: feat = x for f in range(max_out_feat + 1): feat = self._feature_blocks[f](feat) key = self.all_feat_names[f] if key in out_feat_keys: out_feats[out_feat_keys.index(key)] = feat return out_feats
def forward(self, x, out_feat_keys=None): out_feat_keys, max_out_feat = parse_out_keys_arg( out_feat_keys, self.all_feat_names) out_feats = [[]] * len(out_feat_keys) x_size = x.size() if len(x_size) == 5: #unsupervise learning B, T, C, H, W = x_size x = x.transpose(0, 1) for i in range(T): feat = x[i] for f in range(max_out_feat + 1): feat = self._feature_blocks[f](feat) #print(feat.size()) key = self.all_feat_names[f] if key in out_feat_keys: out_feats[out_feat_keys.index(key)].append(feat) for key in out_feat_keys: out_feats[out_feat_keys.index(key)] = torch.cat( out_feats[out_feat_keys.index(key)], 1) print(out_feats[0].size()) return out_feats else: feat = x for f in range(max_out_feat + 1): feat = self._feature_blocks[f](feat) key = self.all_feat_names[f] if key in out_feat_keys: out_feats[out_feat_keys.index(key)] = feat return out_feats
def forward(self, x, out_feat_keys=None): """ Override forward function of standard AlexNet """ feat = x if cfg.MODEL.FEATURE_EVAL_MODE: # Evaluation of SSL features out_feat_keys, max_out_feat = parse_out_keys_arg( out_feat_keys, self.all_feat_names) out_feats = [None] * len(out_feat_keys) for f in range(max_out_feat + 1): feat = self._feature_blocks[f](feat) key = self.all_feat_names[f] if key in out_feat_keys: out_feats[out_feat_keys.index(key)] = feat return out_feats else: # Pretext Training: process each puzzle piece through model batch_dim, jigsaw_dim, _, _, _ = feat.size() feat = feat.transpose(0, 1) output = [] for i in range(9): jigsaw_piece = feat[i] for layer in self._feature_blocks: jigsaw_piece = layer(jigsaw_piece) jigsaw_piece = self.fc6(jigsaw_piece) output.append(jigsaw_piece) output = torch.cat(output, dim=1) return [output]