导入 keras 时出现 ValueError «您正在尝试使用旧的 GPU 后端»

ValueError «You are trying to use the old GPU back-end» when importing keras

我在 Ubuntu 16.04 上使用 Keras with the Theano 后端。我的设置一直没有问题,但是,当我导入 Keras (import keras) 时突然出现以下错误:

ValueError: You are trying to use the old GPU back-end. It was removed from Theano. Use device=cuda* now. See https://github.com/Theano/Theano/wiki/Converting-to-the-new-gpu-back-end%28gpuarray%29 for more information.

我该如何解决这个问题?

您应该更改(或添加)名为 THEANO_FLAGS 的环境变量。如果您设置变量使其包含 device=cuda 而不是 device=gpu,则错误将消失。

同时在 GPU 上工作时将浮点精度设置为 float32,因为这通常要快得多 (THEANO_FLAGS='device=cuda,floatX=float32')。

可以找到有关此变量的更多信息 here and here

我没有 gpu,使用 cpu,工作:

export THEANO_FLAGS='mode=FAST_RUN,device=cpu,floatX=float32'