JSP's Deep learning

[Deep learning - Obeject Detection] TensorFlow Object Detection API(2) - 커스텀 데이터 셋 생성 본문

Deap learning/Object Detection

[Deep learning - Obeject Detection] TensorFlow Object Detection API(2) - 커스텀 데이터 셋 생성

_JSP_ 2023. 3. 6. 21:46

1. Detection 데이터 만들기

1) labelImg를 이용한 이미지 라벨링

진행순서

  1. labelImg 실행
    • TensorFlow/addons/labelImg 경로로 이동
    • python labelImg.py [이미지 데이터 경로]
      (본문에서는 TensorFlow/workspace/training_demo/images)
  2. 이미지 파일 선택
  3. Ctrl + 마우스 클릭으로 bounding box 지정
  4. Label 입력 or Default label 지정
  5. 저장(본문에서는 TensorFlow/workspace/training_demo/images에 저장)

-> 최종적으로 Image에 대한 box label 정보가 .xml 형태로 저장

labelImg 예시

  • 실행 결과 및 바운딩 박스 표기

  • labelImg로 생성된 .xml 파일 형태

2. 데이터 분리(학습용 및 테스트용)

Script 파일을 이용한 간단 분리

  1. Script 파일 다운로드
  2. Tensorflow/scripts/preprocessing에 저장
  3. Tensorflow/scripts/preprocessing 경로로 이동
  4. Python partition_dataset.py [-h] [-i IMAGEDIR] [-o OUTPUTDIR] [-r RATIO] [-x] 실행
    • -h : help message 출력 옵션
    • -i IMAGEDIR : image data가 있는 폴더 경로 지정
    • -o OUTPUTDIR : train & test data 를 저장할 폴더 경로 지정
    • -r RATIO : 분할 비율 지정(test data 비율)
    • -x : 저장시 .xml 파일도 함께 저장하도록 지정

 

3. Label Map 생성

Labelsinteger values매핑된 Label map을 생성한다.

수기로 파일을 작성하여 TensorFlow/workspace/training_demo/annotations 경로에 예시와 같은 label_map.pbtxt을 저장한다.

  • 예시)

4. TensorFlow Records 생성

Script 파일을 이용하여 TFRecords 파일 생성

  • 스크립트 다운로드 : Download
  • TensorFlow/scripts/preprocessing 경로에 저장
  • TensorFlow/scripts/preprocessing 경로로 이동
  • python generate_tfrecord.py [-h] [-x XML_DIR] [-l LABELS_PATH] [-o OUTPUT_PATH] [-i IMAGE_DIR] [-c CSV_PATH]
    • -h : help message
    • -x XML_DIR : input .xml 파일 저장 경로
    • -l LABELS_PATH : label map(.pbtxt) 파일 저장 경로
    • -o OUTPUT_PATH : .record 파일 저장할 경로
    • -c CSV_PATH : .csv 파일 저장할 경로

참고

[1] https://tensorflow-object-detection-api-tutorial.readthedocs.io/en/latest/training.html

 

Training Custom Object Detector — TensorFlow 2 Object Detection API tutorial documentation

Whether you are using the TensorFlow CPU or GPU variant: In general, even when compared to the best CPUs, almost any GPU graphics card will yield much faster training and detection speeds. As a matter of fact, when I first started I was running TensorFlow

tensorflow-object-detection-api-tutorial.readthedocs.io

 

Comments