完成后,!apt install caffe-cuda
我尝试在 google colaboratory 上使用 caffe,但没有结果。欢迎任何帮助。谢谢
问问题
742 次
1 回答
0
该命令apt install caffe-cuda
为 Python3 安装 cuda。对于 python2,您必须手动安装它(克隆git 文件夹并制作)。在 colab 笔记本中使用以下命令:
#Clone the repo
!cp caffe/Makefile.config.example caffe/Makefile.config
# Make changes to Makefile
!git clone https://github.com/BVLC/caffe.git
!sed -i 's/# OPENCV_VERSION/OPENCV_VERSION/g' caffe/Makefile.config
!sed -i 's/CUDA_ARCH :=/CUDA_ARCH :=\n/g' caffe/Makefile.config
!sed -i 's/# USE_CUDNN/USE_CUDNN/g' caffe/Makefile.config
!sed -i 's/# WITH_PYTHON_LAYER := 1/WITH_PYTHON_LAYER := 1\n/g' caffe/Makefile.config
!sed -i 's/-gencode arch=compute_20,code=sm_20/#-gencode arch=compute_20,code=sm_20/g' caffe/Makefile.config
!sed -i 's/-gencode arch=compute_20,code=sm_21/#-gencode arch=compute_20,code=sm_21/g' caffe/Makefile.config
!sed -i 's/\/usr\/local\/include/\/usr\/local\/include \/usr\/include\/hdf5\/serial/g' caffe/Makefile.config
!sed -i 's/\/usr\/local\/lib/\/usr\/local\/lib \/usr\/lib\/x86_64-linux-gnu\/hdf5\/serial/g' caffe/Makefile.config
!sed -i 's/\/usr\/lib\/python2.7\/dist-packages\/numpy/\/usr\/local\/lib\/python2.7\/dist-packages\/numpy/g' caffe/Makefile.config
!cat caffe/Makefile.config
#Install Dependencies
!sudo apt-get install libprotobuf-dev libleveldb-dev libsnappy-dev libopencv-dev libhdf5-serial-dev protobuf-compiler libgflags-dev libgoogle-glog-dev liblmdb-dev
#Make
!cd caffe && make -j32
另外,我正在尝试安装 pycaffe。所以一旦你制作了 pycaffe,你必须将python/
caffe 的文件夹添加到sys
. 您可以使用以下方法实现它:
import sys
sys.path.insert(1, "{path to pycaffe}/python")
于 2019-07-26T10:44:22.997 回答