python - Keras 无法使用 theano 后端进行编译

标签 python cuda theano keras

当我尝试编译 keras 文档中的示例时出现以下错误。

/usr/include/string.h: In function ‘void* __mempcpy_inline(void*, const void*, size_t)’:
/usr/include/string.h:652:42: error: ‘memcpy’ was not declared in this scope
   return (char *) memcpy (__dest, __src, __n) + __n;
                                          ^
ERROR (theano.sandbox.cuda): Failed to compile cuda_ndarray.cu: ('nvcc return status', 1, 'for cmd', 'nvcc -shared -O3 -m64 -Xcompiler -DCUDA_NDARRAY_CUH=mc72d035fdf91890f3b36710688069b2e,-DNPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION,-fPIC,-fvisibility=hidden -Xlinker -rpath,/home/chase/.theano/compiledir_Linux-4.4--generic-x86_64-with-Ubuntu-16.04-xenial-x86_64-3.5.1+-64/cuda_ndarray -I/usr/local/lib/python3.5/dist-packages/theano/sandbox/cuda -I/usr/lib/python3/dist-packages/numpy/core/include -I/usr/include/python3.5m -I/usr/local/lib/python3.5/dist-packages/theano/gof -o /home/chase/.theano/compiledir_Linux-4.4--generic-x86_64-with-Ubuntu-16.04-xenial-x86_64-3.5.1+-64/cuda_ndarray/cuda_ndarray.so mod.cu -L/usr/lib -lcublas -lpython3.5m -lcudart')

我在 Ubuntu 16.04 上。我正在使用从默认存储库安装的 CUDA 7.5。我已经使用 CUDA 编译了一些我自己的 cuda 程序以及 ArrayFire 程序,所以我知道 CUDA 正在工作。

这是我尝试编译的...

from keras.models import Sequential

model = Sequential()
from keras.layers.core import Dense, Activation

model.add(Dense(output_dim=64, input_dim=100))
model.add(Activation("relu"))
model.add(Dense(output_dim=10))
model.add(Activation("softmax"))

model.compile(loss='categorical_crossentropy', optimizer='sgd', metrics=['accuracy'])

最佳答案

GCC 5.3 和 CUDA 似乎存在问题。我不得不在/usr/include/string.h 中注释掉以下更改,现在它可以工作了。

https://fossies.org/diffs/glibc/2.22_vs_2.23/string/string.h-diff.html

关于python - Keras 无法使用 theano 后端进行编译,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37083936/

相关文章:

python - Numpy:将每行中的最大值更改为 1,所有其他数字更改为 0

python - TensorFlow中Variable和get_variable的区别

python - 从标准泰国舞蹈 wav 歌曲中检测钹(泰国乐器)节奏

caching - 我的 CUDA JIT 缓存始终远低于 CUDA_CACHE_MAXSIZE

python - 我可以在 Keras 中分步训练模型吗?

Python:在基于 distutils 的项目中安装手册页

c++ - Cuda 内核返回 vector

algorithm - GPU Blob 边界框连接组件标记

python - 使用 Theano 进行神经网络特征提取

python - 如何定义允许差异化的自定义 Theano 类型