bn + fc
| 648 | |
| 649 | |
| 650 | class BNClassifier(nn.Module): |
| 651 | '''bn + fc''' |
| 652 | |
| 653 | def __init__(self, in_dim, class_num): |
| 654 | super(BNClassifier, self).__init__() |
| 655 | |
| 656 | self.in_dim = in_dim |
| 657 | self.class_num = class_num |
| 658 | |
| 659 | self.bn = nn.BatchNorm1d(self.in_dim) |
| 660 | self.bn.bias.requires_grad_(False) |
| 661 | self.classifier = nn.Linear(self.in_dim, self.class_num, bias=False) |
| 662 | |
| 663 | self.bn.apply(weights_init_kaiming) |
| 664 | self.classifier.apply(weights_init_classifier) |
| 665 | |
| 666 | def forward(self, x): |
| 667 | feature = self.bn(x) |
| 668 | if not self.training: |
| 669 | return feature |
| 670 | else: |
| 671 | cls_score = self.classifier(feature) |
| 672 | return cls_score |
| 673 | |
| 674 | class Attribute_Classifier5(nn.Module): |
| 675 | def __init__(self, dict_attribute, in_dim, projected_dim, norm_type='bn', use_independent_projection=True): |