XifengGuo / CapsNet-Pytorch

Pytorch implementation for NIPS2017 paper `Dynamic Routing Between Capsules`
MIT License
154 stars 36 forks source link

Construction of PrimaryCaps #2

Open manuelsh opened 6 years ago

manuelsh commented 6 years ago

I believe this line:

https://github.com/XifengGuo/CapsNet-Pytorch/blob/8a5a3572d91eb9479425168d3d565eb02e78be46/capsulelayers.py#L104

is not making the capsules in the right way. In theory if we do:

outputs = self.conv2d(x) outputs_2 = outputs.view(x.size(0), -1, self.dim_caps)

then outputs[0,0:8,0,0] should be equal to outputs_2[0,0,0:8]

and if you apply the view in that way this may not be guaranteed.

manuelsh commented 6 years ago

I believe you should permute the dimensions to be [batch_size, 6, 6, 256] before doing the view.

See for example the original implementation of the authors:

https://github.com/Sarasra/models/blob/984fbc754943c849c55a57923f4223099a1ff88c/research/capsules/models/capsule_model.py#L68

XifengGuo commented 6 years ago

@manuelsh Yes, you are totally right. Thanks.

manuelsh commented 6 years ago

What are your results if you do that? Our experience so far seems that with the correct view the results are actually worse. (!)

Btw, we are using cosine annealing as learning rate decay and works better than the exponential one.