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

spatial_routing_matrix = utl.create_routing_map(child_space=1, k=1, s=1) ? #12

Closed
itxiud2015 opened this issue Feb 11, 2020 · 2 comments

Comments

@itxiud2015
Copy link

Hi Ashley,
In layers.py, 'def fc_caps( )' creat spatial_routing_matrix with 'spatial_routing_matrix = utl.create_routing_map(child_space=1, k=1, s=1)' , where child_space is 1, but i think it's not necessary to be 1 over this point, you know along the tensor shape alteration flow before (64, 7, 7, 8, *) ---> (64, 5, 5, 16, *) , the child_space should be 5 instead of 1.
And with child_space=1, the newly generated spatial_routing_matrix has shape (1,1), that will make the 'em_routing()' thereafter incorrect.
How do you think about that? maybe my reasoning is wrong somewhere?

Kindly regards
Jeff

@ashleygritzman
Copy link
Contributor

Hi Jeff,

Thanks for your question.

The spatial_routing_map is used to determine which child capsules vote for which parent capsules. The layer fc_caps() refers to a fully connected capsule layer, which means that all the child capsules feed to the parent capsules. We achieve this by flattening the child capsules along their spatial dimension, so considering an example with a batch size of 1, we would go from (1, 7, 7, 8, ?) to (1, 778, ?) [batch_size, child_space * child_space * child_caps, ?]. In other words, we now have one long vector of capsules, instead of a cube of capsules. So for this reason it is correct to have a spatial_routing_matrix of (1,1), which effectively means that no spatial routing occurs in this layer.

You can contract this to the convolutional capsule layer conv_caps(), where we do have spatial routing of capsules.

Hope this helps :-)

So

@itxiud2015
Copy link
Author

itxiud2015 commented Feb 26, 2020

Hi Ashley,

Thanks for your clearly explanation :)

I tried 'spatial_routing_matrix = utl.create_routing_map(child_space=5, k=5, s=1)', this result in a 'spatial_routing_matrix' of shape [25, 1]. It function well and the test accuracy is slightly more than 90% after 65 epoch training, which is comparable with that of setting utl.create_routing_map(child_space=1, k=1, s=1) at my workstation.

Best regards
Jeff

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

2 participants