https://aifactory.space/task/1952/overview
AI Factory 경진대회
GitHub - qubvel/segmentation_models.pytorch: Segmentation models with pretrained backbones. PyTorch.
annotatoin file은 json 형태로 주어졌고, train, test set이 나뉘어져있다.
train으로 훈련, test로 validation 하여 최종적으로 가장 높은 metric을 갖는 모델을 선택하면 될 듯하다.
json file은 크게 아래와 같이 구성돼있다.
images
file_name
: train_****.PNG (start from 0)width
: various (860 - 1282)height
: various (540 - 720)id
: start from 1annotations
image_id
: same as id of images
segmentation
: value of even index is of x axis, that of odd is of y axis
category_id
: (target)
Generate Masks
import cv2
import numpy as np
import os
%matplotlib inline
import matplotlib.pyplot as plt
import skimage.draw as draw
imgName = _json["images"][16]["file_name"]
imgPath = os.path.join("train_images", imgName)
img = cv2.imread(imgPath)
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
plt.imshow(img)
anns = []
for ann in _json["annotations"]:
if ann["image_id"] == 17:
anns.append(ann)
groundImg = np.zeros(img.shape[:2])
for ann in anns:
polys = []
seg = np.array(ann["segmentation"])
# sequence of (x, y, x, y..) -> (x, y), (x, y)
seg = seg.reshape(int(len(seg)/2), 2)
mask = draw.polygon2mask(groundImg.shape, seg[:, ::-1])
groundImg[mask] = ann["category_id"] / 2
plt.imshow(groundImg, cmap=plt.cm.gray, vmin=0, vmax=1); plt.axis("off")
GitHub - qubvel/segmentation_models.pytorch: Segmentation models with pretrained backbones. PyTorch.
[batch_size, classes, width, height]
<aside> ☝🏻 위 github code는 semantic segmentation이므로 우리가 원하는 결과를 얻기 어려움 따라서 Mask R-CNN 을 이용한 Detectron2 를 사용해본다
</aside>
Detectron2 github