cezannec / capsule_net_pytorch

Readable implementation of a Capsule Network as described in "Dynamic Routing Between Capsules" [Hinton et. al.]
MIT License
370 stars 130 forks source link

There may be wrong for computing the softmax of digCaps #1

Closed CoderHHX closed 5 years ago

CoderHHX commented 5 years ago

Thank you for your contribution. I find in the code that >c_ij` = helpers.softmax(b_ij, dim=2) which computs the softmax of PrimaryCaps, however, in original paper, the c_ij is the softmax of DigCaps. and I think that softmax logits [10, Batchsize, 1152, 1, 16] should apply to dim 0. probs = softmax ( logits, dim=0 ) as the original paper presents.

cezannec commented 5 years ago

Hi! So, you're basically right, c_ij are the coupling coefficients or the weights between the connections of the PrimaryCaps layer and DigitCaps layer. It may help to look at the softmax function that I am implementing in the helpers.py file in this repo, where you can see that the dim (2) I am referring to is for transpose purposes. In that file, I am taking advantage of how these connections are structured to calculate a softmax over the connections between each of the primary capsules their ten possible parent capsules.