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

Code runs fine on CPU but gives ValueError on GPU #4877

Closed
shariqfarooq123 opened this issue Dec 30, 2016 · 2 comments
Closed

Code runs fine on CPU but gives ValueError on GPU #4877

shariqfarooq123 opened this issue Dec 30, 2016 · 2 comments

Comments

@shariqfarooq123
Copy link

shariqfarooq123 commented Dec 30, 2016

I'm trying to build a Deconvolutional Network, model is built as follows:

`
model = Sequential([

Convolution2D(120,5,5,input_shape=(3,16,16),dim_ordering="th",activation="relu",border_mode="same"),

MaxPooling2D(pool_size=(2,2)),

Convolution2D(240,3,3,activation="relu",border_mode="same"),

MaxPooling2D(pool_size=(2, 2)),

Convolution2D(90,1,1,activation="relu",border_mode="same"),

MaxPooling2D(pool_size=(2, 2)),

Convolution2D(512,2,2,activation="relu"),

UpSampling2D(dim_ordering="th"),

Deconvolution2D(112,2,2,input_shape=(512,2,2),output_shape=(None,112,4,4),subsample=(2,2),dim_ordering="th",activation="relu",),

Deconvolution2D(64,2,2,input_shape=(112,4,4),output_shape=(None,64,8,8),subsample=(2,2),dim_ordering="th",activation="relu"),

Deconvolution2D(32,2,2,input_shape=(64,8,8),output_shape=(None,32,16,16),subsample=(2,2),dim_ordering="th",activation="relu"),

Deconvolution2D(4,1,1,input_shape=(32,16,16),output_shape=(None,4,16,16),dim_ordering="th",activation="relu"),

Flatten(),

])
`

If I set "optimizer=None" in .theanorc file i.e if code is run on CPU, No error occurs. But when run using GPU (optimizer=fast_run) following error occurs:
`

 Traceback (most recent call last):

File "C:/Users/Lab/PycharmProjects/srcovnet/shariq/cov2d.py", line 59, in <module>
model.fit(data_train,labels_train,nb_epoch=10)

File "C:\Users\Lab\Anaconda2\lib\site-packages\keras\models.py", line 652, in fit
sample_weight=sample_weight)

File "C:\Users\Lab\Anaconda2\lib\site-packages\keras\engine\training.py", line 1111, in fit
initial_epoch=initial_epoch)

File "C:\Users\Lab\Anaconda2\lib\site-packages\keras\engine\training.py", line 826, in _fit_loop
outs = f(ins_batch)

File "C:\Users\Lab\Anaconda2\lib\site-packages\keras\backend\theano_backend.py", line 811, in 
__call__
return self.function(*inputs)

File "C:\Users\Lab\Anaconda2\lib\site-packages\theano\compile\function_module.py", line 871, in 
__call__

storage_map=getattr(self.fn, 'storage_map', None))

File "C:\Users\Lab\Anaconda2\lib\site-packages\theano\gof\link.py", line 314, in raise_with_op
reraise(exc_type, exc_value, exc_trace)

File "C:\Users\Lab\Anaconda2\lib\site-packages\theano\compile\function_module.py", line 859, in 
__call__

outputs = self.fn()



ValueError: GpuDnnConv images and kernel must have the same stack size`

What is the problem?

@gvtulder
Copy link
Contributor

gvtulder commented Jan 4, 2017

Which version of Keras are you using? I looks similar to a problem I had before and that was fixed by #4631. If your problem is similar, upgrading to 1.2.0 might help. Keras 1.1.2 and older have an incorrect order of the filter shape in the deconvolution layer for Theano.

If this is indeed the cause of your problem, your code probably also doesn't do what you want in CPU mode. It's just that the GPU code has better checks. (This is fixed in the current Theano master and should be included in the next Theano release.)

@stale stale bot added the stale label May 23, 2017
@stale
Copy link

stale bot commented May 23, 2017

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs, but feel free to re-open it if needed.

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