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