<jupyter_start><jupyter_text>Data Block by fastai---<jupyter_code>from fastai.vision import *
from fastai import *<jupyter_output><empty_output><jupyter_text>MNIST Example<jupyter_code>path = untar_data(URLs.MNIST_TINY)
tfms = get_transforms(do_flip=False)
path
path.ls()
(path/'train').ls()
doc(get_transforms)
tfms<jupyter_output><empty_output><jupyter_text>**Simple Way**<jupyter_code>data = ImageDataBunch.from_folder(path, ds_tfms=tfms, size=64)
data.show_batch(3, figsize=(7,6))<jupyter_output><empty_output><jupyter_text>**Customizable Data Block Way**<jupyter_code>doc(ImageImageList.from_folder)
data = (ImageItemList.from_folder(path)
        .split_by_folder()
        .label_from_folder()
        .add_test_folder()
        .transform(tfms, size=64)
        .databunch())
data.show_batch(rows=3, figsize=(6,7))<jupyter_output><empty_output><jupyter_text>**Utils**<jupyter_code>show_batch = partial(data.show_batch, rows=3, figsize=(6,7))
show_batch()<jupyter_output><empty_output><jupyter_text>Amazon Planet Example<jupyter_code>path = untar_data(URLs.PLANET_TINY)
path
path.ls()
(path/'train').ls()[:5]
planet_tfms = get_transforms(flip_vert=True, max_lighting=0.1, max_warp=0., max_zoom=1.05)
data = ImageDataBunch.from_csv(path,folder='train',suffix='.jpg',label_delim=' ',
                               ds_tfms=planet_tfms,size=128)
data.show_batch(rows=3)
data = (ImageList.from_csv(path, csv_name='labels.csv', folder='train', suffix='.jpg')
        .random_split_by_pct()
        .label_from_df(label_delim=' ')
        .transform(planet_tfms, size=128)
        .databunch())
data.show_batch(rows=3)<jupyter_output><empty_output><jupyter_text>Stages of using DataBlock<jupyter_code>data = (ImageList.from_csv(path, csv_name='labels.csv', folder='train', suffix='.jpg')
        .random_split_by_pct()
        .label_from_df(label_delim=' ')
        .transform(planet_tfms, size=128)
        .databunch())<jupyter_output><empty_output><jupyter_text>**Step 1: Provide inputs**<jupyter_code>item_list = ImageList.from_csv(path, csv_name='labels.csv', folder='train', suffix='.jpg')
type(item_list)
dir(item_list)[-10:]<jupyter_output><empty_output><jupyter_text>**Step 2: Split the data between the training and the validation set**<jupyter_code>item_list_split = item_list.random_split_by_pct()
type(item_list_split)
dir(item_list_split)[-10:]<jupyter_output><empty_output><jupyter_text>**Step 3: Label the inputs**<jupyter_code>item_list_split_label = item_list_split.label_from_df(label_delim=' ')
type(item_list_split_label)
dir(item_list_split_label)[-10:]<jupyter_output><empty_output><jupyter_text>**Step 4: convert to a DataBunch**<jupyter_code>data = item_list_split_label.databunch()
type(data)
dir(data)[-10:]<jupyter_output><empty_output><jupyter_text>Camvid Example<jupyter_code>path = untar_data(URLs.CAMVID_TINY)
path
path_img = path/'images'
path_lbl = path/'labels'<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.14754098360655737, 'fraction_numerical': 0.014685792349726777, 'mean_word_length': 7.640117994100295, 'pattern_counts': {'":': 0, '<': 49, '<?xml version=': 0, '>': 49, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '12', 'dir': 'jupyter-structured-clean-dedup', 'id': '149972', 'license': 'MIT', 'n_tokens_mistral': 1172, 'n_tokens_neox': 1136, 'n_words': 125, 'path': 'notebooks/Data_Block_fastai.ipynb', 'repo_name': 'AmanDaVinci/DeepLabs', 'size': '2928'}