Until you install Caffe and run the sample

I wanted to use Caffe, a library with a good reputation for image recognition, I tried to summarize the procedure to install and run the sample (mnist).

The setup environment is as follows.

1. 1. Installation of external libraries

Install the required set of libraries.

~


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

2. Download Caffe

Download the Caffe source from git.

~


$ git clone https://github.com/BVLC/caffe.git
$ cd caffe

3. 3. Edit configuration file

First, create a make file for compilation.

caffe/


$ cp Makefile.config.example Makefile.config

If you compile as it is, some errors occurred, so To avoid that, rewrite some configuration files.

3.1. around hdf5

If you are told something like "can't find hdf5.h" First, let's check if libhdf5-dev is apt-get.

If it's installed but you get an error, Modify INCLUDE_DIRS in Makefile.config.

caffe/Makefile.config


#INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include /usr/include/hdf5/serial/
INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include /usr/include/hdf5/serial/

3.2. around cuda

Next, if you are told "/ usr / local / cuda / bin / nvcc: not found", Modify CUDA_DIR in Makefile.config.

caffe/Makefile.config


#CUDA_DIR := /usr/local/cuda
CUDA_DIR := /usr

3.3. around memcpy

If you get an error around memcpy, modify NVCCFLAGS in caffe / Makefile as follows. (Not Makefile.config, confusing)

caffe/Makefile


#NVCCFLAGS += -ccbin=$(CXX) -Xcompiler -fPIC $(COMMON_FLAGS)
NVCCFLAGS += -D_FORCE_INLINES -ccbin=$(CXX) -Xcompiler -fPIC $(COMMON_FLAGS)

3.4. around lhdf5

When you are told "/ usr / bin / ld: -hdf5_hl not found" Paste the symbolic link inside / usr / lib / x86_64-linux-gnu.

/usr/lib/x86_64-linux-gnu


$ cd /usr/lib/x86_64-linux-gnu
$ sudo ln -s libhdf5_serial.so.10.1.0 libhdf5.so
$ sudo ln -s libhdf5_serial_hl.so.10.0.2 libhdf5_hl.so

4. compile

At this point, the necessary settings should be almost complete. Let's compile and test.

caffe


$ make
$ make runtest

If the runtest result is PASSED, the Caffe installation is complete.

passed.png

5. Sample test

By default, caffe contains a set of learning scripts.

So, after that, you can move the sample just by hitting the script one by one.

First, download the mnist data and convert it.

caffe/


$ data/mnist/get_mnist.sh
$ examples/mnist/create_mnist.sh

Now that we have the training data, let's train the model.

caffe/


$ examples/mnist/train_lenet.sh

Finally, run the mnist test using the trained model.

caffe/


$ ./build/tools/caffe test -model ./examples/mnist/let_train_test.prototxt -weights ./examples/mnist/lenet_iter_10000.caffemodel

Up to this point, I was able to move Caffe.

References

Recommended Posts

Until you install Caffe and run the sample
Until you install Gauge and run the official sample
Until you install and run matplotlib
Until you run the changefinder sample in python
Until you can install blender and run it with python for the time being
Until you build the environment with ABCI and run MaskTrack RCNN
[Introduction to machine learning] Until you run the sample code with chainer
Until you install MySQL-python
Until you install Python with pythonbrew and run Flask on a WSGI server
Until you install Anaconda for data analysis on your Mac and launch the IDE
Try and learn iptables, until you can browse the web
Install and run dropbox on Ubuntu 20.04
Run Pylint and read the results
Until you run python with apache
Quickly install OpenCV 2.4 (+ python) on OS X and try the sample
Until you install Apache and Tomcat on Linux (CentOS) and deploy Java apps
[xgboost error] Cannot find XGBoost Libarary in the candicate path, did you install compilers and run build.sh in root path
Until you can read the error log
Until you install your own Python library
Until you install Arch Linux on VMware
Until you create an Ubuntu boot USB on your Macbook and install Ubuntu on your Thinkpad
Install the Python API of the autonomous driving simulator LGSVL and execute the sample program
Install and run Python3.5 + NumPy + SciPy on Windows 10
Until you use the Kaggle API with Colab
Run unit tests the moment you save the file
Until you can use the Google Speech API
[Mac] Run the RealSense D415 sample in Python
Until you run a Flask application on Google App Engine for the time being
Until you create a machine learning environment with Python on Windows 7 and run it
Run the flask app on Cloud9 and Apache Httpd
Install Apache 2.4 on Ubuntu 19.10 Eoan Ermine and run CGI
Install the latest stable Python with pyenv (both 2 and 3)
Install Docker on Arch Linux and run it remotely
Until you run server Django in Visual Studio Code
Install Ubuntu 20.04 with GUI and prepare the development environment
Until you install TensorFlow-GPU with pip in Windows environment
Install django on python + anaconda and start the server
Run the Caffe model on Google Colaboratory to predict the age and gender of the world's supermodels