머신러닝 || 딥러닝

[객체추출] Object detection with 텐서플로

써니(>_<) 2022. 9. 8. 02:34

Object detection using Tensor flow API 

 

Setup (MAC) 

Install Python library 

$ pip install pillow

$ pip install lxml

$ pip install jupyter

$ pip install matplotlib

 

Install protocol buffer 

1. download protobuf-all-21.5.tar.gz from https://github.com/protocolbuffers/protobuf/releases

2. Extract the tar.gz file.

3. $cd ~/Downloads/protobuf-2.4.1

4. $./configure

5. $make

6. $make check

7. $sudo make install

8. $which protoc

9. $protoc --version

 

Install Tensorflow object detection API

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

Protocol buffer compile 

1. go to the directory where API is installed 

$cd models\research\object_detection

 

2. compile 

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

 

3. configure path 

$vi ~/.bash_rc

export PYTHONPATH=$PYTHONPATH:/PATH-TO/models/research:/PATH-TO/models/research/slim

$ source ~/.bash_rc

 

4. test 

$python model_builder_test.py 

 

if you see some errors, try : 

$sudo pip3 install absl-py

$sudo pip3 install google

$sudo pip3 install protobuf

$sudo pip3 install six

$brew install tensorflow

$pip3 install tensorflow-object-detection-api --user

$xcode-select --install

 

 

Tutorial  (Demo) 

models/research/object_detection/object_detection_tutorial.ipynb

 

Application 

1) add your images 

add your test image in the ~/research/object_detection/test_images with the format of image{number}.jpg

change the TEST_IMAGE_PATHS range in Detectuon code block

 

2) use different pretrained models

download the model in github repository : 

https://github.com/tensorflow/models/blob/master/research/object_detection/g3doc/tf2_detection_zoo.md

 

unzip the model and locate it to ~/models/research/object_detection/{model_folder_name}

/frozen_inference_graph.pb

 

change the MODEL_NAME in Variables block 

 

3) create own labeling in the image 

LabelImg 

https://github.com/heartexlabs/labelImg

 

list of labeled image open dataset : 

  • voc2012
  • coco
  • imageNet
  • Open Image Dataset V4