kbressem / trainlib

MIT License
4 stars 0 forks source link

get_base_transforms() doesn't allow for custom LoadImaged #44

Closed markus-hinsche closed 1 year ago

markus-hinsche commented 1 year ago

I would like to include a LoadImaged which support a custom reader NrrdReader

transforms:
  prob: 0.1
  mode: [bilinear, nearest]
  base:
    LoadImaged:
      keys: [image, label]
      reader: [ITKReader, NrrdReader]

This is the current implementation in trainlib:

def get_base_transforms(config: dict) -> List[Callable]:
    """Transforms applied everytime at the start of the transform pipeline"""
    tfms = [
        get_transform("LoadImaged", config=config, allow_missing_keys=True),
        get_transform("EnsureChannelFirstd", config=config, allow_missing_keys=True),
    ]
    if "base" in config.transforms.keys():
        tfm_names = list(config.transforms.base)
        tfms += [get_transform(tn, config) for tn in tfm_names]
    return tfms

Problem: When adding a custom LoadImaged, I also have to get the standard LoadImaged by default, which I don't want

A solution I could think of is: removing default/opinionated transforms (in the tfms list above) as they are but limit other use cases.

Related: https://github.com/kbressem/transforms/pull/4

kbressem commented 1 year ago

I think we discussed this some time ago? Given you are having troubles again with the defaults, it's probably a good idea to change it. Will you do the PR?