%reload_ext autoreload %autoreload 2 %matplotlib inline from fastai.vision import * path = Path('/mnt/fe2_disk/imagenet/') names = {o.name for o in (path/'train').ls()} classes = pd.read_csv(path/'classids.txt', delimiter=' ', header=None, names=['id','name']) classes = {k:v for k,v in [o.strip().split() for o in (path/'classids.txt').open().readlines()] if k in names} #doggies subids = 'n02096294 n02093754 n02111889 n02088364 n02086240 n02089973 n02087394 n02115641 n02099601 n02105641'.split() #nette subids = 'n01440764 n02102040 n02979186 n03000684 n03028079 n03394916 n03417042 n03425413 n03445777 n03888257'.split() ds = '{' + ','.join(subids) + '}' ds ', '.join([classes[o] for o in subids]) for o in ['160','320','imagenet']: for p in ['val','train']: src = Path('/mnt/fe2_disk')/o/p dst = Path('/mnt/fe2_disk/imagewoof')/o/p dst.mkdir(exist_ok=True, parents=True) for s in subids: shutil.copytree(src/s, dst/s) bs,size = 64,224 path = untar_data(URLs.PETS)/'images' src = ImageList.from_folder(path).split_by_rand_pct(0.2) data = src.label_from_re(r'([^/]+)_\d+.jpg$').presize(size) img = data.train.x[0] img.px.shape %timeit flip_lr(img) %timeit t = tensor(np.ascontiguousarray(np.array(img.px)[...,::-1])) idxs = torch.arange(224-1,-1,-1) %timeit t=img.px[...,idxs]; %timeit t=img.px[...,torch.arange(224-1,-1,-1)];