The Visionary Researcher

http://caffe.berkeleyvision.org/gathered/examples/mnist.html

wget 혹은 gunzip 설치 (sudo apt-get install xx이용)


데이터 준비

1. cd caffe-master(caffe가 설치된 dir)

2. ./data/mnist/get_mnist.sh

3. ./examples/mnist/create_mnist.sh


Training and Test

1. ./examples/mnist/train_lenet.sh

아래와 같은 결과 생성

99.05%의 정확도

binary proto file 생성 (examples/mnist/lenet_iter_10000.solverstate)

I0429 13:06:59.745952 19500 sgd_solver.cpp:273] Snapshotting solver state to binary proto file examples/mnist/lenet_iter_10000.solverstate
I0429 13:06:59.748658 19500 solver.cpp:317] Iteration 10000, loss = 0.00336479
I0429 13:06:59.748695 19500 solver.cpp:337] Iteration 10000, Testing net (#0)
I0429 13:06:59.840243 19500 solver.cpp:404]     Test net output #0: accuracy = 0.9905
I0429 13:06:59.840282 19500 solver.cpp:404]     Test net output #1: loss = 0.0290998 (* 1 = 0.0290998 loss)
I0429 13:06:59.840291 19500 solver.cpp:322] Optimization Done.
I0429 13:06:59.840297 19500 caffe.cpp:222] Optimization Done.


LeNet이란?

1. MNIST classification model

2. caffe-master/examples/mnist/lenet_train_test.prototxt의 내용

name: "LeNet"
layer {
  name: "mnist"
  type: "Data"
  top: "data"
  top: "label"
  include {
    phase: TRAIN
  }
  transform_param {
    scale: 0.00390625
  }
  data_param {
    source: "examples/mnist/mnist_train_lmdb"
    batch_size: 64
    backend: LMDB
  }
}
layer {
  name: "mnist"
  type: "Data"
  top: "data"
  top: "label"
  include {
    phase: TEST
  }
  transform_param {
    scale: 0.00390625
  }
  data_param {
    source: "examples/mnist/mnist_test_lmdb"
    batch_size: 100
    backend: LMDB
  }
}
layer {
  name: "conv1"
  type: "Convolution"
  bottom: "data"
  top: "conv1"
  param {
    lr_mult: 1
  }
  param {
    lr_mult: 2
  }
  convolution_param {
    num_output: 20
    kernel_size: 5
    stride: 1
    weight_filler {
      type: "xavier"
    }
    bias_filler {
      type: "constant"
    }
  }
}
layer {
  name: "pool1"
  type: "Pooling"
  bottom: "conv1"
  top: "pool1"
  pooling_param {
    pool: MAX
    kernel_size: 2
    stride: 2
  }
}
layer {
  name: "conv2"
  type: "Convolution"
  bottom: "pool1"
  top: "conv2"
  param {
    lr_mult: 1
  }
  param {
    lr_mult: 2
  }
  convolution_param {
    num_output: 50
    kernel_size: 5
    stride: 1
    weight_filler {
      type: "xavier"
    }
    bias_filler {
      type: "constant"
    }
  }
}
layer {
  name: "pool2"
  type: "Pooling"
  bottom: "conv2"
  top: "pool2"
  pooling_param {
    pool: MAX
    kernel_size: 2
    stride: 2
  }
}
layer {
  name: "ip1"
  type: "InnerProduct"
  bottom: "pool2"
  top: "ip1"
  param {
    lr_mult: 1
  }
  param {
    lr_mult: 2
  }
  inner_product_param {
    num_output: 500
    weight_filler {
      type: "xavier"
    }
    bias_filler {
      type: "constant"
    }
  }
}
layer {
  name: "relu1"
  type: "ReLU"
  bottom: "ip1"
  top: "ip1"
}
layer {
  name: "ip2"
  type: "InnerProduct"
  bottom: "ip1"
  top: "ip2"
  param {
    lr_mult: 1
  }
  param {
    lr_mult: 2
  }
  inner_product_param {
    num_output: 10
    weight_filler {
      type: "xavier"
    }
    bias_filler {
      type: "constant"
    }
  }
}
layer {
  name: "accuracy"
  type: "Accuracy"
  bottom: "ip2"
  bottom: "label"
  top: "accuracy"
  include {
    phase: TEST
  }
}
layer {
  name: "loss"
  type: "SoftmaxWithLoss"
  bottom: "ip2"
  bottom: "label"
  top: "loss"
}

