def __init__(self, **kwargs): """ :param **kwargs: args to pass to visual.ImageStim """ labtools_dir = unipath.Path(__file__).absolute().parent mask_files = unipath.Path(labtools_dir, 'dynamic_mask').listdir('*.png') self.masks = [ ImageStim(image=str(pth), **kwargs) for pth in mask_files ] self.cur_ix = 0
def test_cifar10_convert(): with tempdir() as td: data = load_cifar_batch('./cifar-10-batches-py/data_batch_1') unpack_cifar_batch(data, td) batch, labels, files, encoder = dir_to_cifar(td) batch = sorted( zip(batch, files), key=lambda x: data['filenames'].index(unipath.Path(x[1]).name)) batch = zip(*batch)[0] assert (batch == data['data']).all() labels = sorted( zip(labels, files), key=lambda x: data['filenames'].index(unipath.Path(x[1]).name)) labels = zip(*labels)[0] assert all(x == y for x, y in zip(labels, data['labels']))
def validate_PathNotEmpty(value): """ """ path = unipath.Path(value).strip() if len(path) == 0: raise ValidationError(u'String must not be empty')
def validate_PathInScope(value): """ """ path = unipath.Path(value) path.absolute() if not abspath.startswith(settings.SRC_PATH) or not path.isdir(abspath): raise ValidationError(u'Invalid path for source code')
def validate_IsValidName(value): """ """ validate_PathNotEmpty(value) path = unipath.Path(value) if not path.isalnum(): raise ValidationError(u'Project name must be alnum')
def unpack_cifar_batch(data, dest): """ Unpacking cifar file format to directory Parameters ---------- data: dict cifar batch file dest: str path where store resulting data """ batch = data['data'] with cwd(dest): for l in set(data['labels']): unipath.Path(l).mkdir() for i, (f, label) in enumerate(zip(data['filenames'], data['labels'])): image = cifar_image_to_pil(batch[i]) image.save(unipath.Path(label).child(unipath.Path(f).name))
def dir_to_cifar(source): labels = [] files = [] label_encoder = {} label_code = 0 with cwd(source) as source: for class_path in source.listdir(): fs = unipath.Path(class_path).walk( filter=lambda x: x.isfile() and x.lower().endswith(VALID_EXT)) fs = [x.lstrip('./') for x in fs] files.extend(fs) labels.extend([label_code] * len(fs)) label_encoder[class_path.name] = label_code label_code += 1 batch = files_to_batch(files) return batch, labels, [str(x) for x in files], label_encoder