These are my notes in random order from today:
Sep 10, 2019
Digging Deep in Transforms
-
02_data_transforms.ipynb
notebook - no order in v2 of the library for DataBlock API so can’t have mistakes when order is not correct as it was in v1
-
filt
knows which set transform is applied to - transform creates a callable object, after creating you should call it and pass some data
-
_TfmMeta
is meta class ofTransform
-
...
for pass in Python (or do nothing) -
Foo2 = type(‘Foo2’, (object), {})
will create a class calledFoo2
-
type
is class that constructs things - reason for meta classes is to change how Python works underneath the hood
- meta class is a way to not use
type
constructor, but some other constructor in fastai v2 - meta class is called every time we create a class (not when objects are created)
- 3. Data model — Python 3.7.4 documentation
- class’s namespace is
__dict__
object -
_TfmMeta
uses_TfmDict
instead of plain dict as the namespace dict - it behaves as the normal dict except for cases when ‘encodes’ and ‘decodes’ parameters are passed
-
TypeDispatch
— allows for the same function to work differently for different types - Python method dispatching — can be single or multiple
- Multiple Dispatching — Python 3 Patterns, Recipes and Idioms
- Method dispatching in Python
- PEP 443 — Single-dispatch generic functions | Python.org
-
TypeDispatch
has dictfuncs
where key is a type and value is the function to call (NICE!) -
_p1_anno
grabs the first parameter annotation - how to use
Transform
subclass as a decorator? This will allow to dynamically add functionality to a given transform later outside the class definition. - Using class as decorator needs to be a callable, but not in the
__init__
sense. We need to reimplement__call__()
method. If parameter is callable it will be added to class’s methods. -
__new__()
should have an expectableShift + Tab
autocomplete for the signature. Signature is customized in__new__()
forTransform