transform is only instantiated and is not applied until you explicitly apply it to an image, which you are in the __getitem__ method. But note that you are flattening your data/image in the __init__ method prior to applying your transform. I hope this clarifies my earlier comment on- transform after view.