capsule-networks
capsule-networks copied to clipboard
How should I set num_route_nodes?
According to my understanding, num_route_nodes should be the length of the vote vectors that are used as input to dynamic routing.
In the example code, this value is set according to:
self.primary_capsules = CapsuleLayer(num_capsules=8, num_route_nodes=-1, in_channels=256, out_channels=32,
kernel_size=9, stride=2)
self.digit_capsules = CapsuleLayer(num_capsules=NUM_CLASSES, num_route_nodes=32 * 6 * 6, in_channels=8,
out_channels=16)
32 appears to come from the previous out_channels, but I can't tell what 6 * 6 are doing. Is this arbitrary, or is it preventing some kind of dimension mismatch? If I am implementing my own capsule network with new dimensions, do I need to be careful about how I pick this value?
Thanks, Will
Hi, 6 * 6 comes from the following: input(MNIST) size is 28^2(capsule network was tried on MNIST). First convolution layer has 9 kernel size with stride 1, making its output ceil((28 - kernel_size + 1) / stride_size)^2 = 20^2. Primary capsule side has another convolution layer inside, but this time it has stride = 2. The same formula, gives: ceil((20 - kernel_size + 1) / stride_size)^2 = 6 * 6. I hope the rest is comprehendible.
According to my understanding,
num_route_nodesshould be the length of the vote vectors that are used as input to dynamic routing.In the example code, this value is set according to:
self.primary_capsules = CapsuleLayer(num_capsules=8, num_route_nodes=-1, in_channels=256, out_channels=32, kernel_size=9, stride=2) self.digit_capsules = CapsuleLayer(num_capsules=NUM_CLASSES, num_route_nodes=32 * 6 * 6, in_channels=8, out_channels=16)
32appears to come from the previousout_channels, but I can't tell what6 * 6are doing. Is this arbitrary, or is it preventing some kind of dimension mismatch? If I am implementing my own capsule network with new dimensions, do I need to be careful about how I pick this value?Thanks, Will
I think it's arbitrary.