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

Modifications needed for multi-label classification #88

Closed
shan18 opened this issue Jan 19, 2019 · 4 comments
Closed

Modifications needed for multi-label classification #88

shan18 opened this issue Jan 19, 2019 · 4 comments

Comments

@shan18
Copy link

shan18 commented Jan 19, 2019

If I want to apply this model to a multi-class multi-label classification, what changes would be required for me to make on the Mask() layer? Can you give me any hint?
Will there be any other changes that I would have to make?

Thank You.

@Ryanglambert
Copy link

Ryanglambert commented Jan 19, 2019 via email

@shan18
Copy link
Author

shan18 commented Jan 20, 2019

@Ryanglambert I was asking for a multi-label classifier, where each image can contain multiple objects, so for example, the output of an image can be [0, 1, 1, 0, 0, 0, 1]. In the Mask layer at line 56, instead of argmax, there should be a different operation which would select the probabilities to be either 1 or 0 based on a threshold. Please correct me if I am wrong.

def call(self, inputs, **kwargs):
if type(inputs) is list: # true label is provided with shape = [None, n_classes], i.e. one-hot code.
assert len(inputs) == 2
inputs, mask = inputs
else: # if no true label, mask by the max length of capsules. Mainly used for prediction
# compute lengths of capsules
x = K.sqrt(K.sum(K.square(inputs), -1))
# generate the mask which is a one-hot code.
# mask.shape=[None, n_classes]=[None, num_capsule]
mask = K.one_hot(indices=K.argmax(x, 1), num_classes=x.get_shape().as_list()[1])
# inputs.shape=[None, num_capsule, dim_capsule]
# mask.shape=[None, num_capsule]
# masked.shape=[None, num_capsule * dim_capsule]
masked = K.batch_flatten(inputs * K.expand_dims(mask, -1))
return masked

And when I ran the code as it is on my dataset, the accuracy was not improving, it wasn't going above 0.5. So I just wanted to know, is there any place else except the Mask layer where the changes have to be made for a multi-label classifier?

@XifengGuo
Copy link
Owner

@shan18
By default, during training, the mask is provided by y, so you needn't change the line#56.
If the accuracy does not improve, you can track the training loss to see a NaN?

@shan18
Copy link
Author

shan18 commented Mar 1, 2019

Okay, understood. Thank you for your help.

@shan18 shan18 closed this as completed Mar 1, 2019
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

3 participants