cp-vton을 새로운 이미지들로 training 시키려니 많은 문제가 생겼다.
우선 segmentation 파일을 만들어야하는데.
이건 내가 좌표별(json)로 polygon을 사용해서 각 segment 별로 색상을 부여한것이다. 하지만, label(classification)이 없기 때문에 pixel 별로 어느 class에 속하는지 알려주는 데이터를 만들어보자.
이미지의 color map 을 matplotlib 을 통해 찾아보자.
근데 정확하지가 않음. 왜냐면 convert P , ADAPTIVE 사용해서 다시 하는것보다. 그냥 내가 지정해놓은 색깔가지고 segmentation을 labeling하면됌
from PIL import Image
import numpy as npim = Image.open('1008_1008_720_B_B022_B022_000.png')
im_array = np.array(im)segment_dict = {"hair":(255,0,0),
"hat":(255,255,0),
"face":(0,0,255),
"neck":(0,24,24),
"outer_lsleeve":(96,0,90),
"outer_rsleeve":(29,96,0),
"outer_torso":(86,96,0),
"inner_torso":(255,96,0),
"inner_rsleeve":(155,96,0),
"inner_lsleeve":(0,128,128),
"right_arm":(48,168,216),
"left_arm":(0,255,255),
"pants_hip":(0,96,96),
"pants_rsleeve":(0,76,76),
"pants_lsleeve":(0,56,56),
"skirt":(0,16,96),
"right_leg":(128,0,0),
"left_leg":(165,42,42),
"right_shoe":(96,69,0),
"left_shoe":(70,0,96)}segment_label = {"hair":1,
"hat":2,
"face":3,
"neck":4,
"outer_lsleeve":5,
"outer_rsleeve":6,
"outer_torso":7,
"inner_torso":8,
"inner_rsleeve":9,
"inner_lsleeve":10,
"right_arm":11,
"left_arm":12,
"pants_hip":13,
"pants_rsleeve":14,
"pants_lsleeve":15,
"skirt":16,
"right_leg":17,
"left_leg":18,
"right_shoe":19,
"left_shoe":20}def _indice(seg):
indices = np.where((im_array == segment_dict[seg] ).all(axis=-1))
coordinate_list = list(zip(indices[0],indices[1]))
return coordinate_list#open new image
im2 = Image.new('P',im.size)
im2_array = np.array(im2)for key in segment_dict.keys():
print(key)
seg_list = _indice(key)for i in range(0, len(seg_list)):
y_axis = seg_list[i][0]
x_axis = seg_list[i][1]
print(x_axis,y_axis)
im2_array[y_axis][x_axis] = segment_label[key]
코드더럽긴함;
완성~