All Documents
Current Document

Content is empty

If you don't find the content you expect, please try another search term

Documentation

Install Caffe

Last updated:2021-06-15 11:09:33

Prerequisites

  1. Install CUDA. For more information about how to install CUDA, see Install CUDA.
  2. Install cuDNN and NCCL. For more information about how to install cuDNN and NCCL, see Install cuDNN and NCCL.
  3. Install the dependency libraries by executing the following commands:

    sudo apt-get install libprotobuf-dev libleveldb-dev libsnappy-dev libopencv-dev libhdf5-serial-dev protobuf-compiler libgflags-dev libgoogle-glog-dev liblmdb-dev libatlas-base-dev git  –y
    sudo apt-get install --no-install-recommends libboost-all-dev  -y

Install Caffe

  1. Download the proper Caffe version from GitHub by accessing https://github.com/NVIDIA/caffe/releases. Select Source code (tar.gz) or using the following command:

    wget https://github.com/NVIDIA/caffe/archive/v0.16.6.tar.gz
  2. Download and install OpenBLAS.

    wget  https://github.com/xianyi/OpenBLAS/archive/v0.2.20.tar.gz
    tar -xvf v0.2.20.tar.gz
    cd OpenBLAS-0.2.20
    make PRFIX=/opt/OpenBLAS
    make install
  3. Set the lib paths and make the libraries take effect.

    echo “/opt/OpenBLAS/lib/
          /usr/local/cuda/lib64“ >> /etc/ld.so.conf.d/cuda.conf 
    ldconfig 
    ldconfig –v
  4. Decompress the Caffe installation package and save the files to the /home directory.

    tar -xvf v0.16.6.tar.gz
    cd caffe-0.16.6 
    cp Makefile.config.example Makefile.config
  5. Edit the Makefile.config file as follows:

    vi Makefile.config

    Delete the comment sign (#) before USE_NCCL := 1 and USE_CUDNN := 1 to make the settings take effect. caffe1.jpg

    Note:

    • The USE_CUDNN := 1 setting enables cuDNN acceleration.
    • The USE_NCCL := 1 setting enables NCCL so Caffe can run on multiple GPUs.
  6. Save and close the file.
  7. Compile Caffe.

    make -all –j4   

    After the editor is opened, add the bin path as follows:

    vi /etc/profile
    export  PATH=$PATH:/home/ caffe-0.16.6/build/tools

    Save and close the profile. Execute the following command to make the profile take effect:

    source /etc/profile

Configure pycaffe

  1. Install the previously mentioned dependency libraries according to the manifest defined in the requirements.txt file, which resides in the python folder in the Caffe root directory. To view the content of the requirements.txt file, execute the following commands:

    cd caffe-0.16.6/python
    cat requirements.txt

    The following information is displayed:

    cython>=0.19.2
    numpy>=1.7.1,<=1.11.0
    scipy>=0.13.2
    scikit-image>=0.9.3
    matplotlib>=1.3.1
    ipython>=3.0.0,<=5.4.1
    h5py>=2.2.0
    leveldb>=0.191
    networkx>=1.8.1
    nose>=1.3.0
    pandas>=0.12.0
    protobuf>=2.5.0
    pydot2
    python-dateutil>=1.4,<2
    python-gflags>=2.0
    pyyaml>=3.10
    Pillow>=2.3.0
    six>=1.1.0
  2. Execute the installation code:

    for seq in $(cat requirements.txt  )
    do
    pip install $seq
    done
  3. After the installation is completed, execute the following commands:

    cd ..  ---- Return from the **python** directory to the Caffe root directory
    sudo pip install -r python/requirements.txt

    For items that have been successfully installed, the Requirement already satisfied message is displayed. The items that have not been successfully installed will be reinstalled.

  4. Compile the python interface.

    make pycaffe

    Open /etc/profile and add a path as follows:

    vi /etc/profile
    export PYTHONPATH=/home/ caffe-0.16.6/python:$PYTHONPATH

    Save and close the profile. Execute the following command to make the profile take effect:

    source /etc/profile
  5. Use Python code to test pycaffe. If the configuration is completed, the following command lines can be executed successfully:

    import caffe
    from caffe import layers as L
    from caffe import params as P
    
On this page
Pure ModeNormal Mode

Pure Mode

Click to preview the document content in full screen
Feedback