<jupyter_start><jupyter_text>Load and Visualize Pascal Dataset<jupyter_code>%load_ext autoreload
%autoreload 2
from importlib.util import find_spec
if find_spec("model") is None:
    import sys
    sys.path.append('..')
from fastai.vision.all import *
path = untar_data(URLs.PASCAL_2007)
path.ls()
(path/"train").ls()
imgs, lbl_bbox = get_annotations(path/"train.json")
imgs[0]
lbl_bbox[0]<jupyter_output><empty_output><jupyter_text>We Want to be able to quickly look up an image's corresponding label.<jupyter_code>img2bbox = dict(zip(imgs, lbl_bbox))
first = {k: img2bbox[k] for k in list(img2bbox)[:1]};
first<jupyter_output><empty_output><jupyter_text>Building the Datablock<jupyter_code>getters = [lambda o: path/"train"/o, lambda o: img2bbox[o][0], lambda o: img2bbox[o][1]]
item_tfms = [Resize(128, method="pad"),]
batch_tfms = [Rotate(), Flip(), Dihedral(), Normalize.from_stats(*imagenet_stats)]
def get_train_imgs(noop): return imgs
pascal = DataBlock(blocks=(ImageBlock, BBoxBlock, BBoxLblBlock),
                   splitter=RandomSplitter(),
                   get_items=get_train_imgs,
                   getters=getters,
                   item_tfms=item_tfms,
                   batch_tfms=batch_tfms,
                   n_inp=1)
dls = pascal.dataloaders(path/"train")
dls.c = 20
dls.show_batch()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13049962714392244, 'fraction_numerical': 0.015659955257270694, 'mean_word_length': 4.477551020408163, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, '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': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '228209', 'license': 'MIT', 'n_tokens_mistral': 514, 'n_tokens_neox': 497, 'n_words': 91, 'path': 'notebooks/19_fastai_pascal_dataset.ipynb', 'repo_name': 'mhd53/retinanet-from-torch', 'size': '1341'}