Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

shapes are not aligned #1

Open
Louis-Fiacre opened this issue May 17, 2022 · 4 comments
Open

shapes are not aligned #1

Louis-Fiacre opened this issue May 17, 2022 · 4 comments

Comments

@Louis-Fiacre
Copy link

Hi, I use your work in a learning goal. When I create small network with few layers everything works perfectly. But when i try this kind of network :
`reseau = Network()

reseau.add(FCLayer(8*8,100))
reseau.add(ActivationLayer(tanh, tanh_prime))
reseau.add(FCLayer(100,80))
reseau.add(ActivationLayer(tanh, tanh_prime))
reseau.add(FCLayer(80,60))
reseau.add(ActivationLayer(tanh, tanh_prime))
reseau.add(FCLayer(60,10))
reseau.add(ActivationLayer(tanh, tanh_prime))`

I have this issue when i use fit method :
`---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
/tmp/ipykernel_367850/57939880.py in
1 reseau.use(mse, mse_prime)
----> 2 reseau.fit(learning_rate=0.0001, epochs=300, data_train=x_train, data_val=y_train)
3 reseau.show_fit()

~/Bureau/maths_python/14 avril/network.py in fit(self, learning_rate, epochs, data_train, data_val)
44
45 for layer in reversed(self.layers):
---> 46 error = layer.backward_propagation(error, learning_rate)
47
48 err /= iterations

~/Bureau/maths_python/14 avril/layer.py in backward_propagation(self, output_error, learning_rate)
49 def backward_propagation(self, output_error, learning_rate):
50 input_error = np.dot(output_error, self.weights.T)
---> 51 weights_error = np.dot(self.input.T, output_error)
52 # dBias = output_error
53

<array_function internals> in dot(*args, **kwargs)

ValueError: shapes (64,) and (1,100) not aligned: 64 (dim 0) != 1 (dim 0)`

When trying to debug it, I saw output_error changing type from ndarray to float64 but i really don't understand why.
Could you help me ? Thank in advance

@omaraflak
Copy link
Owner

You need to reshape your input as (64,1) before passing it in to the network. (64,) is considered different from (64,1).

@Louis-Fiacre
Copy link
Author

Of course, thank a lot, i was trying to change it inside de network but not in the shape of my data... Another question, i have the same issue with the forward_propagation
`~/Bureau/maths_python/14 avril/layer.py in forward_propagation(self, input_data)
43 def forward_propagation(self, input_data):
44 self.input = input_data
---> 45 self.output = np.dot(self.input, self.weights) + self.bias
46 return self.output
47

<array_function internals> in dot(*args, **kwargs)

ValueError: shapes (64,1) and (64,100) not aligned: 1 (dim 1) != 64 (dim 0)

`
I'm missing something, do i need to transpose (64,1) another time ?

@omaraflak
Copy link
Owner

Sorry I thought you were commenting on another repo. Actually you need a row matrix.

So your input should be of size (1, 64).

What you pass to the fit method as x_train should be an array of such objects. Meaning, of shape (n, 1, 64). Likewise y_train should be (n, 1, 10).

@Louis-Fiacre
Copy link
Author

Ok thank a lot. My data come from load_digits in sklearn_datasets, i will change ma dataset shape. I hope you will pass a good afternoon. Thank for your wonderful work :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants