yongyong-e

[Tensorflow Object Detection API] 3. Testing your own dataset 본문

머신러닝/Tensorflow - Models

[Tensorflow Object Detection API] 3. Testing your own dataset

Yonghan Kim 2017. 9. 4. 10:49

1) Exporting the Tensorflow Graph

Training후, 생성된 model.ckpt-{CEHCKPOINT_NUMBER}.* 파일들을 inference_graph로 변환하여 학습된 모델을 평가해보자.

# models/object_detection/

python export_inference_graph.py \

--input_type image_tensor \

--pipeline_config_path training/ssd_mobilenet_v1_pets.config \

--trained_checkpoint_prefix training/model.ckpt-{CHECKPOINT_NUMBER} \

--output_directory inference_graph_fish


스크립트 실행 후, 다음과 같이 inference_graph가 생성된 것을 볼 수 있다.


2) Test preparation

이제 test를 위해 models/object_detection/test_images 디렉토리에 test하고 싶은 이미지를 image{NUMBER}.jpg으로 저장하도록 한다.


그리고 object_detection_tutorial.ipynb의 코드 몇몇 부분을 수정하여 test를 해보자.

In[4]: 

# What model to download.
MODEL_NAME = 'inference_graph_fish'
# MODEL_FILE = MODEL_NAME + '.tar.gz'
# DOWNLOAD_BASE = 'http://download.tensorflow.org/models/object_detection/'

# Path to frozen detection graph. This is the actual model that is used for the object detection.
PATH_TO_CKPT = MODEL_NAME + '/frozen_inference_graph.pb'

# List of the strings that is used to add correct label for each box.
PATH_TO_LABELS = os.path.join('data', 'object-detection.pbtxt')

NUM_CLASSES = 1

In[5]: 

Download Model 부분의 코드는 삭제.


In[8]:

# For the sake of simplicity we will use only 2 images:
# image1.jpg
# image2.jpg
# If you want to test the code with your images, just add path to the images to the TEST_IMAGE_PATHS.
PATH_TO_TEST_IMAGES_DIR = 'test_images'
TEST_IMAGE_PATHS = [ os.path.join(PATH_TO_TEST_IMAGES_DIR, 'image{}.jpg'.format(i)) for i in range(3, 6) ]

# Size, in inches, of the output images.
IMAGE_SIZE = (12, 8)


3) Run All

이제 object_detection_tutorial.ipynb를 실행하여 결과를 확인해보자.

     


Comments