Normalization in custom Dataset class

Yes you right, you should not return a dictionary in ToTensor or any of Transforms class.
Sorry if I answered late (time zone differences!).

But I have a suggestion here. It is better to build your classes modular so you can use them in other tasks with different datasets easily. For instance, maybe you need 3 or 4 images to be transformed or using different transforms on them. In this case you have to edit your ToTensor or Rescale class. So I think it is better to implement all transform classes for only a sample of input, actually, this is the approach has been chosen in PyTorch.

If I want to explain scenario, I can say if want to do other transforms for example adding gaussian noise to your image not landmarks, you will be stuck again and you have change your ToTensor code because still you are returning dictionary or even you are using another transform inside another one. But if your classes only take one tensor as input and return the changed tensor, you can use all of your custom classes in any order or in any dataset you want.

By the way, I use same approach as pytorch so I really did not think about your ToTensor custom implementation.

usage in preprocessing step

usage in DataLoaders

Custom Transform

Good luck

1 Like