(self, vit_backbone_model, dict_attribute, grad_from_block=11)
| 880 | |
| 881 | class Meta_Attribute_Generator2(nn.Module): |
| 882 | def __init__(self, vit_backbone_model, dict_attribute, grad_from_block=11): |
| 883 | super().__init__() |
| 884 | backbone_feat_dim = vit_backbone_model.num_features |
| 885 | self.num_attribute_class = len(dict_attribute.keys()) |
| 886 | self.num_attribute_all = sum([len(v) for v in dict_attribute.values()]) |
| 887 | self.attribute_generator_list = nn.ModuleList() |
| 888 | |
| 889 | for key in dict_attribute.keys(): |
| 890 | _conv = attribute_subnet(backbone_feat_dim) |
| 891 | _classifier = nn.Linear(backbone_feat_dim, len(dict_attribute[key]) + 1) # 1 for no present |
| 892 | _softmax = nn.Softmax(dim=1) |
| 893 | self.attribute_generator_list.append(nn.Sequential(_conv, _classifier, _softmax)) |
| 894 | |
| 895 | del vit_backbone_model |
| 896 | torch.cuda.empty_cache() |
| 897 | self.apply(self._init_weights) |
| 898 | |
| 899 | def _init_weights(self, m): |
| 900 | if isinstance(m, nn.Linear): |
nothing calls this directly
no test coverage detected