{ "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]Some other tests where DataBunch
is used:
pytest -sv tests/test_basic_data.py::test_DataBunch_Create
[source]pytest -sv tests/test_basic_data.py::test_DataBunch_no_valid_dl
[source]pytest -sv tests/test_basic_data.py::test_DataBunch_save_load
[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`=***`4`***, **`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",
"Tests found for create
:
pytest -sv tests/test_basic_data.py::test_DataBunch_Create
[source]pytest -sv tests/test_basic_data.py::test_DataBunch_no_valid_dl
[source]Some other tests where create
is used:
pytest -sv tests/test_basic_data.py::test_DeviceDataLoader_getitem
[source]To run tests please refer to this guide.
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)=***`No tests found for dl
. To contribute a test please refer to this guide and this discussion.
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_basic_data.py::test_DataBunch_save_load
[source]pytest -sv tests/test_text_data.py::test_backwards_cls_databunch
[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]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
(**`file`**:`PathLikeOrBinaryStream`=***`'data_save.pkl'`***)\n",
"\n",
"load_data
[source][test]load_data
(**`path`**:`PathOrStr`, **`file`**:`PathLikeOrBinaryStream`=***`'data_save.pkl'`***, **`bs`**:`int`=***`64`***, **`val_bs`**:`int`=***`None`***, **`num_workers`**:`int`=***`4`***, **`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
(**`file`**:`PathLikeOrBinaryStream`=***`'export.pkl'`***)\n",
"\n",
"No tests found for export
. To contribute a test please refer to this guide and this discussion.
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='cuda')`***, **`tfms`**:`Collection`\\[`Callable`\\]=***`None`***, **`num_workers`**:`int`=***`4`***, **`collate_fn`**:`Callable`=***`'data_collate'`***, **\\*\\*`kwargs`**:`Any`)\n",
"\n",
"Tests found for create
:
Some other tests where create
is used:
pytest -sv tests/test_basic_data.py::test_DataBunch_Create
[source]pytest -sv tests/test_basic_data.py::test_DataBunch_no_valid_dl
[source]pytest -sv tests/test_basic_data.py::test_DeviceDataLoader_getitem
[source]To run tests please refer to this guide.
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.