.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/basics/demo_dataset.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_basics_demo_dataset.py: Creating your own dataset ==================================================================================================== This example shows how to create your own dataset for deep image inverse problems from a base dataset of images. Here we use Set3C as a base dataset of natural images. This base dataset contains 3 images. .. GENERATED FROM PYTHON SOURCE LINES 9-17 .. code-block:: Python import deepinv as dinv from pathlib import Path import torch from torch.utils.data import DataLoader from torchvision import transforms from deepinv.utils.demo import load_dataset .. GENERATED FROM PYTHON SOURCE LINES 18-21 Setup paths for data loading and results. ---------------------------------------------------------------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 21-26 .. code-block:: Python BASE_DIR = Path(".") DATA_DIR = BASE_DIR / "measurements" .. GENERATED FROM PYTHON SOURCE LINES 27-33 Load base image datasets ---------------------------------------------------------------------------------------- We download the Set3 dataset which is a :class:`torchvision.datasets.ImageFolder` dataset. You can use any other dataset as long as it is a :class:`torch.utils.data.Dataset`. .. GENERATED FROM PYTHON SOURCE LINES 33-55 .. code-block:: Python # Set the global random seed from pytorch to ensure reproducibility of the example. torch.manual_seed(0) device = dinv.utils.get_freer_gpu() if torch.cuda.is_available() else "cpu" # Set up the variable to fetch dataset and operators. dataset_name = "set3c" img_size = 256 if torch.cuda.is_available() else 32 val_transform = transforms.Compose( [transforms.CenterCrop(img_size), transforms.ToTensor()] ) # add batch and channel dimensions dataset = load_dataset(dataset_name, transform=val_transform) # display an image from the base dataset dinv.utils.plot(dataset[0][0].unsqueeze(0)) .. image-sg:: /auto_examples/basics/images/sphx_glr_demo_dataset_001.png :alt: demo dataset :srcset: /auto_examples/basics/images/sphx_glr_demo_dataset_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none Downloading datasets/set3c.zip 0%| | 0.00/385k [00:00` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: demo_dataset.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: demo_dataset.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_