Search code examples
machine-learningtheano

Theano: expected 2, got 1 with shape (128,).')


Im trying to make a neural network. I have followed the video from

https://www.youtube.com/watch?v=S75EdAcXHKk

I have loaded the adult.data training set.

I am now on my way of training and i have these lines where the code fails.

while(epocs<5):
            i = 0
            for start, end in zip(range(0, len(trX), 128), range(128, len(trX), 128)):
                print(trX.shape)
                tr = trX[start:end]
                print(tr.shape[0])
                print(tr.shape[1])
                self.cost = train(tr.reshape(tr.shape[0],tr.shape[1]), trY[start:end])
            epocs+=1

I am strugling with an error message which is:

n.training()

File "C:\Users\Bjornars\PycharmProjects\cogs-118a\Project\NN\Network.py", line 101, in training self.cost = train(tr.reshape(128,106), trY[start:end]) File "C:\Anaconda3\lib\site-packages\theano\compile\function_module.py", line 513, in call allow_downcast=s.allow_downcast) File "C:\Anaconda3\lib\site-packages\theano\tensor\type.py", line 169, in filter data.shape)) TypeError: ('Bad input argument to theano function with name "C:\Users\Bjornars\PycharmProjects\cogs-118a\Project\NN\Network.py:84" at index 1(0-based)', 'Wrong number of dimensions: expected 2, got 1 with shape (128,).')

The shape of the array im sending in is (5000,106)

---Solved----


Solution

  • Used this, it expected array not number in trY

        def preprocess(self,trDmatrix,labels):
              for i in range(len(trDmatrix)):
                  numbers = [0.0]*2
                  numbers[int(labels[i])]= 1.0
                  labels[i] = numbers
              return trDmatrix, labels