3. caffe-master/examples/mnist/lenet_solver.prototxt의 내용

# The train/test net protocol buffer definition
net: "examples/mnist/lenet_train_test.prototxt"
# test_iter specifies how many forward passes the test should carry out.
# In the case of MNIST, we have test batch size 100 and 100 test iterations,
# covering the full 10,000 testing images.
test_iter: 100
# Carry out testing every 500 training iterations.
test_interval: 500
# The base learning rate, momentum and the weight decay of the network.
base_lr: 0.01
momentum: 0.9
weight_decay: 0.0005
# The learning rate policy
lr_policy: "inv"
gamma: 0.0001
power: 0.75
# Display every 100 iterations
display: 100
# The maximum number of iterations
max_iter: 10000
# snapshot intermediate results
snapshot: 5000
snapshot_prefix: "examples/mnist/lenet"
# solver mode: CPU or GPU
solver_mode: GPU


댓글 0

BVLC caffe

1. https://github.com/BVLC/caffe에서 Download ZIP이용해서 save

2. 압축해제

3. cd Downloads/caffe-master (압축 해제)

4. caffe-master folder를 home으로 이동

5. cd caffer-master

6. sudo cp Makefile.config.example Makefile.config

(이름 변경)

7. sudo gedit Makefile.config

8. 원하는 주석 해제

CUDNN사용할 것이므로 USE_CUDNN = 1 주석 제거

9. make all -j4(CPU가 쿼드코어인경우, 옥타코어면 -j8)

10. make test -j4

11. make runtest -j4 (모두 pass가 나오는지 확인)


lisa-caffe

1. https://github.com/LisaAnne/lisa-caffe-public/tree/lstm_video_deploy에서 Download ZIP이용해서 save

2. 압축해제

3. cd Downloads/lisa-caffe-public-lstm_video_deploy (압축 해제)

4. lisa-caffe-public-lstm_video_deploy folder를 home으로 이동

5. cd lisa-caffe-public-lstm_video_deploy

6. sudo cp Makefile.config.example Makefile.config

(이름 변경)

7. sudo gedit Makefile.config

8. 원하는 주석 해제

CUDNN사용할 것이므로 USE_CUDNN = 1 주석 제거

9. make all -j4(CPU가 쿼드코어인경우, 옥타코어면 -j8)


cblas.h 문제가 있을 경우 3. cudnn에서 아래의 dependency 수행

댓글 0

1. https://developer.nvidia.com/cudnn

2. register (회원가입하면 해당 이메일로 확인 메일 발송)

3. 비밀번호 설정 후 https://developer.nvidia.com/cudnn에서 다운로드

4. 해당 CUDA 버전에 맞는 Cudnn 설치

Download cuDNN v5 Release Candidate (RC) (April, 2016), for CUDA 7.5 and later.

Download cuDNN v4 (Feb 10, 2016), for CUDA 7.0 and later.

CUDA7.0의 경우 v4 설치

5. save cuDNN v4 Library for Linux

6. Download된 장소에 가서 압축 풀기

7. cd Downloads/cuda (압축 푼 장소)

8. 아래의 복사 명령어 수행

sudo cp ./lib64/libcudnn.so /usr/local/cuda-7.0(해당 버전)/lib64

sudo cp ./lib64/libcudnn_static.a /usr/local/cuda-7.0/lib64

sudo cp ./lib64/libcudnn.so.4.0.7 /usr/local/cuda-7.0/lib64

sudo cp ./lib64/libcudnn.so.4 /usr/local/cuda-7.0/lib64

sudo cp ./include/cudnn.h /usr/local/cuda-7.0/include


파일 명은 조금씩 다를 수 있으므로 lib64에 있는 파일이 무엇인지 이름 맞게 수정

9. http://caffe.berkeleyvision.org/install_apt.html에서 아래의 내용 입력

sudo apt-get install libprotobuf-dev libleveldb-dev libsnappy-dev libopencv-dev libhdf5-serial-dev protobuf-compiler
sudo apt-get install --no-install-recommends libboost-all-dev

sudo apt-get install libatlas-base-dev

sudo apt-get install libgflags-dev libgoogle-glog-dev liblmdb-dev


댓글 0

티스토리 툴바