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

some problems about Dense layer #13

Closed
CCV-Edward opened this issue Oct 9, 2016 · 4 comments
Closed

some problems about Dense layer #13

CCV-Edward opened this issue Oct 9, 2016 · 4 comments

Comments

@CCV-Edward
Copy link

When I ran 'MachineLearning-master/DeepLearning Tutorials/keras_usage/cnn.py', it occur these following problems. can you give me some advice?
`C:\Users\Edward\Anaconda2\python.exe "D:/project/Github/MachineLearning-master/DeepLearning Tutorials/keras_usage/cnn.py"
Using Theano backend.

42000 samples
Traceback (most recent call last):
File "D:/project/Github/MachineLearning-master/DeepLearning Tutorials/keras_usage/cnn.py", line 79, in
model.add(Dense(128, init='normal', input_dim=16_4_4))
File "C:\Users\Edward\Anaconda2\lib\site-packages\keras\models.py", line 308, in add
output_tensor = layer(self.outputs[0])
File "C:\Users\Edward\Anaconda2\lib\site-packages\keras\engine\topology.py", line 487, in call
self.build(input_shapes[0])
File "C:\Users\Edward\Anaconda2\lib\site-packages\keras\layers\core.py", line 695, in build
name='{}_W'.format(self.name))
File "C:\Users\Edward\Anaconda2\lib\site-packages\keras\initializations.py", line 36, in normal
return K.random_normal_variable(shape, 0.0, scale, name=name)
File "C:\Users\Edward\Anaconda2\lib\site-packages\keras\backend\theano_backend.py", line 145, in random_normal_variable
return variable(np.random.normal(loc=0.0, scale=scale, size=shape),
File "mtrand.pyx", line 1903, in mtrand.RandomState.normal (numpy\random\mtrand\mtrand.c:18479)
File "mtrand.pyx", line 234, in mtrand.cont2_array_sc (numpy\random\mtrand\mtrand.c:3092)
ValueError: negative dimensions are not allowed

Process finished with exit code 1
`

@wepe
Copy link
Owner

wepe commented Oct 10, 2016

in line 79

model.add(Dense(128, init='normal', input_dim=1644))

input_dim is required when using as the first layer in a model, not necessary to set this argument here (keras auto-infer the input_dim ).

this may cause the error

@CCV-Edward
Copy link
Author

Thanks firstly.
Unluckily, there are some new problems such as below:
Traceback (most recent call last): File "D:/project/Github/MachineLearning-master/DeepLearning Tutorials/keras_usage/cnn.py", line 79, in <module> model.add(Dense(128, init='normal')) File "C:\Users\Edward\Anaconda2\lib\site-packages\keras\models.py", line 308, in add output_tensor = layer(self.outputs[0]) File "C:\Users\Edward\Anaconda2\lib\site-packages\keras\engine\topology.py", line 487, in __call__ self.build(input_shapes[0]) File "C:\Users\Edward\Anaconda2\lib\site-packages\keras\layers\core.py", line 695, in build name='{}_W'.format(self.name)) File "C:\Users\Edward\Anaconda2\lib\site-packages\keras\initializations.py", line 36, in normal return K.random_normal_variable(shape, 0.0, scale, name=name) File "C:\Users\Edward\Anaconda2\lib\site-packages\keras\backend\theano_backend.py", line 145, in random_normal_variable return variable(np.random.normal(loc=0.0, scale=scale, size=shape), File "mtrand.pyx", line 1903, in mtrand.RandomState.normal (numpy\random\mtrand\mtrand.c:18479) File "mtrand.pyx", line 234, in mtrand.cont2_array_sc (numpy\random\mtrand\mtrand.c:3092) ValueError: negative dimensions are not allowed

And I am not clearly about the usage of Dense layer, please give me some advice...

@wepe
Copy link
Owner

wepe commented Oct 11, 2016

I know what is wrong. You use theano as backend but your K.image_dim_ordering() is tf. To solve this problem, just reshape your data, please refer to https://github.com/fchollet/keras/blob/master/examples/mnist_cnn.py#L35 .

And check the file .keras/keras.json , if your use theano, it should be

{
    "image_dim_ordering": "th",
    "epsilon": 1e-07,
    "floatx": "float32",
    "backend": "theano"
}

@CCV-Edward
Copy link
Author

Thanks a lot!
This problem has been successfully sloved.

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