I agm trying to train an autoencoder on the MNIST set, where the digits are supposed to have a random translation applied to them. Using the torch transforms, I can resize and translate, but this doens't have the desired effect (the digit gets translated out of frame). Does anyone here know of a transform or some other method that would allow me to get a smaller digit randomnly translated?
I have tried to do so manually using the following code:
image = dataset[0][0][0]
background = np.zeros((56,56))
topLeft = (random.randint(0,27), random.randint(0,27))
background[topLeft[0]:topLeft[0]+28, topLeft[1]:topLeft[1]+28] = image[0][0]
but I am unable to do this transformation on the actual MNIST set. Any help would be greatly appreciated.
i have done it with Affine transform
On top of this you can also use 56x56 resize method
here you can see more details, you can play with
translateandscaleparams to shift the image from centerI hope this helps