์๋ ๋ํ ํธ๋ก ,
์ต๊ทผ์ Detectron์ ์คํํ๊ธฐ ์ํด ์ฌ์ฉ์ ์ง์ coco ๋ฐ์ดํฐ๋ฅผ ์ถ๊ฐํ๋ ค๊ณ ํ๋๋ฐ ๋ค์๊ณผ ๊ฐ์ ๋ฌธ์ ๊ฐ ๋ฐ์ํ์ต๋๋ค.
(1) ์๋์ ๊ฐ์ coco ๋ฐ์ดํฐ์ "๋ถํ ",
{ "์ธ๊ทธ๋จผํธ": [[ 499.71, 397.28, ...... 342.71, 172.31 ]] , "area": โโ43466.12825, "iscrowd": 0, "image_id": 182155, "bbox": [338.89, 51.69, 205.82, 367.61], "category_id": 1, "id": 1248258},
{ "segmentation": { "counts": [66916, 6, 587, ..... 1, 114303], "size": [594, 640] }, "area": โโ6197, "iscrowd": 1, "image_id": 284445, "bbox": [112, 322, 335, 94], "category_id": 1, "id": 9.001002844e + 11},
'์ธ๊ทธ๋จผํธ'์ ์ฒซ ๋ฒ์งธ ํ์์ ๋ค๊ฐํ์ด๊ณ ๋ ๋ฒ์งธ ํ์์ RLE ํ์์ ์ธ์ฝ๋ฉ / ๋์ฝ๋ฉํด์ผํฉ๋๋ค.
์์ ํ์์ Detectron์์ ์คํํ ์ ์์ต๋๋ค.
(2) ์๋ก์ด ์นดํ
๊ณ ๋ฆฌ๋ฅผ ์ถ๊ฐํ๊ณ coco api encode () / decode () ๋ง์คํฌ๋ฅผ ํตํด "๋ถํ "ํ๋์ ๋ํ ์๋ก์ด RLE ํ์์ ์์ฑํ์ต๋๋ค.
๋๋ ์ด์ ๊ฐ์ ๋ฐ์ดํฐ๋ฅผ ์์ฑํ์ต๋๋ค.
"๋ถํ ": [{ "์นด์ดํธ" "= MNG 1fb02O1O1O001N2O001O1O0O2O1O1O001N2O001O1O0O2O1O001O1O1O010000O01000O010000O01000O01000O01000O01N2N2M2O2N2N1O2N2O001O10O B000O10O1O001 ^ OQ ^ O9Pb0EQ ^ O; Wb0OO01O1O1O001O1N2N`jT3?", "ํฌ๊ธฐ": 600,1000]}]
๊ตต๊ฒ ํ์๋ ๋ฌธ์๋ ์๋ coco "์ธ๊ทธ๋ฉํ ์ด์ "json ํ์๊ณผ ๋ค๋ฅด์ง๋ง, MatterPort์ Mask-RCNN ๊ตฌํ์์ ์คํํ ์ ์์ต๋๋ค.
๋ํ ๋ด ์๊ตฌ ์ฌํญ์ ์ถฉ์กฑ์ํค๊ธฐ ์ํด ์ผ๋ถ Detectron์ ์ฝ๋๋ฅผ ์์ ํ๋ ค๊ณ ํ์ง๋ง ๋ง์ ์ฝ๋๋ฅผ ๋ณ๊ฒฝํด์ผํ๋ฏ๋ก ๋งค์ฐ ์ด๋ ต์ต๋๋ค.
๋ด ์ฌ์ฉ์ ์ง์ ๋ฐ์ดํฐ๋ฅผ ์คํํ๊ธฐ์ํ ๋ช ๊ฐ์ง ์ ์์ ํด์ฃผ์๊ฒ ์ต๋๊น?
๊ฐ์ฌ.
๋น์ทํ ๋ฌธ์ ๊ฐ์์์ต๋๋ค. lib / utils / segms.py์ ์ผ๋ถ ํจ์๋ ์ธ๊ทธ๋จผํธ๊ฐ "ํด๋ฆฌ"ํ์์ผ๋ก๋์ด ์๊ณ RLE์์ ์ ๊ณต ๋ ๋ ์ค๋จ ๋ ๊ฒ์ผ๋ก ์์ํฉ๋๋ค.
๋ถํธํ์ง๋ง ํผ์กํ์ง ์์ ์ง์ญ (iscrowd = 0) ์ฌ์์ ๋ถํฉํ๋ ๊ฒ ๊ฐ์ต๋๋ค.
์ธ๋ถํ ํ์์ ์ธ์คํด์ค๊ฐ ๋จ์ผ ๊ฐ์ฒด (ํด๋ฆฌ๊ณค์ด ์ฌ์ฉ๋๋ ๊ฒฝ์ฐ iscrowd = 0) ๋๋ ๊ฐ์ฒด ์ปฌ๋ ์ (RLE์ด ์ฌ์ฉ๋๋ ๊ฒฝ์ฐ iscrowd = 1)์ ๋ํ๋ด๋ ์ง ์ฌ๋ถ์ ๋ฐ๋ผ ๋ค๋ฆ ๋๋ค.
[1] http://cocodataset.org/#download , ์น์ "4.1. ๊ฐ์ฒด ์ธ์คํด์ค ์ฃผ์"
๋๋ฅผ์ํ ํด๊ฒฐ ๋ฐฉ๋ฒ์ ๋ณธ์ง์ ์ผ๋ก (x, y) ๊ผญ์ง์ ๋ชฉ๋ก ์ธ "poly"ํ์์ผ๋ก ๋ณํํ๋ ๊ฒ์ด ์์ต๋๋ค.
-๋ ์ค.
2018 ๋ 2 ์ 2 ์ผ 06:41์ Hu Xingui [email protected] ์ ๋ค์๊ณผ ๊ฐ์ด ์ผ์ต๋๋ค.
์๋ ๋ํ ํธ๋ก ,
์ต๊ทผ์ Detectron์ ์คํํ๊ธฐ ์ํด ์ฌ์ฉ์ ์ง์ coco ๋ฐ์ดํฐ๋ฅผ ์ถ๊ฐํ๋ ค๊ณ ํ๋๋ฐ ๋ค์๊ณผ ๊ฐ์ ๋ฌธ์ ๊ฐ ๋ฐ์ํ์ต๋๋ค.
(1) ์๋์ ๊ฐ์ coco ๋ฐ์ดํฐ์ "๋ถํ ",{ "์ธ๊ทธ๋จผํธ": [[499.71, 397.28, ...... 342.71, 172.31]], "area": โโ43466.12825, "iscrowd": 0, "image_id": 182155, "bbox": [338.89, 51.69, 205.82, 367.61], "category_id": 1, "id": 1248258},
{ "segmentation": { "counts": [66916, 6, 587, ..... 1, 114303], "size": [594, 640]}, "area": โโ6197, "iscrowd": 1, "image_id": 284445, "bbox": [112, 322, 335, 94], "category_id": 1, "id": 9.001002844e + 11},
'์ธ๊ทธ๋จผํธ'์ ์ฒซ ๋ฒ์งธ ํ์์ ๋ค๊ฐํ์ด๊ณ ๋ ๋ฒ์งธ ํ์์ RLE ํ์์ ์ธ์ฝ๋ฉ / ๋์ฝ๋ฉํด์ผํฉ๋๋ค.์์ ํ์์ Detectron์์ ์คํํ ์ ์์ต๋๋ค.
(2) ์๋ก์ด ์นดํ ๊ณ ๋ฆฌ๋ฅผ ์ถ๊ฐํ๊ณ coco api encode () / decode () ๋ง์คํฌ๋ฅผ ํตํด "๋ถํ "ํ๋์ ๋ํ ์๋ก์ด RLE ํ์์ ์์ฑํ์ต๋๋ค.
๋๋ ์ด์ ๊ฐ์ ๋ฐ์ดํฐ๋ฅผ ์์ฑํ์ต๋๋ค."๋ถํ ": [{ "์นด์ดํธ" "= MNG 1fb02O1O1O001N2O001O1O0O2O1O1O001N2O001O1O0O2O1O001O1O1O010000O01000O010000O01000O01000O01000O01N2N2M2O2N2N1O2N2O001O10O B000O10O1O001 ^ OQ ^ O9Pb0EQ ^ O; Wb0OO01O1O1O001O1N2N`jT3?", "ํฌ๊ธฐ": 600,1000]}]
๊ตต๊ฒ ํ์๋ ๋ฌธ์๋ ์๋ coco "์ธ๊ทธ๋ฉํ ์ด์ "json ํ์๊ณผ ๋ค๋ฅด์ง๋ง, MatterPort์ Mask-RCNN ๊ตฌํ์์ ์คํํ ์ ์์ต๋๋ค.
๋ํ ๋ด ์๊ตฌ ์ฌํญ์ ์ถฉ์กฑ์ํค๊ธฐ ์ํด ์ผ๋ถ Detectron์ ์ฝ๋๋ฅผ ์์ ํ๋ ค๊ณ ํ์ง๋ง ๋ง์ ์ฝ๋๋ฅผ ๋ณ๊ฒฝํด์ผํ๋ฏ๋ก ๋งค์ฐ ์ด๋ ต์ต๋๋ค.
๋ด ์ฌ์ฉ์ ์ง์ ๋ฐ์ดํฐ๋ฅผ ์คํํ๊ธฐ์ํ ๋ช ๊ฐ์ง ์ ์์ ํด์ฃผ์๊ฒ ์ต๋๊น?
๊ฐ์ฌ.
โ
์ด ์ค๋ ๋๋ฅผ ๊ตฌ๋ ํ๊ธฐ ๋๋ฌธ์์ด ๋ฉ์์ง๊ฐ ์ ์ก๋์์ต๋๋ค.
์ด ์ด๋ฉ์ผ์ ์ง์ ๋ต์ฅํ๊ฑฐ๋ GitHub์์ ๋ณด๊ฑฐ๋ ์ค๋ ๋๋ฅผ ์์๊ฑฐํ์ญ์์ค.
@amokeev , "RLE"๋ฅผ "poly"ํ์์ผ๋ก ๋ณํํ์ฌ ํด๊ฒฐ ๋ฐฉ๋ฒ์ผ๋ก
@amokeev , ์ธ๋ถํ์ ์ซ์๊ฐ (x, y) ๊ผญ์ง์ ์ ๋๊น? ์๋ฅผ ๋ค์ด "66916", ๋ง์ ์! RLE ํ์์ ๋ํด "iscrowd"๋ฅผ "1"๋ก ์ค์ ํ์ง๋ง Detectron์์ ์คํํ ์ ์์ต๋๋ค.
์ ๋ poly๋ฅผ [[x1, y1, x2, y2โฆ xN, yN],โฆ [x1, y1, x2, y2โฆ xN, yN]]๊ณผ ๊ฐ์ด ๊ผญ์ง์ ์ผ๋ก ์ ์ ๋ ๋ค๊ฐํ ๋ชฉ๋ก์ผ๋ก ํด์ํฉ๋๋ค. ์ฌ๊ธฐ์ ์ขํ๋ ์ด๋ฏธ์ง์ ๊ฐ์ ํฌ๊ธฐ์
๋๋ค.
์ด๋ ๊ฒ ์ธ์ฝ๋ฉ ๋ ๋ง์คํฌ๋ CocoAPI [1]์ ์ํด ์ฌ๋ฐ๋ฅด๊ฒ ํ์๋ฉ๋๋ค.
๊ทธ๋ฌ๋ "๊ณต์์ ์ธ"๋ต๋ณ์ ์ํ ์ ์์ต๋๋ค.
[1] https://github.com/cocodataset/cocoapi https://github.com/cocodataset/cocoapi
2018 ๋ 2 ์ 2 ์ผ 09:18์ Hu Xingui [email protected] ์ ๋ค์๊ณผ ๊ฐ์ด ์ผ์ต๋๋ค.
@amokeev https://github.com/amokeev , ์ธ๋ถํ์ ์ซ์๊ฐ (x, y) ๊ผญ์ง์ ์ ๋๊น? ์๋ฅผ ๋ค์ด "66916", ๋ง์ ์! RLE ํ์์ ๋ํด "iscrowd"๋ฅผ "1"๋ก ์ค์ ํ์ง๋ง Detectron์์ ์คํํ ์ ์์ต๋๋ค.
โ
๋น์ ์ด ์ธ๊ธ ๋์๊ธฐ ๋๋ฌธ์ ์ด๊ฒ์ ๋ฐ๊ณ ์์ต๋๋ค.
์ด ์ด๋ฉ์ผ์ ์ง์ ๋ต์ฅํ๊ฑฐ๋ GitHub https://github.com/facebookresearch/Detectron/issues/100#issuecomment-362516928 ์์ ๋ณด๊ฑฐ๋ https://github.com/notifications/unsubscribe-auth/AFlh63ObnXg- ์ค๋ ๋๋ฅผ ์์๊ฑฐํฉ๋๋ค.
๋ฟก๋ฟก
๋ง์คํฌ๋ฅผ ํด๋ฆฌ๋ก ๋ณํ ํ ์ ์์ต๋๋ค.
labels_info = []
for mask in mask_list:
# opencv 3.2
mask_new, contours, hierarchy = cv2.findContours((mask).astype(np.uint8), cv2.RETR_TREE,
cv2.CHAIN_APPROX_SIMPLE)
# before opencv 3.2
# contours, hierarchy = cv2.findContours((mask).astype(np.uint8), cv2.RETR_TREE,
# cv2.CHAIN_APPROX_SIMPLE)
segmentation = []
for contour in contours:
contour = contour.flatten().tolist()
# segmentation.append(contour)
if len(contour) > 4:
segmentation.append(contour)
if len(segmentation) == 0:
continue
# get area, bbox, category_id and so on
labels_info.append(
{
"segmentation": segmentation, # poly
"area": area, # segmentation area
"iscrowd": 0,
"image_id": index,
"bbox": [x1, y1, bbox_w, bbox_h],
"category_id": category_id,
"id": label_id
},
)
@amokeev ,
๋ฟก๋ฟก
์ ์ ํด ์ฃผ์
์ ๊ฐ์ฌํฉ๋๋ค.
์๋ ํ ๊ฒ์ด๋ค.
@Sundrops , ๋ณํ ๋ฐฉ๋ฒ์ผ๋ก "poly"๋ชฉ๋ก์ ๊ฒฐ๊ณผ๋ฅผ ์ป์ ์ ์์ต๋๋ค. ๋๋จํ ๊ฐ์ฌํฉ๋๋ค! ๊ทธ๋ฐ๋ฐ๋ COCO json ํ์ผ์ ์ขํ๊ฐ "66916"๋๋ "1"๊ณผ ๊ฐ์ด ํฌ๊ณ ์์ ์ซ์ ์ธ ์ด์ ๋ฅผ ์์ง ๋ชจ๋ฆ ๋๋ค.
@topcomma COCO ์ฃผ์์๋ ๋ ๊ฐ์ง ์ ํ์ ์ธ๋ถํ ์ฃผ์์ด ์์ต๋๋ค.
๋ค๊ฐํ ๋ฐ ์์ถ๋์ง ์์ RLE๋ MaskApi๋ฅผ ์ฌ์ฉํ์ฌ ์์ถ RLE ํ์์ผ๋ก ๋ณํ๋ฉ๋๋ค.
์ปดํฉํธ RLE ํ์ :
๋ถํ ": [{"์นด์ดํธ ""= MNG 1fb02O1O1O001N2O001O1O0O2O1O1O001N2O001O1O0O2O1O001O1O1O010000O01000O010000O01000O01000O01000O01N2N2M2O2N2N1O2N2O001O10O B000O10O1O001 ^ OQ ^ O9Pb0EQ ^ O; Wb0OO01O1O1O001O1N2N`jT3 ","ํฌ๊ธฐ ": [600,1000]}]
@Sundrops ,
ํฐ ๋์์ ์ฃผ์
์ ๊ฐ์ฌํฉ๋๋ค.
์ด์ Detectron์์ ์ฌ์ฉ์ ์ง์ Coco์ ์ ์ฌํ ๋ฐ์ดํฐ๋ฅผ ํ์ต ํ ์ ์์ต๋๋ค.
@topcomma ,
๋๋ u์ ๊ฐ์ ๋ฌธ์ ๊ฐ ์์ต๋๋ค.
Sundrops์ ๋ฐฉ๋ฒ์ผ๋ก ๋ง์คํฌ๋ฅผ ํด๋ฆฌ๋ก ๋ณํํ๋ ํ์ผ์ ์ฐพ์ ์ ์์ต๋๋ค.
์ด๋ค ํ์ผ์ธ์ง ๋ง์ํด ์ฃผ์๊ฒ ์ต๋๊น? ์ ๋ง ๊ฐ์ฌํฉ๋๋ค!
@ lg12170226 ๏ผ
coco stuff (https://github.com/nightrome/cocostuff) ํ์ด์ฌ ์ฝ๋๋ฅผ ์ฐธ์กฐํ์ฌ ์ง์ ๊ตฌํํ ์ ์์ต๋๋ค.
์ฝ๋๋ฒ ์ด์ค์๋ ๊ด๋ จ ์ฃผ์์ ํ์ผ์ด ์์ต๋๋ค.
@topcomma : ์๋ณธ ์ด๋ฏธ์ง์ N
๋ ์ด๋ธ ์ด๋ฏธ์ง๊ฐ ์์ต๋๋ค. ๊ฐ ๋ ์ด๋ธ์ ๋จ์ผ ํ์ผ์ ์ ์ฅ๋๋ฏ๋ก ๋ ์ด๋ธ์ ๋ํ N
์ด๋ฏธ์ง๊ฐ ์์ต๋๋ค. ๋ด ๋ฐ์ดํฐ ์ธํธ์์ Mask RCNN์ ํ๋ จ์ํค๊ณ ์ถ๊ธฐ ๋๋ฌธ์ ๋จผ์ COCO ํ์์ผ๋ก ๋ณํํด์ผํฉ๋๋ค. ์ฝ๋๋ฅผ COCO ์คํ์ผ๋ก ๋ณํํ๋ ๋ฐฉ๋ฒ์ ๊ณต์ ํด ์ฃผ์๊ฒ ์ต๋๊น? ๊ฐ์ฌ
์์ถ ๋ RLE๋ฅผ ํด๋ฆฌ / ์์ถ๋์ง ์์ RLE๋ก ๋ณํํ๋ ๋ฐฉ๋ฒ์ด ์๋์ง ๊ถ๊ธํ์ญ๋๊น?
pycocotools.mask.decode๋ก RLE๋ฅผ ๋์ฝ๋ฉ ํ ํ @realwecan์์ opencv๋ก ๋ค๊ฐํ์ ์์ฑํ๋๋ก ๊ตฌํ์ ํ์ธํ ์ ์์ต๋๋ค.
@hazirbas : ์ฝ๋ ์ฃผ์ ์ ๊ฐ์ฌํฉ๋๋ค. ์ธ์คํด์ค ๋ถํ ์ด ํฌํจ ๋ Davis 2017์ ์ฌ์ฉํ์ง ์๋ ์ด์ ๋ ๋ฌด์์ ๋๊น? ์ด maskrcnn ๊ตฌํ์ ์ฌ์ฉํ๊ธฐ ์ํด ์ฝ๋๋ฅผ ์ฌ์ฉํ์ฌ Davis 2017์ coco ํ์์ผ๋ก ๋ณํ ํ ์ ์์ต๋๊น?
@ John1231983 ๋ถํ ํ์ผ๊ณผ db_info.yml ํ์ผ์ ์ฝ๊ธฐ ์ํด ์คํฌ๋ฆฝํธ๋ฅผ ์ ์ ํ ์์ ํด์ผํฉ๋๋ค. ๋ด ์ฐ๊ตฌ๋ฅผ ์ํด DAVIS 2016์ ํ์ํ์ต๋๋ค.
๋ค๊ฐํ์ ์์ฑํ์ง๋ง, ์ฌ์ฉํ๋ ๋ ๋ค๋ฅธ ๋ฐฉ๋ฒ skimage
๋์ opencv
.
import json
import numpy as np
from pycocotools import mask
from skimage import measure
ground_truth_binary_mask = np.array([[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[ 0, 0, 0, 0, 0, 1, 1, 1, 0, 0],
[ 0, 0, 0, 0, 0, 1, 1, 1, 0, 0],
[ 0, 0, 0, 0, 0, 1, 1, 1, 0, 0],
[ 0, 0, 0, 0, 0, 1, 1, 1, 0, 0],
[ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]], dtype=np.uint8)
fortran_ground_truth_binary_mask = np.asfortranarray(ground_truth_binary_mask)
encoded_ground_truth = mask.encode(fortran_ground_truth_binary_mask)
ground_truth_area = mask.area(encoded_ground_truth)
ground_truth_bounding_box = mask.toBbox(encoded_ground_truth)
contours = measure.find_contours(ground_truth_binary_mask, 0.5)
annotation = {
"segmentation": [],
"area": ground_truth_area.tolist(),
"iscrowd": 0,
"image_id": 123,
"bbox": ground_truth_bounding_box.tolist(),
"category_id": 1,
"id": 1
}
for contour in contours:
contour = np.flip(contour, axis=1)
segmentation = contour.ravel().tolist()
annotation["segmentation"].append(segmentation)
print(json.dumps(annotation, indent=4))
๋ฐ์ด๋๋ฆฌ ๋ง์คํฌ ๋๋ ์ธ์ฝ๋ฉ ๋ RLE๋ฅผ "iscrowd : 1" "counts"ํ๋์์ ์ฌ์ฉํ๊ธฐ ์ํด ์์ถ๋์ง ์์ RLE๋ก ์ด๋ป๊ฒ ๋ณํํฉ๋๊น?
skimage๋ฅผ ์ฌ์ฉํ๋ ์ฝ๋๋ก @waspinator ์ธ๊ทธ๋ฉํ
์ด์
์ @Sundrops ์ ์ฝ๋์
์ด ๋ ๊ฒฐ๊ณผ๊ฐ ๋ชจ๋ ์ ํํ๊ณ Detectron์์์ด ๋ ๊ฒฐ๊ณผ๋ฅผ ๋ชจ๋ ์ฌ์ฉํ ์ ์์ต๋๊น? ์ ๊ฒ ์กฐ์ธ์ ํด์ฃผ์ธ์, ๊ฐ์ฌํฉ๋๋ค. ํธ์ ๋ด์ ๊ฐ๊ธฐ
skimage์ ํจ๊ป ์ฝ๋๋ฅผ ์ฌ์ฉํ ๊ฒฐ๊ณผ :
{ "๋ถํ "[0.0, 252.00196078431372, 1.0 252.00196078431372, 2.0 252.00196078431372, 3.0 252.00196078431372, 4.0 252.00196078431372, 5.0 252.00196078431372, 6.0 252.00196078431372, 7.0 252.00196078431372, 8.0 252.00196078431372, 9.0 252.00196078431372, 10.0 252.00196078431372 , 11.0, 252.00196078431372, 12.0, 252.00196078431372, 13.0, 252.00196078431372, 14.0, 252.00196078431372, 15.0, 252.00196078431372, 16.0, 252.00196078431372, 17.0, 252.00196078431372, 18.0, 252.00372, 252.00372. , 252.00196078431372, 24.0, 252.00196078431372, 25.0, 252.00196078431372, 26.0, 252.00196078431372, 27.0, 252.00196078431372, 28.0, 252.00196078431372, 29.0, 252.00196078431372, 30.0, 252.001960372, 30.0, 2960,372, 396031784,372,960,31.0, 3,960,372,3,2,960,31.0, 3,960,372,2,960,3 , 36.0, 252.00196078431372, 37.0, 252.00196078431372, 38. 0, 252.00196078431372, 39.0, 252.00196078431372, 40.0, 252.00196078431372, 41.0, 252.00196078431372, 42.0, 252.00196078431372, 43.0, 252.00196078431372, 44.0, 252.00196078431372, 45.0, 252.001960784,960, 2.00,372,496031372,52.00,960,372, 4,253,784,2,960,0,372, 4,253,2,960784,3 252.00196078431372, 51.0, 252.00196078431372, 52.0, 252.00196078431372, 53.0, 252.00196078431372, 54.0, 252.00196078431372, 55.0, 252.00196078431372, 56.0, 252.00196078431372, 57.0, 252.00196078431372, 52.00372784,96078431372, 52.00372, 69.01960372. 63.0, 252.00196078431372, 64.0, 252.00196078431372, 65.0, 252.00196078431372, 66.0, 252.00196078431372, 67.0, 252.00196078431372, 68.0, 252.00196078431372, 69.0, 252.00196078431372, 70.0, 252.001960372,2.00,784,960372, 7,0,372,0,0,784,3,2960,372,3,2,0,0,784,31,372,252.001,960, 72.00,78431,372, 2 252.00196078431372, 76.0, 252.00196 078431372, 77.0, 252.00196078431372, 78.0, 252.00196078431372, 79.0, 252.00196078431372, 80.0, 252.00196078431372, 81.0, 252.00196078431372, 82.0, 252.00196078431372, 83.0, 252.00196078431372, 82.00372. 89.0, 252.00196078431372, 90.0, 252.00196078431372, 91.0, 252.00196078431372, 92.0, 252.00196078431372, 93.0, 252.00196078431372, 93.00196078431372, 252.0, 94.0, 251.00196078431372, 95.0, 251.00196078431372, 96.0 ...
cv2 ๋ฅผ ์ฌ์ฉํ๋
[94, 252, 93, 253, 0, 253, 0, 286, 188, 286, 188, 269, 187, 268, 187, 252]
๋ด๊ฐ CV2 ๊ตฌํ @Sundrops์ ํ ์คํธํ์ง๋ง,ํ์ง ์์ @Kongsea ๊ธฐ๋ณธ์ ์ธ ์์ด๋์ด๋ ๋์ผํด์ผํฉ๋๋ค. ๋ชจ์์ ์ค๋ช ํ๋ ๋ฐ ์ฌ์ฉํ ์์๋ ์ ์ธํธ๊ฐ ๋ฌดํํ ์์ผ๋ฏ๋ก ๋ค๋ฅธ ๊ฒฐ๊ณผ๋ฅผ ์์ฑํฉ๋๋ค. ๊ทธ๋ฌ๋ ๊ทธ๋ ์ง ์์ผ๋ฉด ๋ ๋ค ์๋ํด์ผํฉ๋๋ค. cv2๊ฐ ์ค์น๋์ด ์์ง ์์์ ํ์ํ์ง ์์ ๊ฒ์ ์์ฑํ์ต๋๋ค.
@Kongsea @waspinator ๋ด ์ฝ๋๋ฅผ ํ ์คํธํ์ต๋๋ค. ํจ๊ณผ๊ฐ์๋ค.
@Sundrops @waspinator ๊ฐ์ฌํฉ๋๋ค.
๋๋ ์๋ ํ ๊ฒ์ด๋ค.
@waspinator ๋ถํ ํด๋ฆฌ ๋ฒํ ์ค๋ฅผ RLE๋ก ๋ณํํ๋ ๋ฐฉ๋ฒ์ด ์์ต๋๊น? ๋ด ๋ชฉํ๋ iscrowd = 1์ ๋๋ค.
@Sundrops ์ฝ๋์์์ด ๋ถ๋ถ์ ์ฃผ์์ผ๋ก
# if len(contour) > 4:
# segmentation.append(contour)
# if len(segmentation) == 0:
# continue
์ฐ๋ฆฌ๋ ์ ๋ง๋ก ๊ทธ๋ฌํ ์ฌ๊ฑด์ ์ฒ๋ฆฌํด์ผํฉ๋๋ค.
@ Yuliang-Zou Detectron์ ์ค๊ณฝ์ ์ ์ฌ์ฉํ๋ ๊ฒฝ์ฐ์ด ๋ถ๋ถ์ ์ฃผ์ ์ฒ๋ฆฌ๋ฅผ ์ ๊ฑฐํด์ผํฉ๋๋ค. Detectron์ len (contour) == 4 ์ผ ๋ ์ฌ๊ฐํ์ผ๋ก ์ฒ๋ฆฌํฉ๋๋ค. ์ด์ ์ฝ๋๋ฅผ ์ ๋ฐ์ดํธํ์ต๋๋ค.
@ Sundrops ๊ฐ์ฌํฉ๋๋ค. ํ์ง๋ง ์ฐ๋ฆฌ๋ ์ฌ์ ํ len(contour)==2
์ฒ๋ฆฌํด์ผํฉ๋๋ค.
@ Yuliang-Zou ์,ํ์ง๋ง if len(contour) > 4:
์ฝ๋์๋ len(contour)==2
๋ฐ len(contour)==4
ํธ๋ค์ด ์์ต๋๋ค.
@Sundrops , ๊ฐ์ฌํฉ๋๋ค!
์ ๋ COCO ์คํ์ผ ๋ฐ์ดํฐ ์ธํธ๋ฅผ ๋ง๋๋ ๋ฐ ๋์์ด๋๋ ๋ผ์ด๋ธ๋ฌ๋ฆฌ์ ๊ธฐ์ฌ๋ฅผ ์์ฑํ์ต๋๋ค.
@Sundrops & @topcomma ๋ด ์ฃผ์์ด ๋ง์คํฌ์์ด ์ธ๋ถํ๋ฅผ ํฌํจํ๊ธฐ ๋๋ฌธ์ ์ฃผ์์ด ๋ฌ๋ฆฐ ๋ฐ์ดํฐ๋ฅผ pycocotols์๋ก๋ํ๋ ๋ฐ ๋ฌธ์ ๊ฐ ์์ต๋๋ค. pycocotools์์ ๋ง์คํฌ์์ด ์ฃผ์์ ์๊ฐํํ๋ ๋ฐฉ๋ฒ์ ๋ํ ์์ด๋์ด๊ฐ ์์ต๋๊น?
๋ฟก๋ฟก
ann : {
"๋ถํ ": [
[312.29, 562.89, 402.25, 511.49, 400.96, 425.38, 398.39, 372.69, 388.11, 332.85, 318.71, 325.14, 295.58, 305.86, 269.88, 314.86, 258.31, 337.99, 217.19, 321.29, 217.19, 321.29, 217.19, 321.29 , 358.55, 159.36, 377.83, 116.95, 421.53, 167.07, 499.92, 232.61, 560.32, 300.72, 571.89]
],
"๋ฉด์ ": 54652.9556,
"iscrowd": 0,
"image_id": 480023,
"bbox": [116.95, 305.86, 285.3, 266.03],
"category_id": 58,
"id": 86
}
coco-api์์ mask.py๋ก ๋ฉด์ ์ ์ด๋ป๊ฒ ๊ณ์ฐํ ์ ์์ต๋๊น? ๊ฐ์ฌํฉ๋๋ค.
๋ด ์ฝ๋๋ ๋ค์๊ณผ ๊ฐ์ง๋ง ์ค๋ฅ์
๋๋ค.
์ธ๋ถํ = ann [ '์ธ๋ถํ']
bimask = np.array (segmentation, dtype = np.uint8, order = 'F')
print ( "bimask :", bimask)
rleObjs = mask.encode (bimask)
print ( "rleObjs :", rleObjs)
์์ญ = mask.area (rleObjs)
print ( "area :", ๋ฉด์ )
๋ฟก๋ฟก
cv2๋ฅผ ์ฌ์ฉํด ๋ณผ ์๋ ์์ง๋ง ์ณ์์ง๋ ๋ชจ๋ฅด๊ฒ ์ต๋๋ค. Python ๋ฐ OpenCV๋ฅผ ์ฌ์ฉํ์ฌ ์ด๋ฏธ์ง์์ ์ค๊ณฝ์ ์ ๊ฑฐ ์ ์์ผ๋ฟ์
๋๋ค.
def is_contour_bad(c):
# approximate the contour
peri = cv2.arcLength(c, True)
approx = cv2.approxPolyDP(c, 0.02 * peri, True)
# return True if it is not a rectangle
return not len(approx) == 4
image = cv2.imread('xx.jpg')
contours = ann['segmentation']
mask = np.ones(image.shape[:2], dtype="uint8") * 255
# loop over the contours
for c in contours:
# if the contour is not a rectangle, draw it on the mask
if is_contour_bad(c):
cv2.drawContours(mask, [c], -1, 0, -1)
area = (mask==0).sum()
@Sundrops @waspinator ์ง๋ฌธ์ด ์์ต๋๋ค. ์๋ ๊ฐ์ฒด ๋ง์คํฌ์ ํฐ ๊ตฌ๋ฉ์ด์๋ ๊ฒฝ์ฐ ๋ค๊ฐํ์ผ๋ก ๋ณํ ํ ๋ ์ด๋ป๊ฒ ๋ค์ ์ฌ๋ฐ๋ฅด๊ฒ ๋ณํํด์ผํฉ๋๊น? coco API์ ๋์ฝ๋ฉ ๋ฐ ๋ณํฉ ๊ธฐ๋ฅ์ ๊ตฌ๋ฉ์ ๊ฐ์ฒด์ ์ผ๋ถ๋ก ์ทจ๊ธํ๋ฏ๋ก ๋ค์ ๋ณํํ๋ฉด ๊ตฌ๋ฉ์ด ๋ง์คํฌ๊ฐ๋ฉ๋๋ค. ์ด ๊ฒฝ์ฐ ์ด๋ป๊ฒํด์ผํฉ๋๊น?
@ wangg12 ๋ด๊ฐ ์๋ ํ COCO์๋ ๊ตฌ๋ฉ์ ์ธ์ฝ๋ฉํ๋ ๊ธฐ๋ณธ ๋ฐฉ๋ฒ์ด ์์ต๋๋ค.
for contour in contours:
contour = contour.flatten().tolist()
segmentation.append(contour)
if len(contour) > 4:
segmentation.append(contour)
์๋ ํ์ธ์ @Sundrops , ๊ทํ์ ์ฝ๋์ ๋ํด ์ง์ฌ์ผ๋ก ๊ฐ์ฌ๋๋ฆฝ๋๋ค. ์ ๋ Detectron์ ์ด๋ณด์์ ๋๋ค. ์ปจํฌ์ด์ ๊ธธ์ด (๋ชฉ๋ก)๊ฐ 4๋ณด๋ค ์ปค์ผํ๋ ์ด์ , ์ฆ ๊ธธ์ด๊ฐ 4๋ณด๋ค ์์ ๋ ๋ชจ๋ธ์ ์ด๋ค ์ผ์ด ๋ฐ์ํ๋์ง ํผ๋์ค๋ฌ์ํฉ๋๋ค. ๋ต๋ณ ์ค ํ๋๊ฐ Detectron์ด ์ง์ฌ๊ฐํ. ์ ์๊ฐ์๋ ์ง์ฌ๊ฐํ ๋ชจ์์ ๋ฌผ์ฒด๊ฐ์์ ์ ์์ผ๋ ๊ด์ฐฎ๋ค๊ณ ์๊ฐํฉ๋๋ค. ๋ํ ํ ๋ฒ์ ๋ ๋ฒ ์ค๊ณฝ์ ์ ์ถ๊ฐํ๋์ง ๊ถ๊ธํฉ๋๋ค. ์ฌ๋ฐ๋ฅธ ์ฝ๋๊ฐ๋์ด์ผํ๋ค๊ณ ์๊ฐํฉ๋๋ค.
for contour in contours:
contour = contour.flatten().tolist()
if len(contour) > 4:
segmentation.append(contour)
์ ์๊ฒ ๋ช ๊ฐ์ง ์ ์์ ํด์ฃผ์๋ฉด ๋๋จํ ๊ฐ์ฌํ๊ฒ ์ต๋๋ค. ์ ๋ง ๊ณ ๋ง์ต๋๋ค!
@BobZhangHT ์, ํ ๋ฒ์ ํ ๋ฒ ์ค๊ณฝ์ ์ถ๊ฐํด์ผํฉ๋๋ค.
์ฒซ ๋ฒ์งธ ์ง๋ฌธ์์ len (ann [ 'segmentation'] [0]) == 4์ด๋ฉด cocoapi๋ ๋ชจ๋ ์ง์ฌ๊ฐํ์ด๋ผ๊ณ ๊ฐ์ ํฉ๋๋ค.
# cocoapi/PythonAPI/pycocotools/coco.py
def annToRLE(self, ann):
t = self.imgs[ann['image_id']]
h, w = t['height'], t['width']
segm = ann['segmentation']
if type(segm) == list:
rles = maskUtils.frPyObjects(segm, h, w)
rle = maskUtils.merge(rles)
......
# cocoapi/PythonAPI/pycocotools/_mask.pyx
def frPyObjects(pyobj, h, w):
# encode rle from a list of python objects
if type(pyobj) == np.ndarray:
objs = frBbox(pyobj, h, w)
elif type(pyobj) == list and len(pyobj[0]) == 4:
objs = frBbox(pyobj, h, w)
elif type(pyobj) == list and len(pyobj[0]) > 4:
objs = frPoly(pyobj, h, w)
......
@Sundrops ๋ต์ฅ์ ๋ณด๋ด ์ฃผ์ ์ ๊ฐ์ฌํฉ๋๋ค!
์ ๋ poly๋ฅผ [[x1, y1, x2, y2โฆ xN, yN],โฆ [x1, y1, x2, y2โฆ xN, yN]]๊ณผ ๊ฐ์ด ๊ผญ์ง์ ์ผ๋ก ์ ์ ๋ ๋ค๊ฐํ ๋ชฉ๋ก์ผ๋ก ํด์ํฉ๋๋ค. ์ฌ๊ธฐ์ ์ขํ๋ ์ด๋ฏธ์ง์ ๊ฐ์ ํฌ๊ธฐ์ ๋๋ค. ์ด๋ ๊ฒ ์ธ์ฝ๋ฉ ๋ ๋ง์คํฌ๋ CocoAPI [1]์ ์ํด ์ฌ๋ฐ๋ฅด๊ฒ ํ์๋์ง๋ง "๊ณต์์ ์ธ"๋ต๋ณ์ ์ป๊ณ ์ถ์ ์๋ ์์ต๋๋ค. [1] https://github.com/cocodataset/cocoapi https://github.com/cocodataset/cocoapi
โฆ
2018 ๋ 2 ์ 2 ์ผ 09:18์ Hu Xingui @ . * > ์ผ์ต๋๋ค : @amokeev https://github.com/amokeev , ์ธ๋ถํ์ ์ซ์๊ฐ (x, y) ๊ผญ์ง์ ์ ๋๊น? ์๋ฅผ ๋ค์ด "66916", ๋ง์ ์! RLE ํ์์ ๋ํด "iscrowd"๋ฅผ "1"๋ก ์ค์ ํ์ง๋ง Detectron์์ ์คํํ ์ ์์ต๋๋ค. โ ๊ทํ๊ฐ ๋ฉ์ ๋์๊ธฐ ๋๋ฌธ์ ์์ ํ ๊ฒ์ ๋๋ค. ์ด ์ด๋ฉ์ผ์ ์ง์ ํ์ ํ๊ฑฐ๋ GitHub < # 100 (comment) >์์ ๋ณด๊ฑฐ๋ https://github.com/notifications/unsubscribe-auth/AFlh63ObnXg-DcaDKwIi3pB4Ppig464Hks5tQsTkgaJpZM4R2tN3 ์ค๋ ๋๋ฅผ ์์๊ฑฐ
matterport / MaskRCNN์ด ๋ค๊ฐํ์์๋ง ์๋ํ๊ธฐ ๋๋ฌธ์ "iscrowd"๊ฐ "1"์ผ ๋ RLE๋ฅผ ๋ค๊ฐํ์ผ๋ก ๋ณํํ๋ ค๋ฉด ์ด๋ป๊ฒํด์ผํฉ๋๊น? @amokeev. pycococreator๋ฅผ ์ฌ์ฉํ์ฌ ๋ง๋ coco ๋ฐ์ดํฐ ์ธํธ์ ํจ๊ป maskRCNN์ matterport ๊ตฌํ์ ์ฌ์ฉํ๊ณ ์ถ์ต๋๋ค.
๊ฐ์ฅ ์ ์ฉํ ๋๊ธ
๋ฟก๋ฟก
๋ง์คํฌ๋ฅผ ํด๋ฆฌ๋ก ๋ณํ ํ ์ ์์ต๋๋ค.