def save_im(im, save_path, transpose=False, check_bound=False): """ im: (1) shape [3, H, W], transpose should be True (2) shape [H, W, 3], transpose should be False (3) shape [H, W], transpose should be False """ may_make_dir(ospdn(save_path)) if transpose: im = im.transpose(1, 2, 0) if check_bound: im = im.clip(0, 255) im = im.astype(np.uint8) mode = 'L' if len(im.shape) == 2 else 'RGB' im = Image.fromarray(im, mode=mode) im.save(save_path)
def save_im(im, save_path): """im: shape [3, H, W]""" may_make_dir(ospdn(save_path)) im = im.transpose(1, 2, 0) Image.fromarray(im).save(save_path)
def insert_package_path(): """This init_path.py should be placed at `${PROJECT_DIR}/package/utils/init_path.py`. Here we add `${PROJECT_DIR}/package` to `sys.path`. If you want to move this file to other places, remember to change the following path to insert. """ sys.path.insert(0, ospdn(ospdn(ospdn(ospap(__file__)))))
from os.path import dirname as ospdn from os.path import abspath as ospap from os.path import join as ospj import sys sys.path.insert(0, ospj(ospdn(ospdn(ospdn(ospap(__file__)))), 'cocoapi/PythonAPI')) import pycocotools.mask as mask_util import numpy as np def GetDensePoseMask(Polys): MaskGen = np.zeros([256,256]) for i in range(1,15): if(Polys[i-1]): current_mask = mask_util.decode(Polys[i-1]) MaskGen[current_mask>0] = i return MaskGen