Failing to pass a simple tensor into a simple deep nn

I’m failing to pass a simple tensor into a simple deep nn.

What am I doing wrong?

ERROR MESSAGE:

“RuntimeError: mat1 and mat2 shapes cannot be multiplied (1x2 and 1x128)”

import numpy as np

import torch as t

import torch.nn as nn

import torch.nn.functional as F

import torch.optim as optim

class DNN(nn.Module):

def __init__ (self,input=1,h1=128,output=1):

    super().__init__()

    self.input = input

    self.h1 = h1

    self.output = output

    self.fc1 = nn.Linear(input,h1)

    self.fc2 = nn.Linear(h1,output)

def forward(self,kiwi):

    out = F.relu(self.fc1(kiwi))

    out = self.fc2(out)

    return out

dnn = DNN()

data = t.tensor([1,2])

dnn.forward(data)

Try sending a 1x1 tensor instead of 1x2

data = t.tensor([1]) instead of t.tensor([1, 2])

i did it but another error has emerged:

“RuntimeError: expected scalar type Long but found Float”

@Eric_Cartman

This appears to be a issue with data types.
Try sending t.tensor([1.0])

Usually to test a network, I send random data using t.randn(shape)
In this case, shape = (1, )

I did this modifications and everything went fine:

input = 2

data = t.tensor([1,2],dtype = t.float)

Thanks for your attention, @torch_bearer !!!