注意:我使用的是Keras 2.2.4和TensorFlow 1.12.0。 我能够通过以下步骤解决问题:
1)使用CudnnLSTM训练模型并保存模型(model_GPU.json)和权重(* .h5)。
2)为LSTM定义改变CudnnLSTM的相同模型,这必须在没有GPU的系统/计算机中完成,然后您可以保存模型(model_CPU.json)。
2 *)在LSTM单元格中,激活='tanh',recurrent_activation ='sigmoid'。因为这些是CudnnLSTM中的默认值。
3)然后您可以使用CudnnLSTM训练的权重加载model_CPU.json。
具体来说,我使用了以下内容
中央处理器: 来自keras.layers导入LSTM
双向(LSTM(hidden_units_LSTM,return_sequences = True,activation ='tanh',recurrent_activation ='sigmoid'))(输出)
GPU: 来自keras.layers导入CuDNNLSTM
双向(CuDNNLSTM(hidden_units_LSTM,return_sequences = True))(输出)