{ "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.basic_data import * " ] }, { "cell_type": "code", "execution_count": null, "metadata": { "hide_input": true }, "outputs": [ { "data": { "text/markdown": [ "
class
DataBunch
[source]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), `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`, `tfms`:`Optional`\\[`Collection`\\[`Callable`\\]\\]=`None`, `path`:`PathOrStr`=`'.'`, `collate_fn`:`Callable`=`'data_collate'`)"
],
"text/plain": [
"create
[source]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`:[`Dataset`](https://pytorch.org/docs/stable/data.html#torch.utils.data.Dataset)=`None`, `path`:`PathOrStr`=`'.'`, `bs`:`int`=`64`, `num_workers`:`int`=`4`, `tfms`:`Optional`\\[`Collection`\\[`Callable`\\]\\]=`None`, `device`:[`device`](https://pytorch.org/docs/stable/tensor_attributes.html#torch-device)=`None`, `collate_fn`:`Callable`=`'data_collate'`) → `DataBunch`"
],
"text/plain": [
"show_batch
[source]show_batch
(`rows`:`int`=`5`, `ds_type`:[`DatasetType`](/basic_data.html#DatasetType)=`dl
[source]dl
(`ds_type`:[`DatasetType`](/basic_data.html#DatasetType)=`one_batch
[source]one_batch
(`ds_type`:[`DatasetType`](/basic_data.html#DatasetType)=`one_item
[source]one_item
(`item`, `detach`:`bool`=`False`, `denorm`:`bool`=`False`)\n",
"\n",
"Get ìtem` into a batch. Optionally `detach` and `denorm`. "
],
"text/plain": [
"add_tfm
[source]add_tfm
(`tfm`:`Callable`)"
],
"text/plain": [
"class
DeviceDataLoader
[source]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'`, `skip_size1`:`bool`=`False`)"
],
"text/plain": [
"create
[source]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`)"
],
"text/plain": [
"add_tfm
[source]add_tfm
(`tfm`:`Callable`)"
],
"text/plain": [
"remove_tfm
[source]remove_tfm
(`tfm`:`Callable`)"
],
"text/plain": [
"Enum
= [Train, Valid, Test, Single]"
],
"text/plain": [
"proc_batch
[source]proc_batch
(`b`:`Tensor`) → `Tensor`\n",
"\n",
"Proces batch `b` of `TensorImage`. "
],
"text/plain": [
"export
[source]export
(`fname`:`str`=`'export.pkl'`)"
],
"text/plain": [
"_databunch_load_empty
[source]_databunch_load_empty
(`path`, `fname`:`str`=`'export.pkl'`, `tfms`:`Union`\\[`Callable`, `Collection`\\[`Callable`\\]\\]=`None`, `tfm_y`:`bool`=`False`, `kwargs`)"
],
"text/plain": [
"data_collate
[source]data_collate
(`batch`:`ItemsList`) → `Tensor`\n",
"\n",
"Convert `batch` items to tensor data. "
],
"text/plain": [
"