Example #1
0
def read_seg(seg_dir):
    seg = Image.open(seg_dir)
    h, w = seg.size
    if (len(args.scale_size) == 1):
        if (h > w):
            tw = args.scale_size[0]
            th = (tw * h) / w
            th = int((th // 64) * 64)
        else:
            th = args.scale_size[0]
            tw = (th * w) / h
            tw = int((tw // 64) * 64)
    else:
        tw = args.scale_size[1]
        th = args.scale_size[0]
    seg = np.asarray(seg).reshape((w, h, 1))
    seg = np.squeeze(seg)
    seg = scipy.misc.imresize(seg, (tw // 8, th // 8), "nearest", mode="F")

    t = []
    t.extend([transforms.ToTensor()])
    trans = transforms.Compose(t)
    pair = [seg, seg]
    transformed = list(trans(*pair))
    seg = transformed[0]
    return to_one_hot(seg)
Example #2
0
def read_seg(seg_dir, scale_size):
    seg = Image.open(seg_dir)
    # seg_im = np.array(seg.getpalette()).reshape((-1,3))
    # seg_cv = cv2.imread(seg_dir)
    h,w = seg.size
    if(len(scale_size) == 1):
    	if(h > w):
    		tw = scale_size[0]
    		th = (tw * h) / w
    		th = int((th // 64) * 64)
    	else:
    		th = scale_size[0]
    		tw = (th * w) / h
    		tw = int((tw // 64) * 64)
    else:
    	tw = scale_size[1]
    	th = scale_size[0]

    seg = np.asarray(seg).reshape((w,h,1))
    seg_ori = np.squeeze(seg)
    small_seg = scipy.misc.imresize(seg_ori, (tw//8, th//8),"nearest",mode="F")  
    large_seg = scipy.misc.imresize(seg_ori, (tw,th),"nearest",mode="F")

    t = []
    t.extend([transforms.ToTensor()])
    trans = transforms.Compose(t)
    pair = [large_seg, small_seg]
    transformed = list(trans(*pair))
    large_seg = transformed[0]
    small_seg = transformed[1]
    return to_one_hot(large_seg), to_one_hot(small_seg), seg_ori
Example #3
0
def create_transforms():
    normalize = transforms.Normalize(mean=(128, 128, 128), std=(128, 128, 128))
    t = []
    t.extend([transforms.ToTensor(), normalize])
    return transforms.Compose(t)