AI 그게 뭔데
끄적끄적 개발일지
AI 그게 뭔데
전체 방문자
오늘
어제
  • 분류 전체보기 (342)
    • 논문 (5)
    • DL(Deep-Learning) (34)
      • 개념 (14)
      • Python 기초 (14)
      • Tensorflow (6)
      • Pytorch (0)
    • NLP (10)
    • OpenCV (53)
    • DevOps (10)
      • AWS (2)
      • Docker & Kubernetes (4)
      • Spark (3)
      • SQL (1)
    • MacOS (1)
    • React-Native (2)
    • BI (3)
      • GA(Google Analytics) (3)
      • Tableau (0)
    • 알고리즘 (221)
      • 백준 (76)
      • 프로그래머스 (108)
      • 기타 알고리즘 (37)

인기 글

태그

  • 연습문제
  • 프로그래머스
  • 파이썬
  • OpenCV
  • level1
  • 백준
  • 이코테
  • LEVEL2
  • Python
  • 알고리즘

최근 글

hELLO · Designed By 정상우.
AI 그게 뭔데

끄적끄적 개발일지

카테고리 없음

Labelme2YOLO

2022. 2. 25. 11:55

YOLO를 학습하기 위해서 라벨링은 아래의 형태를 갖추고 있어야 한다.

 

2  0.099252  0.561545  0.033488  0.168367

라벨의 이름(번호), center_x, center_y, width, height 로 이루어진 txt파일로 저장되야한다.

 

Labelme를 이용하여 Box annotation을 했을 경우,

 

"shapes": [{
    "label": "1",
    "line_color": null,
    "fill_color": null,
    "points": [[447, 287], [381, 267]],
    "shape_type": "rectangle"
}]

(min_x, min_y), (max_x, max_y) 의 값으로 라벨링이 되어 json파일로 저장이 된다.

 

따라서 Labelme json 파일을 YOLO 라벨링 형식으로 변환해줘야 한다.

아래의 사이트를 참고해서 변환해주면 된다.

 

GitHub - rooneysh/Labelme2YOLO: Help converting LabelMe Annotation Tool JSON format to YOLO text file format. If you've already

Help converting LabelMe Annotation Tool JSON format to YOLO text file format. If you've already marked your segmentation dataset by LabelMe, it's easy to use this tool to help converting to...

github.com

 

 

 

만약 한장의 이미지일 경우 아래의 코드로 진행할 수 있다

import json
    
def convert(size, box):
    dw = 1./size[0]
    dh = 1./size[1]
    x = (box[0] + box[1])/2.0
    y = (box[2] + box[3])/2.0
    w = box[1] - box[0]
    h = box[3] - box[2]
    x = x*dw
    w = w*dw
    y = y*dh
    h = h*dh
    return (x,y,w,h)

im=Image.open(img_path)
w= int(im.size[0])
h= int(im.size[1])


with open("labelme.json", "r") as json_file:
    json_data = json.load(json_file)

xmin, ymin = json_data['shapes'][0]['points'][0]
xmax, ymax = json_data['shapes'][0]['points'][1]

print(xmin, xmax, ymin, ymax) # define your x,y coordinates (Labelme)

b = (xmin, xmax, ymin, ymax)

yolo = convert((w,h), b)

 

 

 

    AI 그게 뭔데
    AI 그게 뭔데
    공부와 개발 그리고 AI가 약간 첨가된 흔적 남기기

    티스토리툴바