def __init__(self, args, **kwargs): super(ArcMarginBlock, self).__init__(**kwargs) self.margin_s = args.margin_s self.margin_m = args.margin_m self.margin_a = args.margin_a self.margin_b = args.margin_b self.num_classes = args.num_classes self.emb_size = args.emb_size # self.weight = gluon.Parameter(name = 'fc7_weight', shape = (self.num_classes, self.emb_size)) # self.weight.initialize() # self._weight = nd.empty(shape = (self.num_classes, self.emb_size)) # if self.margin_a>0.0: with self.name_scope(): self.fc7_weight = self.params.get('fc7_weight', shape=(self.num_classes, self.emb_size)) # else: # self.dense = nn.Dense(self.num_classes, prefix='fc7') self.body = nn.HybridSequential(prefix='') feat = fresnet.get(args.num_layers, version_unit=args.version_unit, version_act=args.version_act) self.body.add(feat) self.body.add( EmbeddingBlock(args.emb_size, args.version_output, prefix=''))
def __init__(self, args, **kwargs): super(TestBlock, self).__init__(**kwargs) feat_with_bn = False use_dropout = True if args.num_classes >= 20000: use_dropout = False with self.name_scope(): self.feature_scale = None self.feat_net = nn.HybridSequential(prefix='') self.feat_net.add( fresnet.get(args.num_layers, args.emb_size, use_dropout)) if feat_with_bn: #self.feat_net.add(nn.BatchNorm(scale=True, epsilon=2e-5)) #self.bn1_gamma = self.params.get('bn1_gamma', shape=(1, args.emb_size)) #self.bn1_gamma.initialize(init=mx.init.Constant(1.0)) self.bn1_beta = self.params.get('bn1_beta', shape=(1, args.emb_size)) self.bn1_beta.initialize(init=mx.init.Constant(0.0)) #else: # self.bn1_beta = self.params.get('bn1_beta', shape=(1, args.emb_size)) # self.bn1_beta.initialize(init=mx.init.Constant(0.0)) #self.feat_net = fresnet.get(args.num_layers, args.emb_size, use_dropout) #initializer = mx.init.Xavier(rnd_type='gaussian', factor_type="out", magnitude=2) #resnet style #self.feat_net.initialize(init=initializer) self.feat_with_bn = feat_with_bn
def __init__(self, args, **kwargs): super(ArcMarginTestBlock, self).__init__(**kwargs) self.body = nn.HybridSequential(prefix='') feat = fresnet.get(args.num_layers, version_unit=args.version_unit, version_act=args.version_act) self.body.add(feat) self.body.add(EmbeddingBlock(args.emb_size, args.version_output))
def __init__(self, args, num_classes, **kwargs): super(_GABlock, self).__init__(**kwargs) with self.name_scope(): self.body = nn.HybridSequential(prefix='') feat = fresnet.get(args.num_layers, version_unit=args.version_unit, version_act=args.version_act) self.body.add(feat) self.body.add(EmbeddingBlock(mode=args.version_output)) self.body.add(nn.Dense(num_classes))
def __init__(self, args, **kwargs): super(DenseBlock, self).__init__(**kwargs) self.num_classes = args.num_classes self.emb_size = args.emb_size self.body = nn.HybridSequential(prefix='') feat = fresnet.get(args.num_layers, version_unit=args.version_unit, version_act=args.version_act) self.body.add(feat) self.body.add(EmbeddingBlock(args.emb_size, args.version_output, prefix='')) self.dense = nn.Dense(self.num_classes, prefix='fc7')
def __init__(self, args, is_train, **kwargs): super(FeatBlock, self).__init__(**kwargs) with self.name_scope(): self.feat_net = nn.HybridSequential(prefix='') self.feat_net.add( fresnet.get(args.num_layers, args.emb_size, args.use_dropout)) self.is_train = is_train if is_train: initializer = mx.init.Xavier(rnd_type='gaussian', factor_type="out", magnitude=2) #resnet style self.feat_net.initialize(init=initializer)