duhaime
duhaime

Reputation: 27602

Keras: Loading model built with CuDNNLSTM on host without GPU

I trained a keras model that uses CuDNNLSTM cells, and now wish to load the model on a host device that lacks a GPU. Because CuDNNLSTM cells require a GPU, though, the loading process bombs out, throwing:

No OpKernel was registered to support Op 'CudnnRNN' with these attrs.

Is there some backdoor that will allow me to load the model on a host without a GPU? Any suggestions would be very helpful!

Upvotes: 2

Views: 2085

Answers (1)

David GG
David GG

Reputation: 125

Note: I am using Keras 2.2.4 and TensorFlow 1.12.0. I was able to solve the issue with the following steps:

1) Train the model with CudnnLSTM and save the model (model_GPU.json) and the weights (*.h5).

2) Define the same model changing CudnnLSTM for LSTM, this must be done in a system/computer with no GPU, and then you can save the model (model_CPU.json).

2*) In the LSTM cell set activation='tanh',recurrent_activation='sigmoid'. Since these are the default ones in CudnnLSTM.

3) Then you can load model_CPU.json with the weights trained with CudnnLSTM.

Specifically, I used the following

CPU:

from keras.layers import LSTM

Bidirectional(LSTM(hidden_units_LSTM, return_sequences=True,activation='tanh',recurrent_activation='sigmoid'))(output)

GPU:

from keras.layers import CuDNNLSTM

Bidirectional(CuDNNLSTM(hidden_units_LSTM, return_sequences=True))(output)

Upvotes: 6

Related Questions