randinoo:

weight [10, 8, 3, 3], but got 2-dimensional input of size [6451, 42] instead


It seems that you should reshape out before self.cnn2(out). A convolution layer needs 4D tensor, but the output of nn.Linear is 2D.