DataBlock and the major 4 lines of code of FastAI

[Major 4 lines of code]

path = untar_data(URLs.PETS)

dls = ImageDataLoaders.from_name_func(path, get_image_files(path/"images"),
label_func, item_tfms=Resize(224))
learn = cnn_learner(dls, resnet34, metrics=error_rate)
learn.fine_tune(1)

[DataBlock]

The way we usually build the data block in one go is by answering a list of questions:

  • what is the types of your inputs/targets? Here images and categories
  • where is your data? Here in filenames in subfolders
  • does something need to be applied to inputs? Here no
  • does something need to be applied to the target? Here the label_func function
  • how to split the data? Here randomly
  • do we need to apply something on formed items? Here a resize
  • do we need to apply something on formed batches? Here no

This gives us this design:

dblock = DataBlock(blocks    = (ImageBlock, CategoryBlock),
                   get_items = get_image_files,
                   get_y     = label_func,
                   splitter  = RandomSplitter(),
                   item_tfms = Resize(224))

For two questions that got a no, the corresponding arguments we would pass if the anwser was different would be get_x and batch_tfms.





Comments

Popular posts from this blog

自修溫習|港大醫科生研溫書App(筆記系統化助「主動回憶」)( 部份轉載)

Agent based intelligent KM (Knowledge Management) Chatbot (Part 1)