{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "## Get your data ready for training" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "This module defines the basic [`DataBunch`](/basic_data.html#DataBunch) object that is used inside [`Learner`](/basic_train.html#Learner) to train a model. This is the generic class, that can take any kind of fastai [`Dataset`](https://pytorch.org/docs/stable/data.html#torch.utils.data.Dataset) or [`DataLoader`](https://pytorch.org/docs/stable/data.html#torch.utils.data.DataLoader). You'll find helpful functions in the data module of every application to directly create this [`DataBunch`](/basic_data.html#DataBunch) for you." ] }, { "cell_type": "code", "execution_count": null, "metadata": { "hide_input": true }, "outputs": [], "source": [ "from fastai.gen_doc.nbdoc import *\n", "from fastai.basics import * " ] }, { "cell_type": "code", "execution_count": null, "metadata": { "hide_input": true }, "outputs": [ { "data": { "text/markdown": [ "
class DataBunch[source][test]DataBunch(**`train_dl`**:[`DataLoader`](https://pytorch.org/docs/stable/data.html#torch.utils.data.DataLoader), **`valid_dl`**:[`DataLoader`](https://pytorch.org/docs/stable/data.html#torch.utils.data.DataLoader), **`fix_dl`**:[`DataLoader`](https://pytorch.org/docs/stable/data.html#torch.utils.data.DataLoader)=***`None`***, **`test_dl`**:`Optional`\\[[`DataLoader`](https://pytorch.org/docs/stable/data.html#torch.utils.data.DataLoader)\\]=***`None`***, **`device`**:[`device`](https://pytorch.org/docs/stable/tensor_attributes.html#torch-device)=***`None`***, **`dl_tfms`**:`Optional`\\[`Collection`\\[`Callable`\\]\\]=***`None`***, **`path`**:`PathOrStr`=***`'.'`***, **`collate_fn`**:`Callable`=***`'data_collate'`***, **`no_check`**:`bool`=***`False`***)\n",
"\n",
"Tests found for DataBunch:
pytest -sv tests/test_data_block.py::test_custom_dataset [source]Direct tests:
pytest -sv tests/test_basic_data.py::test_DataBunch_no_valid_dl [source]pytest -sv tests/test_basic_data.py::test_DataBunch_onebatch [source]pytest -sv tests/test_basic_data.py::test_DataBunch_oneitem [source]pytest -sv tests/test_basic_data.py::test_DataBunch_Create [source]pytest -sv tests/test_basic_data.py::test_DataBunch_show_batch [source]To run tests please refer to this guide.
create[source][test]create(**`train_ds`**:[`Dataset`](https://pytorch.org/docs/stable/data.html#torch.utils.data.Dataset), **`valid_ds`**:[`Dataset`](https://pytorch.org/docs/stable/data.html#torch.utils.data.Dataset), **`test_ds`**:`Optional`\\[[`Dataset`](https://pytorch.org/docs/stable/data.html#torch.utils.data.Dataset)\\]=***`None`***, **`path`**:`PathOrStr`=***`'.'`***, **`bs`**:`int`=***`64`***, **`val_bs`**:`int`=***`None`***, **`num_workers`**:`int`=***`8`***, **`dl_tfms`**:`Optional`\\[`Collection`\\[`Callable`\\]\\]=***`None`***, **`device`**:[`device`](https://pytorch.org/docs/stable/tensor_attributes.html#torch-device)=***`None`***, **`collate_fn`**:`Callable`=***`'data_collate'`***, **`no_check`**:`bool`=***`False`***, **\\*\\*`dl_kwargs`**) → `DataBunch`\n",
"\n",
"show_batch[source][test]show_batch(**`rows`**:`int`=***`5`***, **`ds_type`**:[`DatasetType`](/basic_data.html#DatasetType)=***`dl[source][test]dl(**`ds_type`**:[`DatasetType`](/basic_data.html#DatasetType)=***`one_batch[source][test]one_batch(**`ds_type`**:[`DatasetType`](/basic_data.html#DatasetType)=***`Tests found for one_batch:
pytest -sv tests/test_basic_data.py::test_DataBunch_onebatch [source]pytest -sv tests/test_text_data.py::test_should_load_backwards_lm_1 [source]pytest -sv tests/test_text_data.py::test_should_load_backwards_lm_2 [source]pytest -sv tests/test_text_data.py::test_backwards_cls_databunch [source]To run tests please refer to this guide.
one_item[source][test]one_item(**`item`**, **`detach`**:`bool`=***`False`***, **`denorm`**:`bool`=***`False`***, **`cpu`**:`bool`=***`False`***)\n",
"\n",
"sanity_check[source][test]sanity_check()\n",
"\n",
"No tests found for sanity_check. To contribute a test please refer to this guide and this discussion.
save[source][test]save(**`fname`**:`PathOrStr`=***`'data_save.pkl'`***)\n",
"\n",
"No tests found for save. To contribute a test please refer to this guide and this discussion.
load_data[source][test]load_data(**`path`**:`PathOrStr`, **`fname`**:`str`=***`'data_save.pkl'`***, **`bs`**:`int`=***`64`***, **`val_bs`**:`int`=***`None`***, **`num_workers`**:`int`=***`8`***, **`dl_tfms`**:`Optional`\\[`Collection`\\[`Callable`\\]\\]=***`None`***, **`device`**:[`device`](https://pytorch.org/docs/stable/tensor_attributes.html#torch-device)=***`None`***, **`collate_fn`**:`Callable`=***`'data_collate'`***, **`no_check`**:`bool`=***`False`***, **\\*\\*`kwargs`**) → [`DataBunch`](/basic_data.html#DataBunch)\n",
"\n",
"export[source][test]export(**`fname`**:`str`=***`'export.pkl'`***)\n",
"\n",
"load_empty[source][test]load_empty(**`path`**, **`fname`**:`str`=***`'export.pkl'`***)\n",
"\n",
"No tests found for _databunch_load_empty. To contribute a test please refer to this guide and this discussion.
add_test[source][test]add_test(**`items`**:`Iterator`\\[`T_co`\\], **`label`**:`Any`=***`None`***)\n",
"\n",
"No tests found for add_test. To contribute a test please refer to this guide and this discussion.
add_tfm[source][test]add_tfm(**`tfm`**:`Callable`)\n",
"\n",
"No tests found for add_tfm. To contribute a test please refer to this guide and this discussion.
class DeviceDataLoader[source][test]DeviceDataLoader(**`dl`**:[`DataLoader`](https://pytorch.org/docs/stable/data.html#torch.utils.data.DataLoader), **`device`**:[`device`](https://pytorch.org/docs/stable/tensor_attributes.html#torch-device), **`tfms`**:`List`\\[`Callable`\\]=***`None`***, **`collate_fn`**:`Callable`=***`'data_collate'`***)\n",
"\n",
"create[source][test]create(**`dataset`**:[`Dataset`](https://pytorch.org/docs/stable/data.html#torch.utils.data.Dataset), **`bs`**:`int`=***`64`***, **`shuffle`**:`bool`=***`False`***, **`device`**:[`device`](https://pytorch.org/docs/stable/tensor_attributes.html#torch-device)=***`device(type='cpu')`***, **`tfms`**:`Collection`\\[`Callable`\\]=***`None`***, **`num_workers`**:`int`=***`8`***, **`collate_fn`**:`Callable`=***`'data_collate'`***, **\\*\\*`kwargs`**:`Any`)\n",
"\n",
"add_tfm[source][test]add_tfm(**`tfm`**:`Callable`)\n",
"\n",
"No tests found for add_tfm. To contribute a test please refer to this guide and this discussion.
remove_tfm[source][test]remove_tfm(**`tfm`**:`Callable`)\n",
"\n",
"No tests found for remove_tfm. To contribute a test please refer to this guide and this discussion.
new[source][test]new(**\\*\\*`kwargs`**)\n",
"\n",
"No tests found for new. To contribute a test please refer to this guide and this discussion.
proc_batch[source][test]proc_batch(**`b`**:`Tensor`) → `Tensor`\n",
"\n",
"No tests found for proc_batch. To contribute a test please refer to this guide and this discussion.
Enum = [Train, Valid, Test, Single, Fix]\n",
"\n",
"No tests found for DatasetType. To contribute a test please refer to this guide and this discussion.
data_collate[source][test]data_collate(**`batch`**:`ItemsList`) → `Tensor`\n",
"\n",
"No tests found for data_collate. To contribute a test please refer to this guide and this discussion.