MCPcopy Create free account
hub / github.com/TPCD/DCCL / BNClassifier

Class BNClassifier

model/vision_transformer.py:650–672  ·  view source on GitHub ↗

bn + fc

Source from the content-addressed store, hash-verified

648
649
650class 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
674class Attribute_Classifier5(nn.Module):
675 def __init__(self, dict_attribute, in_dim, projected_dim, norm_type='bn', use_independent_projection=True):

Callers 1

__init__Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected