Woodman718 / FixCaps

FixCaps: An Improved Capsules Network for Diagnosis of Skin Cancer,DOI: 10.1109/ACCESS.2022.3181225
MIT License
29 stars 8 forks source link

Question about dynamic routing with BatchSize > 1 for HAM10000 FixCaps model #2

Open udiboy1209 opened 1 year ago

udiboy1209 commented 1 year ago

Hello! I am replicating your model for the HAM10000 for a course project. I had a question about the dynamic routing implementation inside your Digit Caps module.

In model.py line 120, you initialize the b_ij routing logits to have shape (1, features, num_units, 1). Here the routing logits have a batch dimension of 1, implying that one set of routing logits are shared across the entire batch. Similarly, on line 142 you have taken a mean of u_vj1 across dimension 0 (batch dimension).

It is my understanding that these routing logits should be different for each image in the batch. So the dimension of b_ij should actually be (batch, features, num_units, 1). Also you should not perform the mean(dim=0) on u_vj1. This averaging is a problem for me because, when I try to run the test dataset with batchsize 1 (T_size = 1), the accuracy drops to ~30%. This is generally not expected at testing time, because ideally each image's inference should be independent.

Question: I was wondering if you could tell me some details about why you have opted to average the dynamic routing logits across the batch?

Note that we did not face issue in recreating your accuracy with the correct batch size settings, based on the FixCaps_HAM-29.ipynb and your comments in issue #1 .

Thank you for the well commented code and detailed explanation of running your notebooks!

Woodman718 commented 1 year ago

Thank you for your attention to my work and for pointing out the error in the comment section related to b_ij. The primary focus of our work lies in the design of weight sharing (mean on u_vj1). However, the current version has some limitations. For the most up-to-date version, please refer to the latest release posted on our GitHub (https://github.com/Woodman718/CapsNets).