The error message you get is also given when you pass something not channel x height x width. So eg if you have gray as h x w you need to use .unsqueeze(0) or so to add the channel axis.
Best regards
Thomas