필요한 정보를 최대한 인용하여 작성할 생각이다.


아래 글은 블로그(http://bcho.tistory.com/1192) 에서 인용했다.


Tensorflow Object Detection API는, Tensorflow 를 이용하여 이미지를 인식할 수 있도록 개발된 모델로, 라이브러리 형태로 제공되며, 각기 다른 정확도와 속도를 가지고 있는 5개의 모델을 제공한다. 머신러닝이나 텐서플로우에 대한 개념이 거의 없더라도 라이브러리 형태로 손쉽게 사용할 수 있으며, 직접 사용자 데이타를 업로드해서 학습을 하여, 내 시나리오에 맞는 Object Detection System을 손쉽게 만들 수 있다.


Object Detection API를 설치하기 위해서는 텐서플로우 1.x 와 파이썬 2.7x 버전이 사전 설치되어 있어야 한다. 이 글에서는 파이썬 2.7.13과 텐서플로우 2.7.13 버전을 기준으로 하고, 맥에 설치하는 것을 기준으로 한다. 리눅스나 다른 플랫폼 설치는 원본 설치 문서 https://github.com/tensorflow/models/blob/master/object_detection/g3doc/installation.md 를 참고하기 바란다.


2017.6.15에 Google에서 Tensorflow로 구현된Object Detection코드를 공개 했다. 지원하는 모델은 아래와 같다.

  • In addition to our base Tensorflow detection model definitions, this release includes:

    • A selection of trainable detection models, including:
      • Single Shot Multibox Detector (SSD) with MobileNet,
      • SSD with Inception V2,
      • Region-Based Fully Convolutional Networks (R-FCN) with Resnet 101,
      • Faster RCNN with Resnet 101,
      • Faster RCNN with Inception Resnet v2
    • Frozen weights (trained on the COCO dataset) for each of the above models to be used for out-of-the-box inference purposes.
    • Jupyter notebook for performing out-of-the-box inference with one of our released models
    • Convenient local training scripts as well as distributed training and evaluation pipelines via Google Cloud.
    SSD, RCNN 등 object detection 및 segmentation 하는 유명한 모델들이 tensorflow 안으로 들어갔다.

파이썬 라이브러리 설치


Object Detection API를 사용하는데 필요한 라이브러리 입니다. 

  • Protobuf 2.6
  • Pillow 1.0
  • lxml
  • tf Slim (which is included in the "tensorflow/models" checkout)
  • Jupyter notebook
  • Matplotlib
  • Tensorflow

pip install pillow
pip install lxml
pip install matplotlib
sudo yum install tkinter
sudo yum install protobuf
sudo yum install protobuf-compiler

pip install jupyter


Object Detection API 다운로드 및 설치


Object Detection API 설치는 간단하게, 라이브러리를 다운 받으면 된다. 설치할 디렉토리로 들어가서 git clone 명령어를 통해서, 라이브러리를 다운로드 받자

% git clone https://github.com/tensorflow/models

Protocol Buffer 컴파일

다음 프로토콜 버퍼를 사용하기 위해서 protoc로 proto 파일을 컴파일 한데, Object Detection API를 설치한 디렉토리에서 models 디렉토리로 들어간 후에, 다음 명령어를 수행한다.

" 레포지토리가 최신화가 안되어서 소스 설치를 했다. "

# $ sudo pip install protobuf
# $ yum install protobuf-compiler

% git clone https://github.com/google/protobuf.git

$ ./autogen.sh

$ ./configure --prefix=/home/tensorflow/local/protoc

$ make

$ python setup.py build

$ python setup.py test

$ sudo python setup.py install

$ protoc

$ protoc --version

export LD_LIBRARY_PATH=../src/.libs

% protoc object_detection/protos/*.proto --python_out=.


Add Libraries to PYTHONPATH

When running locally, the tensorflow/models/research/ and slim directories should be appended to PYTHONPATH. This can be done by running the following from tensorflow/models/research/:

# From tensorflow/models/research/
% export PYTHONPATH=$PYTHONPATH:`pwd`:`pwd`/slim

vi ~/venvs/tensorflow/bin/activate

PATH="$VIRTUAL_ENV/bin:$PATH:/usr/local/cuda-8.0/bin:/home/tensorflow/sylee/src/OBJ_DETECTI
ON_DEMO/models/research:/home/tensorflow/sylee/src/OBJ_DETECTION_DEMO/models/research/slim"
export PATH
PYTHONPATH="/home/tensorflow/sylee/src/OBJ_DETECTION_DEMO/models/research:/home/tensorflow/
sylee/src/OBJ_DETECTION_DEMO/models/research/slim"
export PYTHONPATH


Note: This command needs to run from every new terminal you start. If you wish to avoid running this manually, you can add it as a new line to the end of your ~/.bashrc file.


Testing the Installation

You can test that you have correctly installed the Tensorflow Object Detection
API by running the following command:

% python object_detection/builders/model_builder_test.py



NVIDIA-DOCKER - Ubuntu 16.04 설치 가이드


Tensorflow Object Detection API depends on the following libraries:
•Protobuf 2.6
•Pillow 1.0
•lxml
•tf Slim (which is included in the "tensorflow/models/research/" checkout)
•Jupyter notebook
•Matplotlib
•Tensorflow


For detailed steps to install Tensorflow, follow the Tensorflow installation instructions. A

typical user can install Tensorflow using one of the following commands:

# For CPU
pip install tensorflow
# For GPU
pip install tensorflow-gpu


The remaining libraries can be installed on Ubuntu 16.04 using via apt-get:

sudo apt-get install protobuf-compiler python-pil python-lxml
sudo pip install jupyter
sudo pip install matplotlib

Alternatively, users can install dependencies using pip:

sudo pip install pillow
sudo pip install lxml
sudo pip install jupyter
sudo pip install matplotlib

sudo apt-get install python-tk


Object Detection API 다운로드 및 설치

Object Detection API 설치는 간단하게, 라이브러리를 다운 받으면 된다. 설치할 디렉토리로 들어가서

git clone 명령어를 통해서, 라이브러리를 다운로드 받자

$ git clone https://github.com/tensorflow/models


Protobuf Compilation

The Tensorflow Object Detection API uses Protobufs to configure model and training parameters.

Before the framework can be used, the Protobuf libraries must be compiled. This should be done

by running the following command from the tensorflow/models/research/ directory:

# From tensorflow/models/research/
$ protoc object_detection/protos/*.proto --python_out=.


Add Libraries to PYTHONPATH

When running locally, the tensorflow/models/research/ and slim directories should be appended to PYTHONPATH. This can be done by running the following from tensorflow/models/research/:

# From tensorflow/models/research/$ export PYTHONPATH=$PYTHONPATH:`pwd`:`pwd`/slim

''''

PATH="$PATH:/usr/local/cuda-8.0/bin:/home/tensorflow/sylee/src/OBJ_DETECTION/modd
els/research:/home/tensorflow/sylee/src/OBJ_DETECTION/models/research/slim"
export PATH
PYTHONPATH="/usr/local/cuda-8.0/bin:/home/tensorflow/sylee/src/OBJ_DETECTION/modd
els/research:/home/tensorflow/sylee/src/OBJ_DETECTION/models/research/slim"
export PYTHONPATH

''''


Install object_detection

 

 


마지막으로, models디렉토리 에서 다음 스크립트를 실행하여 object_dection 라이브러리를 설치 할 수 있다.

 

sudo python setup.py install


설치도중 이와 같은 에러가 날 경우 


python-setuptools 설치를 통해 해결 할 수 있다.

sudo apt-get install python-setuptools


Testing the Installation

You can test that you have correctly installed the Tensorflow Object Detection
API by running the following command:


$ python object_detection/builders/model_builder_test.py




※ 설치 할 때부터 하나하나 기록해가면서 했어야 하는데.. 그러지 못해서 역시나.. 순서나 이런게 헛갈린다.

나중에 다시 손을 보겠다.


공부한 내용을 그때그때 바로 기록하는 습관이 갖어지길 바라며..

Posted by 이성윤