This error is raised in the criterion when the model output shapes do not match the expected target shape.
Based on the error message I assume that a reshaping operation in the model might be wrong and the model output shape is thus also wrong.