UMCUtrecht-ECGxAI / ecgxai

Neatly packaged AI methods for explainable ECG analysis
GNU Affero General Public License v3.0
47 stars 10 forks source link

Shape and padding inconsistency in VAE_System #5

Open MohamadAsadi78 opened 5 months ago

MohamadAsadi78 commented 5 months ago

Hi, thanks for your wonderful work! I was trying to run this model, specifically VAE, on my data and I noticed it doesn't work due to an inconsistency: In systems/VAE_system.py:124: reconstruction_mean, reconstruction_std = self.decoder(z) The above line uses CausalCNNVDecoder from ecgxai.network.causalcnn.decoder. In the above decoder we have: ecgxai.network.causalcnn.decoder:42: out = self.causal_cnn(out) Which uses CausalCNN block from .modules. In that file, specifically in lines 71 to 108, the causal CNN is defined the same for both encoder and decoder. More specifically, in ecgxai.network.causalcnn.modules.py:75: Conv1d = torch.nn.Conv1d if forward else torch.nn.ConvTranspose1d If forward is False, which is the case in the decoder, you are using ConvTranspose1d which reduces the length of the input by padding (in contrast to Conv1d which adds that amount to the length). However, the Chomp1d blocks are still kept intact which makes the input length to reach zero by repetitively subtracting the amount of padding from it. For instance, in case of my data (batch_size=256, ECG_length=5000), this is the shape of the input going through CausalCNN in Encoder: Input shape: torch.Size([256, 128, 5000]) After conv1: torch.Size([256, 64, 5512]) After chomp1: torch.Size([256, 64, 5000]) After relu1: torch.Size([256, 64, 5000]) After conv2: torch.Size([256, 64, 5512]) After chomp2: torch.Size([256, 64, 5000]) After relu2: torch.Size([256, 64, 5000])

However, the shape of the input going through CausalCNN in decoder is:

Input shape: torch.Size([256, 64, 600]) After conv1: torch.Size([256, 128, 88]) After chomp1: torch.Size([256, 128, 0]) After relu1: torch.Size([256, 128, 0]) Which causes an error when reaching conv2.

As far as I understood from the repository, there is no other type of CausalCNN defined for the Decoder or any other condition being set upon it to account for this bug. What Encoder/Decoder was then used to produce the results of the paper? Thanks and regards.

NahuelCostaCortez commented 1 month ago

@MohamadAsadi78 were you able to resolve this issue? I am encountering the same problem. It appears that something might be missing since the linear layers for the mean and variance in the decoder expect an output from the causal blocks with a shape of [B, 12, 600]. However, that dimension of 600 is never met. It would be helpful if the authors of the repository could shed some light on this.

Thank you in advance!