The output shape doesn’t match the target shape for the provided output.
nn.NLLLoss expects a model output in the shape [batch_size, nb_classes, *] and a target in the shape [batch_size, *] containing class indices in the range [0, nb_classes-1].
Since you are using ImageFolder I would assume you are working on a multi-class classification use case.
In that case the model output should have the shape [batch_size, nb_classes] and the target [batch_size] (note the missing additonal dimensions).
Remove the .unsqueeze operation performed on y and make sure the model output matches the expected shape.