def parse_inst(image_name, devkit_path):
    """
    Get cooresponding masks, boxes, classes according to image name
    Args:
        image_name: input image name
        devkit_path: root dir for devkit SDS
    Returns:
        roi/mask dictionary of this image
    """
    import PIL
    seg_obj_name = os.path.join(devkit_path, 'SegmentationObject', image_name + '.png')
    seg_obj_data = PIL.Image.open(seg_obj_name)
    seg_obj_data = np.array(seg_obj_data.getdata(), np.uint8).reshape(seg_obj_data.size[1], seg_obj_data.size[0])

    seg_cls_name = os.path.join(devkit_path, 'SegmentationClass', image_name + '.png')
    seg_cls_data = PIL.Image.open(seg_cls_name)
    seg_cls_data = np.array(seg_cls_data.getdata(), np.uint8).reshape(seg_cls_data.size[1], seg_cls_data.size[0])

    unique_inst = np.unique(seg_obj_data)
    # delete background pixels
    background_ind = np.where(unique_inst == 0)[0]
    unique_inst = np.delete(unique_inst, background_ind)
    record = []
    for inst_ind in xrange(unique_inst.shape[0]):
        [r, c] = np.where(seg_obj_data == unique_inst[inst_ind])
        mask_bound = np.zeros(4, dtype=int)
        mask_bound[0] = np.min(c)
        mask_bound[1] = np.min(r)
        mask_bound[2] = np.max(c)
        mask_bound[3] = np.max(r)
        mask = seg_obj_data[mask_bound[1]:mask_bound[3]+1, mask_bound[0]:mask_bound[2]+1]
        mask = (mask == unique_inst[inst_ind])
        mask_cls = seg_cls_data[mask_bound[1]:mask_bound[3]+1, mask_bound[0]:mask_bound[2]+1]
        mask_cls = mask_cls[mask]
        num_cls = np.unique(mask_cls)
        assert num_cls.shape[0] == 1
        cur_inst = num_cls[0]
        record.append({
            'mask': mask,
            'mask_cls': cur_inst,
            'mask_bound': mask_bound
        })

    return record

    Get cooresponding masks, boxes, classes according to image name
    Args:
        image_name: input image name
        devkit_path: root dir for devkit SDS
    Returns:
        roi/mask dictionary of this image
    
lib/dataset/pascal_voc_eval.py