The view operation which should flatten x is throwing this error, since the size of 16*5*5 is not matching your activation size.
In the tutorial the CIFAR10 dataset is used, which has a spatial resolution of 32x32.
Most likely your custom dataset has a different spatial size, such that the view is failing.
Based on the shape given in the error message, it looks like your activation should have the shape [batch_size=4, channels=16, height=37, width=37], which results in 87616 values.
Try to change the input size if your linear layer to 16*37*37 and the flattening to:
x = x.view(x.size(0), 16*37*37)