Hello dear programmers,

I am very new to Pytorch with basic programming skills. My task consists of performing segmentation of seismic data. My training data consists of 9 channels and the labels are of one channel. I have managed to build up a network. However, it can not train and it shows the following error

“TypeError: conv2d(): argument ‘input’ (position 1) must be Tensor, not int”.

My codes are given below

Please, any help would be highly appreciated

```
old_data = np.load()
old_label = np.load()
data = np.zeros((old_data.shape[0],3,old_data.shape[2],old_data.shape[3]))
for i in range(old_data.shape[0]):
a = old_data[i]
a = np.resize(a, (3,old_data.shape[2],old_data.shape[3]))
data[i,:,:] = a
from torch.utils.data import TensorDataset
X = torch.from_numpy(np.array(data)).float()
Y = torch.from_numpy(np.array(old_label)).long()
print(X.size(),Y.size())
CT_dataset = TensorDataset(X,Y)
kwargs = {'num_workers': 4, 'pin_memory': True} if torch.cuda.is_available() else {}
train_loader = torch.utils.data.DataLoader(
CT_dataset,
batch_size=1, shuffle=True, **kwargs)
pretrained_net = models.resnet34(pretrained=False)
num_classes = 2 #len(classes)
class fcn(nn.Module):
def __init__(self, num_classes):
super(fcn, self).__init__()
self.stage1 = nn.Sequential(*list(pretrained_net.children())[:-4])
self.stage2 = list(pretrained_net.children())[-4]
self.stage3 = list(pretrained_net.children())[-3]
self.scores1 = nn.Conv2d(512, num_classes, 1)
self.scores2 = nn.Conv2d(256, num_classes, 1)
self.scores3 = nn.Conv2d(128, num_classes, 1)
self.upsample_8x = nn.ConvTranspose2d(num_classes, num_classes, 16, 8, 4, bias=False)
self.upsample_4x = nn.ConvTranspose2d(num_classes, num_classes, 4, 2, 1, bias=False)
self.upsample_2x = nn.ConvTranspose2d(num_classes, num_classes, 4, 2, 1, bias=False)
def forward(self, x):
x = self.stage1(x)
s1 = x # 1/8
x = self.stage2(x)
s2 = x # 1/16
x = self.stage3(x)
s3 = x # 1/32
s3 = self.scores1(s3)
s3 = self.upsample_2x(s3)
s2 = self.scores2(s2)
s2 = s2 + s3
s1 = self.scores3(s1)
s2 = self.upsample_4x(s2)
s = s1 + s2
s = self.upsample_8x(s2)
return s
model = fcn(num_classes)
criterion = nn.NLLLoss2d()
basic_optim = torch.optim.SGD(model.parameters(), lr=1e-2, weight_decay=1e-4)
optimizer = basic_optim
for e in range(50):
if e > 0 and e % 50 == 0:
optimizer.set_learning_rate(optimizer.learning_rate * 0.1)
train_loss = 0
model= model.train()
from tqdm import tqdm
for data in tqdm(enumerate(train_loader)):
optimizer.zero_grad()
x, y_true = data
if torch.cuda.is_available():
x, y_true = x.cuda(), y_true.cuda()
# forward
out = model(x)
out = F.log_softmax(out, dim=1) # (b, n, h, w)
loss = criterion(out, y_true )
# backward
optimizer.zero_grad()
loss.backward()
optimizer.step()
train_loss += loss.data[0]
label_pred = out.max(dim=1)[1].data.cpu().numpy()
label_true = y_true .data.cpu().numpy()
acc=get_accuracy(label_true,label_pred)
print(acc)
```