ValueError: Expected input batch_size (491520) to match target batch_size (1)

I try to do brain tumor segmentation for BRATS. Sadly i got this error, The problem seems to be here : loss = functional.nll_loss(y, y_hat)

when i try to implement another loss function such as nn.BCELoss, it doesnt recognize the nn and new fuction, the rest of the code:

def train(i_epoch = 0):
model.train()

iteration = len(train_loader) * i_epoch

for x, y_hat in train_loader:

    optimizer.zero_grad()

    y = model(x)
    y = torch.argmax(y)
    loss = functional.nll_loss(y, y_hat)  # crossentropy loss. If one class is too imbalanced,
                                          # we can use the weights argument!
    loss.backward()

    optimizer.step()

    iteration += 1

    if (iteration % 100 == 0):
        writer.add_scalar("loss", loss.data.item(), iteration)

        # img = 
        # writer.add_image("trainimg", y)

# validation:
loss_val = 0
model.eval()
for x, y_hat in val_loader:

    y = model(x)

    # if (loss_val == 0):
    #     writer.add_image("val image", toTensor(img), iteration)


    loss_val += functional.nll_loss(y, y_hat)  # crossentropy loss. If one class is too imbalanced,
                                          # we can use the weights argument!


writer.add_scalar("val", loss_val.data.item(), iteration)

print("Validation loss: {:10}".format(loss_val))

it says : AttributeError: module ‘torch.nn.functional’ has no attribute ‘BCELoss’ although i already satisfy :
pip install torch==1.2.0 torchvision==0.4.1 in the colab…

BCELoss is in torch.nn: https://pytorch.org/docs/stable/nn.html#bceloss

If you want to use torch.nn.functional, it has binary_cross_entropy(): https://pytorch.org/docs/stable/nn.functional.html#binary-cross-entropy

now i get

Traceback (most recent call last):
File “train_bu.py”, line 255, in
train(i_epoch)
File “train_bu.py”, line 213, in train
loss = torch.nn.BCELoss(y, y_hat) # crossentropy loss. If one class is too imbalanced,
File “/usr/local/lib/python3.6/dist-packages/torch/nn/modules/loss.py”, line 495, in init
super(BCELoss, self).init(weight, size_average, reduce, reduction)
File “/usr/local/lib/python3.6/dist-packages/torch/nn/modules/loss.py”, line 19, in init
super(_WeightedLoss, self).init(size_average, reduce, reduction)
File “/usr/local/lib/python3.6/dist-packages/torch/nn/modules/loss.py”, line 12, in init
self.reduction = _Reduction.legacy_get_string(size_average, reduce)
File “/usr/local/lib/python3.6/dist-packages/torch/nn/_reduction.py”, line 36, in legacy_get_string
if size_average and reduce:
RuntimeError: bool value of Tensor with more than one value is ambiguous