RuntimeError: output with shape [1, 28, 28] doesn't match the broadcast shape [3, 28, 28]の対処法

pytorchでMNISTデータセットを用いる際に

RuntimeError: output with shape [1, 28, 28] doesn't match the broadcast shape [3, 28, 28]

というエラーが出るかもしれない。

これはデータセットの準備をする際のtransformの部分に原因がある。

transform = transforms.Compose([transforms.ToTensor(), transforms.Normalize*1])
 
このように書いてしまってはいないだろうか?
 
グレースケールの画像を扱う際は、
transform = transforms.Compose([transforms.ToTensor(), transforms.Normalize*2])
と書くのが正解だ。
 
 以下のサイトが参考になる。
 
 

*1:0.5,0.5,0.5),(0.5,0.5,0.5

*2:0.5,),(0.5,