The codes you see in the video are listed below for you to copy/paste (for your convenience)


$> 

sudo apt-get install build-essential

$> 

sudo apt-get install linux-headers-`uname -r`



**not necessary unless you have GPU installed and want to use CUDA**

$> 

curl -O "http://developer.download.nvidia.com/compute/cuda/6_5/rel/installers/cuda_6.5.14_linux_64.run"

$> 

chmod +x cuda_6.5.14_linux_64.run

$> 

sudo cuda_6.5.14_linux_64.run --kernel-source-path=/usr/src/linux-headers-`uname -r`/




$> echo 'export PATH=/usr/local/cuda/bin:$PATH' >> ~/.bashrc

$> echo 'export LD_LIBRARY_PATH=$LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/cuda/lib64:/usr/local/lib' >> ~/.bashrc

$> source ~/.bashrc

$> echo 'export PATH=/usr/local/cuda/bin:$PATH' >> ~/.bashrc

$> echo 'export LD_LIBRARY_PATH=$LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/cuda/lib64:/usr/local/lib' >> ~/.bashrc

$> source ~/.bashrc



$> 

sudo apt-get install -y libprotobuf-dev libleveldb-dev libsnappy-dev libopencv-dev libboost-all-dev libhdf5-serial-dev protobuf-compiler gfortran libjpeg62 libfreeimage-dev libatlas-base-dev git python-dev python-pip libgoogle-glog-dev libbz2-dev libxml2-dev libxslt1-dev libffi-dev libssl-dev libgflags-dev liblmdb-dev


$> 

sudo apt-get install -y libprotobuf-dev libleveldb-dev libsnappy-dev libopencv-dev libboost-all-dev libhdf5-serial-dev protobuf-compiler gfortran libjpeg62 libfreeimage-dev libatlas-base-dev git python-dev python-pip libgoogle-glog-dev libbz2-dev libxml2-dev libxslt1-dev libffi-dev libssl-dev libgflags-dev liblmdb-dev


$> 

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

$> 

cd caffe

$> 

cat python/requirements.txt | xargs -L 1 sudo pip install



$> 

sudo ln -s /usr/include/python2.7/ /usr/local/include/python2.7

$> 

sudo ln -s /usr/local/lib/python2.7/dist-packages/numpy/core/include/numpy /usr/local/include/python2.7/numpy


$> cp Makefile.config.example Makefile.config

$> vi Makefile.config

......

......

CPU_ONLY := 1

PYTHON_INCLUDE := /usr/local/include/python2.7 \

                                          /usr/local/include/python2.7/numpy




$> make pycaffe

$> make all

$> make test



$> python scripts/download_model_binary.py models/bvlc_reference_caffenet

$> sh data/ilsvrc12/get_ilsvrc_aux.sh


**


import pandas as pd


parser.add_argument(

  ...

)

parser.add_argument(

  "--print_results",

  action='store_true',

  help="Write output text to stdout rather than serializing to a file."

)

parser.add_argument(

  "--labels_file",

  default=os.path.join(pycaffe_dir,"../data/ilsvrc12/synset_words.txt"),

  help="Readable label definition file."

)


...


#Classify

start = time.time()

scores = classifier.predict(inputs, not args.center_only).flatten()

print("Done in %.2f s."(time.time() - start))


if args.print_results:

  with open(args.labels_file) as f:

    labels_df = pd.DataFrame([{'synset_id':l.strip().split(' ')[0], 'name': ' '.join(l.strip().split(' ')[1:]).split(',')[0]} for l in f.readlines()])

    labels = labels_df.sort('synset_id')['name'].values

    

    indices =(-scores).argsort()[:5]

    predictions = labels[indicies]

    

    meta = [(p, '%.5f % scores[i]) for i,p in zip(indices, predictions)]

    print meta


**


$> python python/classify.py --print_results examples/images/cat.jpg foo





--error fix codes--


1. fatal error: gflags/gflags.h:No such file or directory

$> wget https://github.com/schuhschuh/gflags/archive/master.zip

$>  unsip master.zip

$> cd gflags-master

$> mkdir build && cd build

$> export CXXFLAGS="-fPIC" && cmake .. && make VERBOSE=1

$> make

$> sudo make install




2. ImportError: No module named google.protobuf.internal

$> pip install protobuf


3. ImportError: No module named skimage

$> pip install scikit-image


4. ValueError: Mean shape incompatible with input shape


if ms != self.inputs[in_] :

   print(self.inputs[in_])

  in_shape = self.inputs[in_][1:]

    m_min, m_max = mean.min(), mean.max()

  normal_mean = (mean - m_min) / (m_max - m_min)

    mean = resize_image(normal_mean.transpose((1,2,0)), in_shape[1:]).transpose((2,0,1)) * (m_max - m_min) + m_min  








***************************************************************

Credit goes to :


http://yujuwon.tistory.com/entry/DeepLearning-%EC%9A%B0%EB%B6%84%ED%88%AC-1404%EC%97%90-Caffe-%EC%84%A4%EC%B9%98-%ED%95%98%EA%B8%B0 




WRITTEN BY
서상호

,