Hello Shell!



 Shell1500:

I have data in the form of:
tensor([[1.6886e-06, 4.2819e-06, 1.3871e-06,  ..., 1.4353e-05, 1.4173e-05,
         1.3931e-05],
...



I am guessing that this tensor is the X you input to your
network in net(X) and that is has shape [50, 50].


The image is a 50 by 50 gray scale
This is my Network Class:
class Net(nn.Module):
    def __init__(self):
        super().__init__()
        self.fc1 = nn.Linear(50*50, 64)
...

…
However i get the following error:
RuntimeError: size mismatch, m1: [1 x 50], m2: [2500 x 64]


The problem is that pytorch networks (models) always
work with batches of input samples (even if you don’t
want them to –  if you want to pass a single sample to a
network, you have to wrap it in a batch of batch-size 1).
So (according to my theory) pytorch is interpreting your
shape [50, 50] input tensor as a batch of 50 input samples,
where each sample has shape [50].  But your first Linear
layer is expecting an input of shape [2500], hence the
“size mismatch” error (50 != 2500).
You can print out X.shape (and y.shape, for that matter)
to see if this is what is going on.
(Note, Linear (50*50, 64) is exactly the same as
Linear (2500, 64).  The fact that you write the number
2500 as 50*50 does not somehow tell the layer to accept
an input of  shape [50, 50].)
You would first need to flatten() your input tensor X to
give it shape [2500], and then unsqueeze() it to turn in
into a batch (of batch-size 1 containing only one sample)
with shape [1, 2500].
Thus:
X = torch.unsqueeze (torch.flatten (X), dim = 0)
Good luck.
K. Frank