If you want to install Caffe on Ubuntu 16.04 along with Anaconda, here is an installation guide:
Install Nvidia driver and Cuda (Optional)
If you want to use GPU to accelerate, follow instructions here to install Nvidia drivers, CUDA 8RC and cuDNN 5 (skip caffe installation there).
Install Anaconda
Download Anaconda from here. Choose Python 2.7 version 64-BIT INSTALLER to install it. Then update it:
conda update conda
If you want to create an environment such as testcaffe
, execute commands:
conda create -n testcaffe python
source activate testcaffe
Install OpenCV:
conda install -c menpo opencv3
Install Dependencies
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install -y build-essential cmake git pkg-config
sudo apt-get install -y libprotobuf-dev libleveldb-dev libsnappy-dev protobuf-compiler
sudo apt-get install -y libatlas-base-dev
sudo apt-get install -y --no-install-recommends libboost-all-dev
sudo apt-get install -y libgflags-dev libgoogle-glog-dev liblmdb-dev
Build Caffe
Go to https://github.com/BVLC/caffe, download zip archive and unpack it. Or clone the source code. Enter the <caffe-home>
directory in the terminal window:
mkdir build
cd build
cmake ..
make all
make install
Enter <caffe-home>/python
directory to install Python packages:
conda install cython scikit-image ipython h5py nose pandas protobuf pyyaml jupyter
for req in $(cat requirements.txt); do pip install $req; done
cd ../build
make runtest
If you want to use some other packages in the Conda evnviroment, you need to install them now, otherwise the packages might not find the dependences you installed in the evnviroment.
Add the module directory to your $PYTHONPATH
by
cd ../python
export PYTHONPATH=`pwd`${PYTHONPATH:+:${PYTHONPATH}}
Test Run
First verify the installation:
python -c "import caffe;print caffe.__version__"
If the Caffe version number is shown up correctly, then change directory to examples
, execute command:
jupyter notebook
这样装完Caffe之后,只能在<caffe-home>/python
文件夹下 导入caffe, 在其他文件夹下导入不成功。
若要随时 import caffe成功,需要:
将<caffe-home>/python/caffe 文件夹copy到 你的python环境中的site-packages文件夹下即可!
记录几个命令:
conda activate 环境名 // 激活环境
conda deactivate // 关闭环境
文章转载:自