Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

About add the feature variances #11

Open
yuyijie1995 opened this issue Mar 21, 2019 · 1 comment
Open

About add the feature variances #11

yuyijie1995 opened this issue Mar 21, 2019 · 1 comment

Comments

@yuyijie1995
Copy link

I am trying to add the learnable feature variances in the python code,but I found that the acc will decreased a lot.
The add strategy as below:
1.I reshape the var,mean as the (1,num_classes,feature_dim),reshape the input_feature as (batchsize,1,feature_dim)
2. using the input_feature subtract the mean and divise the var get a tensor with shape ((batchsize,num_classes,feature_dim)).
3.using the tensor batch_dot the mean and get the tensor with shape (batchsize,num_classes,num_classes)
4.Then I take the value of the diagonal of the two or three dimensions and get the final tensor as the margin_distance.
BUT the acc result is terrible,can you give me some advice?

@yuyijie1995
Copy link
Author

This is my code:
reshape_var=F.reshape(var,(1,-1,self._feature_dim))
reshape_mean=F.reshape(mean,(1,-1,self._feature_dim))
expand_data=F.expand_dims(x,1)
t=expand_data-reshape_mean#(8,10,2)
m_distance=F.batch_dot(t/(reshape_var+1e-8),t,transpose_b=True)
index=F.array([i for i in range(self._num_class)])
distance=m_distance[:,index,index]
ALPHA = F.one_hot(y, self._num_class, on_value=self._alpha, dtype='float32')
K = ALPHA + F.ones((N, self._num_class), dtype='float32')
logits_with_margin = distance * K
batch_mean = F.take(mean, y)
likelihood_reg_loss = self._lamda * (F.sum(F.square(x - batch_mean)) / 2.0) * (1. / N)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant