Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Redefine transfroms as set of partially applied functions #450

Closed
wants to merge 1 commit into from

Conversation

PiotrCzapla
Copy link

@PiotrCzapla PiotrCzapla commented May 6, 2018

This is refined version of the previous proposal #312. I've managed to get rid of the TfmType and is_y by converting the transformations to set of applied functions whose parameters can be changed during execution.

We keep the concept of determ, apply_transform from #312. but we maketfms.determ() returning a partially applied function (almost as we return wrapper to make the printout nicer).
The change is backward compatible to large extend.

This let us express the sz_y (the reason foris_y existance) as follows:

def ap_t(t, x, y):
    nx = t(x)
    ny = t(y, sz=sz_y) # here the default value is set to sz_y
    return nx,ny

The coords transformation (one of reasons for TfmType) looks like this:

def ap_t(t, x, y): # this is how we can express coords transformation for y
    nx = t(x)
    ny = transform_coords(t, y, x.shape)
    return nx,ny

The mask transformation (another reason for TfmType) can be expressed as follows:

def ap_t(t, x, y): # this is how we can express coords transformation for y
    nx = t(x)
    ny = t(y, **TfmParams.CLASS)
    return nx,ny

I've also add an inspection mechanism to transforms to make it easier to reason about random transformations, here is how it looks like

>>> tfms[0]
Trasnforms(...)
# with ComposedTransform(tfms=[
  RandomScale.do(_, sz=16, interpolation=3, zoom=?),
  AddPadding.do(_, pad=2, pad_mode=2),
  RandomRotate.do(_, pad_mode=2, interpolation=3, rp=?, rdeg=?),
  RandomLighting.do(_, b=?, c=?),
  RandomDihedral.do(_, rot_times=?, do_flip=?),
  NoCrop.do(_, sz=16, interpolation=3),
  Normalize.do(_, mean=[0.5 0.5 0.5], stddev=[0.5 0.5 0.5]),
  ChannelOrder.do(_)
])

>>> tfms[0].determ()
ComposedTransform(tfms=[
  RandomScale.do(_, sz=16, interpolation=3, zoom=1.0),
  AddPadding.do(_, pad=2, pad_mode=2),
  RandomRotate.do(_, pad_mode=2, interpolation=3, rp=False, rdeg=1.3287164035703682),
  RandomLighting.do(_, b=-0.02255752415182746, c=0.008637519508592914),
  RandomDihedral.do(_, rot_times=2, do_flip=True),
  NoCrop.do(_, sz=16, interpolation=3),
  Normalize.do(_, mean=[0.5 0.5 0.5], stddev=[0.5 0.5 0.5]),
  ChannelOrder.do(_)
])

- The deterministic transformations become partially applied functions
- The randomised transformations have their parameters bound twice,
once when the transformation is defined, second when the random
parameters are set before execution.
- We allow to overwrite any parameter passed to such applied function
during execution, so the `sz_y` can be expressed as argument `t(y,
sz=sz_y)`.

See
@jph00
Copy link
Member

jph00 commented Aug 18, 2018

There's a new transform pipeline now available in fastai_v1

@jph00 jph00 closed this Aug 18, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants