Hi, everyone. I am new to Pytorch. I’m trying to use a variational Autoencoder with simple data (a scalar as input). I’m using a batch size=6.
I’m reading the data from a csv file, taken from Kaggle. I’m using only one column as input.
Here is some of my code:
eq=pd.read_csv('/home/zayanir/Documents/data/database.csv')
latitude=eq['Latitude']
train_dl=torch.utils.data.DataLoader(latitude, batch_size=args.batch_size)

class VAE(nn.Module):
    def __init__(self):
        super(VAE, self).__init__()
        self.fc1=nn.Linear(1,3)
        self.fc2=nn.Linear(3,1)

    def encoder(self, x):
        moy=F.relu(self.fc1(x))
        variance=F.relu(self.fc1(x))
        return moy, variance
    
    def decoder(self, z):
        x=self.fc2(z)
        x=torch.sigmoid(x)
        return x
        
    def reparameterise(self, mu, var):
         std = torch.exp(0.5*var)
         eps = torch.randn_like(std) 
         return mu + eps*std
     
    def forward(self, x):
        mu,var=self.encoder(x)
        z=self.reparameterise(mu, var)
        x=self.decoder(z)
        return x, mu, var

The problem is that I get this error:
RuntimeError: size mismatch, m1: [1 x 6], m2: [1 x 3] at /opt/conda/conda-bld/pytorch_1525909934016/work/aten/src/TH/generic/THTensorMath.c:2033

I don’t understand why the model considers the input as a vector of 6 scalars when i’m using just a scalar as input with a batch_size=6.
Can you please help me?
Thank you very much.