model.train()
for epoch in range(3):
running_loss = 0.0
for i,data in enumerate(train_loader,0):
inputs,labels,_ = data
inputs = inputs[:,None,:]
#labels = labels[:,None,:]
print(inputs.shape)
inputs = inputs.to(device=device)
labels = labels.to(device=device)
optimizer.zero_grad()
#print("Input: ", inputs.shape)
#print("Labels: ",labels.shape)
outputs = model(inputs)
#thresh_output = threshold(outputs,0.5)
loss = criterion(outputs,labels)
#dice_score = dice_loss(thresh_output,labels).item()
loss.backward()
optimizer.step()
#wandb.log({"Train_Loss":loss})
if(i%500 == 0):
scheduler.step()
running_loss += loss.item()
# if(i == 1000):
# break
print("Epoch : {}, iteration : {} and Loss : {}".format(epoch+1,i+1,loss.item()))
The code is given above. I get the following error when I try to run it:
torch.Size([1, 1, 256, 256]) /usr/local/lib/python3.7/dist-packages/torch/nn/functional.py:1944: UserWarning: nn.functional.sigmoid is deprecated. Use torch.sigmoid instead. warnings.warn("nn.functional.sigmoid is deprecated. Use torch.sigmoid instead.")
AttributeError Traceback (most recent call last) in () 16 outputs = model(inputs) 17 #thresh_output = threshold(outputs,0.5) ---> 18 loss = criterion(outputs,labels) 19 #dice_score = dice_loss(thresh_output,labels).item() 20 loss.backward()
2 frames /usr/local/lib/python3.7/dist-packages/torch/nn/functional.py in binary_cross_entropy(input, target, weight, size_average, reduce, reduction) 3053 else: 3054 reduction_enum = _Reduction.get_enum(reduction) -> 3055 if target.size() != input.size(): 3056 raise ValueError( 3057 "Using a target size ({}) that is different to the input size ({}) is deprecated. "
AttributeError: 'tuple' object has no attribute 'size'