def _forward_age_cls(self, feat):
'''
Input:
feat: CNN feature (ReLUed)
Output:
age_out: output age prediction (for evaluation)
age_fc: final fc layer output (for compute loss)
'''
#fc_out = self.age_cls(feat)
fc_out = self.age_cls(F.relu(feat))
if self.opts.cls_type == 'dex':
# Deep EXpectation
age_scale = np.arange(self.opts.min_age, self.opts.max_age + 1, 1.0)
age_scale = Variable(fc_out.data.new(age_scale)).unsqueeze(1)
age_out = torch.matmul(F.softmax(fc_out), age_scalei).view(-1)
elif self.opts.cls_type == 'oh':
# Ordinal Hyperplane
fc_out = F.sigmoid(fc_out)
age_out = fc_out.sum(dim = 1) + self.opts.min_age
elif self.opts.cls_type == 'reg':
# Regression
age_out = fc_out.view(-1)
age_out = age_out + self.opts.min_age
return age_out, fc_out
评论列表
文章目录