Setattr and getattr methods

:rocket: Feature

It would be really helpful if we can implement setattr methods in respective classes (say transforms.transform.Normalize) so that attributes of objects can be set recursively say for example by using a loop.

Motivation

It would be helpful to loop through multiple attributes and set them on the fly in order to compare performance among various parameters and attributes. Say for example if we take transformations and want to loop through multiple sets of them say set1: Grayscale, ToTensor, Normalize with a, b, c parameters and set2: with d, e, f parameters or some other transformations altogether. Currently I am not aware of any such implementations.

You should be able to directly access the attributes of the transformations, as they are implemented as Python classes:

norm = transforms.Normalize(mean=torch.tensor([0.5, 0.5, 0.5]),
                            std=torch.tensor([0.5, 0.5, 0.5]))
print(norm)
norm.mean = torch.tensor([1.5, 1.5, 1.5])
print(norm)

The setattr method should do the same, no?

It worked. I was looking for _setattr_ and _getattr_ methods in the code but since I couldn’t find them I thought they weren’t implemented.