datasets

This module has the necessary functions to be able to download several useful datasets that we might be interested in using in our models.

class URLs[source][test]

URLs()

No tests found for URLs. To contribute a test please refer to this guide and this discussion.

Global constants for dataset and model URLs.

This contains all the datasets' and models' URLs, and some classmethods to help use them - you don't create objects of this class. The supported datasets are (with their calling name): S3_NLP, S3_COCO, MNIST_SAMPLE, MNIST_TINY, IMDB_SAMPLE, ADULT_SAMPLE, ML_SAMPLE, PLANET_SAMPLE, CIFAR, PETS, MNIST. To get details on the datasets you can see the fast.ai datasets webpage. Datasets with SAMPLE in their name are subsets of the original datasets. In the case of MNIST, we also have a TINY dataset which is even smaller than MNIST_SAMPLE.

Models is now limited to WT103 but you can expect more in the future!

URLs.MNIST_SAMPLE
'http://files.fast.ai/data/examples/mnist_sample'

Downloading Data

For the rest of the datasets you will need to download them with untar_data or download_data. untar_data will decompress the data file and download it while download_data will just download and save the compressed file in .tgz format.

The locations where the data and models are downloaded are set in config.yml, which by default is located in ~/.fastai. This directory can be changed via the optional environment variable FASTAI_HOME (e.g FASTAI_HOME=/home/.fastai).

If no config.yml is present in the specified directory, a default one will be created with data_path and models_path entries pointing to respectively data folder and models folder in the same directory as config.yml.

Configure those download locations by editing data_path and models_path in config.yml.

untar_data[source][test]

untar_data(url:str, fname:PathOrStr=None, dest:PathOrStr=None, data=True, force_download=False) → Path

Tests found for untar_data:

  • pytest -sv tests/test_vision_data.py::test_trunc_download [source]

To run tests please refer to this guide.

Download url to fname if it doesn't exist, and un-tgz to folder dest.

untar_data(URLs.PLANET_SAMPLE)
PosixPath('/home/ubuntu/.fastai/data/planet_sample')

download_data[source][test]

download_data(url:str, fname:PathOrStr=None, data:bool=True, ext:str='.tgz') → Path

No tests found for download_data. To contribute a test please refer to this guide and this discussion.

Download url to destination fname.

Note: If the data file already exists in a data directory inside the notebook, that data file will be used instead of the one present in the folder specified in config.yml. config.yml is located in the directory specified in optional environment variable FASTAI_HOME (defaults to ~/.fastai/). Paths are resolved by calling the function datapath4file - which checks if data exists locally (data/) first, before downloading to the folder specified in config.yml.

Example:

download_data(URLs.PLANET_SAMPLE)
PosixPath('/home/ubuntu/.fastai/data/planet_sample.tgz')

datapath4file[source][test]

datapath4file(filename, ext:str='.tgz')

No tests found for datapath4file. To contribute a test please refer to this guide and this discussion.

Return data path to filename, checking locally first then in the config file.

All the downloading functions use this to decide where to put the tgz and expanded folder. If filename already exists in a data directory in the same place as the calling notebook/script, that is used as the parent directly, otherwise config.yml is read to see what path to use, which defaults to ~/.fastai/data is used. To override this default, simply modify the value in your config.yml:

data_path: ~/.fastai/data

config.yml is located in the directory specified in optional environment variable FASTAI_HOME (defaults to ~/.fastai/).

url2path[source][test]

url2path(url, data=True, ext:str='.tgz')

No tests found for url2path. To contribute a test please refer to this guide and this discussion.

Change url to a path.

class Config[source][test]

Config()

Tests found for Config:

  • pytest -sv tests/test_datasets.py::test_creates_config [source]

To run tests please refer to this guide.

Creates a default config file 'config.yml' in $FASTAI_HOME (default ~/.fastai/)

You probably won't need to use this yourself - it's used by URLs.datapath4file.

get_path[source][test]

get_path(path)

No tests found for get_path. To contribute a test please refer to this guide and this discussion.

Get the path in the config file.

Get the key corresponding to path in the Config.

data_path[source][test]

data_path()

No tests found for data_path. To contribute a test please refer to this guide and this discussion.

Get the path to data in the config file.

Get the Path where the data is stored.

model_path[source][test]

model_path()

No tests found for model_path. To contribute a test please refer to this guide and this discussion.

Get the path to fastai pretrained models in the config file.