naturomics / CapsNet-Tensorflow

A Tensorflow implementation of CapsNet(Capsules Net) in paper Dynamic Routing Between Capsules
Apache License 2.0
3.8k stars 1.16k forks source link

Valid padding in CapNets #42

Open phongnhhn92 opened 6 years ago

phongnhhn92 commented 6 years ago

Hello sir, I am following the Capsule Network paper and your implementation. I have a quick question about the valid padding in the conv2 you used to get output for the Primary Caps. So as I understand, after the 1st conv layer, the size of output is (batchsize,20,20,256). So if the conv2 has 256, 9x9 kernel, stride 2 then the formula output should be (20-9+2*p)/2+1 = 6. However, mathematically, the formula above can not be solved so I would like to ask how did exactly padding (valid) works in this situation to have the output is (batchsize,6,6,256). Thanks !

TarrySingh commented 6 years ago

Hi — could you respond to the CapsLayer repo as we’ll be developing the library there :)

phongnhhn92 commented 6 years ago

U mean I should post this question in that repo ?

toddlt commented 6 years ago

@phongnhhn92 I think that input of conv1 layer is MNIST image, its size is 28*28, so the output is (28-9+0*2)/1+1=20, and there are 256 neurons, so output of conv1 is (batchsize,20,20,256). The conv2 layer you said is PrimaryCaps? The vec_len of capsule is 8, so there are 8 conv layers stacked in PrimaryCaps. The output here is (20-9+2*p)/2+1=6, there are 32 neurons, each neuron calculates 8 conv, concat them will get (batchsize,6,6,32*8)