Adjust input shape for my pytorch problem
I am trying to create a neural net to feed in an input of shape 249561, 80, 1 and y labels are (249561, 2). 

def __init__(self):
    super(Net1, self).__init__()
    self.conv1 = nn.Conv1d(80, 16, kernel_size=1)

    self.conv2_drop = nn.Dropout()
    self.fc1 = nn.Linear(1,256)
    self.fc2 = nn.Linear(256, 64)
    self.fc3 = nn.Linear(64,32)
    self.fc4 = nn.Linear(32,2)

def forward(self, x):
    print(type(x))
    x = F.relu(F.max_pool1d(self.conv1(x), 1))
    print(x.shape)
    x.reshape(-1)
    e1 = F.relu(self.fc1(x))
    x = F.dropout(e1, training=self.training)
    x = F.relu(self.fc2(x))
    x = F.dropout(x, training=self.training)
    x = F.relu(self.fc3(x))
    x = F.dropout(x, training=self.training)
    x = self.fc4(x)

    return x


My training loop looks something like this

losses = [];
batch_size = 16
for epoch in range(10):
      permutation = torch.randperm(x2.size()[0])
      for i in range(0,len(x2), batch_size):
        indices = permutation[i:i+batch_size]
        batch_x, batch_y = x2[indices], onehot_encoded[indices]
        #images = Variable(images.float())
        #labels = Variable(labels)

        # Forward + Backward + Optimize
        optimizer.zero_grad()
        outputs = model(batch_x)
        loss = criterion(outputs, batch_y)
        loss.backward()
        optimizer.step()


I have a batch of 16 and I feed in a tensor with a shape [16, 80, 1].I get the following error. RuntimeError: Expected object of scalar type Long but got scalar type Float for argument #2 'target' in call to _thnn_nll_loss2d_forward. I suspect that it is the problem with an output layer but it returns a tensor of shape 2 which is the same as my labels. The output x size torch.Size([16, 16, 2])

Instead of changing the input, why don't you use nn.Conv1d (replace both nn.Conv2d -- you'll need to change the dropout as well)?

If you really wanna change the input, you can add:

batch_x = batch_x[..., None]


After

batch_x, batch_y = x2[indices], onehot_encoded[indices]

