def vis_mask(sub_dir, split, num=10, save_dir='', num_parts=14): im_files = get_im_names(osp.join(root_dir, 'images', split), pattern='*.jpg', return_np=False, return_path=True) mask_files = get_im_names(osp.join(root_dir, sub_dir, split), pattern='*.png', return_np=False, return_path=True) im_files.sort() mask_files.sort() assert len(im_files) == len(mask_files) assert all([ osp.basename(im_f)[:-4] == osp.basename(mask_f)[:-4] for im_f, mask_f in zip(im_files, mask_files) ]) for im_f, mask_f in list(zip(im_files, mask_files))[:num]: for vis_func, save_sub_dir in zip( [vis_mask_, vis_mask_each_part_], ['all_on_one_im', 'one_im_per_mask']): vis_func( read_im(im_f, convert_rgb=True, resize_h_w=None, transpose=False), read_im(mask_f, convert_rgb=False, resize_h_w=None, transpose=False), osp.join(save_dir, save_sub_dir, osp.basename(im_f)), num_parts)
def check_mask_value(sub_dir, max_v, split): mask_files = get_im_names(osp.join(root_dir, sub_dir, split), pattern='*.png', return_np=False, return_path=True) for mf in mask_files: check_mask_value_(mf, max_v)
def print_num_ims(sub_dir, split, pattern): im_dir = osp.join(root_dir, sub_dir, split) im_names = get_im_names(im_dir, pattern=pattern, return_np=False, return_path=True) print('{} {} images in {}, {}'.format(len(im_names), split, im_dir, pattern))
def check_mask_value(split): """To make sure saving and loading mask images are correct.""" mask_files = get_im_names(osp.join(save_root_dir, mask_dir, split), pattern='*.png', return_np=False, return_path=True) for mf in mask_files: mask = read_im(mf, convert_rgb=False, resize_h_w=None, transpose=False) check_mask_value_(mask)
def fuse_parts(split): mask_files = get_im_names(osp.join(root_dir, ori_mask_dir, split), pattern='*.png', return_np=False, return_path=True) mask_files.sort() for mask_f in mask_files: fuse_parts_( mask_f, osp.join(root_dir, new_mask_dir, split, osp.basename(mask_f)))
def vis_mask(split, num=10, save_dir=''): im_files = get_im_names(osp.join(save_root_dir, 'images', split), pattern='*.jpg', return_np=False, return_path=True) mask_files = get_im_names(osp.join(save_root_dir, mask_dir, split), pattern='*.png', return_np=False, return_path=True) im_files.sort() mask_files.sort() assert len(im_files) == len(mask_files) assert all([ osp.basename(im_f)[:-4] == osp.basename(mask_f)[:-4] for im_f, mask_f in zip(im_files, mask_files) ]) for im_f, mask_f in list(zip(im_files, mask_files))[:num]: vis_mask_( read_im(im_f, convert_rgb=True, resize_h_w=None, transpose=False), read_im(mask_f, convert_rgb=False, resize_h_w=None, transpose=False), osp.join(save_dir, osp.basename(im_f)))