def check_archive(cat_desc, voxel_dim, example_ids=None): from shapenet.core import cat_desc_to_id, get_example_ids from shapenet.core.voxels.config import VoxelConfig cat_id = cat_desc_to_id(cat_desc) if example_ids is None or len(example_ids) == 0: example_ids = get_example_ids(cat_id) config = VoxelConfig(voxel_dim=voxel_dim) n_absent = 0 with config.get_zip_file(cat_id) as zf: namelist = set(zf.namelist()) for example_id in example_ids: if config.get_binvox_subpath(cat_id, example_id) not in namelist: n_absent += 1 if n_absent == 0: print('All %d %s voxels present' % (len(example_ids), cat_desc)) else: print('%d / %d voxel files missing from %s' % (n_absent, len(example_ids), cat_desc))
def create_archive(cat_desc, voxel_dim, example_ids=None, overwrite=False): import os import zipfile from shapenet.core.voxels.config import VoxelConfig from shapenet.core import get_example_ids, cat_desc_to_id cat_id = cat_desc_to_id(cat_desc) if example_ids is None or len(example_ids) == 0: example_ids = get_example_ids(cat_id) config = VoxelConfig(voxel_dim) with zipfile.ZipFile(config.get_zip_path(cat_id), 'a') as zf: if not overwrite: namelist = set(zf.namelist()) for example_id in example_ids: dst = config.get_binvox_subpath(cat_id, example_id) if not overwrite and dst in namelist: continue src = config.get_binvox_path(cat_id, example_id) if os.path.isfile(src): zf.write(src, dst) else: print('No file at %s for %s/%s: skipping' % (src, cat_id, example_id))