def check_voc_sds_cache(cache_dir, devkit_path, image_names, class_names):
    """
    Args:
        cache_dir: output directory for cached mask annotation
        devkit_path: root directory of VOCdevkitSDS
        image_names: used for parse image instances
        class_names: VOC 20 class names
    """

    if not os.path.isdir(cache_dir):
        os.mkdir(cache_dir)

    exist_cache = True
    for cls_name in class_names:
        if cls_name == '__background__':
            continue
        cache_name = os.path.join(cache_dir, cls_name + '_mask_gt.pkl')
        if not os.path.isfile(cache_name):
            exist_cache = False
            break

    if not exist_cache:
        # load annotations:
        # create a list with size classes
        record_list = [{} for _ in xrange(21)]
        for i, image_name in enumerate(image_names):
            record = parse_inst(image_name, devkit_path)
            for j, mask_dic in enumerate(record):
                cls = mask_dic['mask_cls']
                mask_dic['already_detect'] = False
                if image_name not in record_list[cls]:
                    record_list[cls][image_name] = []
                record_list[cls][image_name].append(mask_dic)
            if i % 100 == 0:
                print 'Reading annotation for {:d}/{:d}'.format(i + 1, len(image_names))

        print 'Saving cached annotations...'
        for cls_ind, name in enumerate(class_names):
            if name == '__background__':
                continue
            cachefile = os.path.join(cache_dir, name + '_mask_gt.pkl')
            with open(cachefile, 'wb') as f:
                cPickle.dump(record_list[cls_ind], f)

    Args:
        cache_dir: output directory for cached mask annotation
        devkit_path: root directory of VOCdevkitSDS
        image_names: used for parse image instances
        class_names: VOC 20 class names
    
lib/dataset/pascal_voc_eval.py