Hello,

I am new to Pytorch as well as ML. Can someone help to fix?

```
class ConvNet(nn.Module):
def __init__(self):
super(ConvNet, self).__init__()
self.conv1 = nn.Sequential(
nn.Conv1d(1, 32, kernel_size=2, stride=1),
nn.Dropout(0.5),
nn.ReLU())
self.conv2 = nn.Sequential(
nn.Conv1d(32,32, kernel_size=2, stride=1),
nn.Dropout(0.5),
nn.ReLU(),
nn.MaxPool1d(2,stride=3))
self.conv3 = nn.Sequential(
nn.Conv1d(32, 32, kernel_size=2, stride=1),
nn.Dropout(0.5),
nn.ReLU())
#fully connected layers
self.fc1 = nn.Linear(32*47,32)
#self.fc2 = nn.Linear(32,2)
self.fc2 = nn.Linear(32,1)
self.activation = nn.Softmax()
def forward(self, x):
# input x :
#expected conv1d input = minibatch_size * num_channel * width
batch_size=x.size(0)
y = self.conv1(x.view(batch_size,1,-1))
y = self.conv2(y)
y = self.conv3(y)
print(y.size())
batch_size= y.size(0)
y = y.flatten(start_dim=1)
print(y.size())
y = self.fc1(y.view(batch_size,1,-1))
y = self.fc2(y.view(batch_size,1,-1))
return y
```

```
import numpy as np
batch_size = 32
epochs = 3
min_valid_loss = np.inf
for e in range(epochs):
train_loss = 0.0
model.train() # Optional when not using Model Specific layer
for data, labels in train_loader:
# Transfer Data to GPU if available
if torch.cuda.is_available():
data, labels = data.cuda(), labels.cuda()
# Clear the gradients
optimizer.zero_grad()
# Forward Pass
target = model(data)
# Find the Loss
loss = criterion(target,labels)
# Calculate gradients
loss.backward()
# Update Weights
optimizer.step()
# Calculate Loss
train_loss += loss.item()
valid_loss = 0.0
model.eval() # Optional when not using Model Specific layer
for data, labels in validloader:
if torch.cuda.is_available():
data, labels = data.cuda(), labels.cuda()
target = model(data)
target = target.long()
loss = criterion(target,labels)
valid_loss = loss.item() * data.size(0)
```