The error points to the shape mismatch in the model output and the target.
Based on your model output shape I assume you are working on a multi-label classification, where each sample can belong to zero, one, or multiple classes (2 in your case based on the shape).
If that’s the case, you would have to make sure that the target has also the same shape.
However, if you are working on a multi-class classification, where each sample belongs to a single class only, you would use e.g. nn.CrossEntropyLoss as the criterion. For this make sure to remove any activation function applied on the output of the model and pass the raw logits to the criterion.