Fastai v2 code walk-thru 6

Use this wiki topic for walk-thru 6.
Feel free to edit this topic.
Fastai v2 daily code walk-thrus
Fastai v2 chat

Brief notes thanks to @maxim.pechyonkin:

02_data_transforms.ipynb notebook

  • How do we know class passes self to a method that we assigned by monkey patching, like in example below?
t = TypeDispatch(m_min, m_nu, m_bll)
class A: f = t
a = A()
a.f(1)
  • self.inst
  • f = types.MethodType(f, self.inst)
  • __get__() when calling a method of a class
  • self.inst = inst binds TypeDispatch object to a particular instance
  • endodes, decodes, setups
  • RAPIDS nVidia — like Pandas, but runs on the GPU

03_data_pipeline.ipynb notebook

  • creating a Pipeline() object, which is callable
  • supports .set_as_item() method
  • function composition
  • decodes on Pipeline calls decodes on each transform in the pipeline in the reverse order
  • pipe.show(t) decodes t one transform at a time until it gets to a type that is showable
  • ShowTitle class that knows how to show itself
  • test_stdout has first element should be a lambda that calls the function whose stdout output we want to test
  • Pipeline can show single elements, also can show individual elements of tuples
  • DataSource class discussion
  • TfmdList overrides self._gets() method and applies pipeline to each element
  • TfmdDS allows to handle 2 pipelines - for x and for y separately, both pipelines will start from the same thing — path to images (in this example), but can also be applied to tuples of items, where x and y come from different places (like images from folder, and labels from a .csv
  • tls stands for transformed lists
  • L has .mapped() method that applies a function to each element of L
  • pipelines passed to TfmdDS should be a list of lists
  • Categorize transform
  • @delegates() and @docs decorator

06_data_source.ipynb notebook

  • DataSource is almost identical to TfmdDS
  • DataSource has filts parameter
  • pets.subset(1) is the same as pets.valid
  • Transform can know whether to apply to validation or test set — use filt for that functionality
    • filt=0 — only apply to train set
    • filt is just an integer, or a bool mask
2 Likes