Added elastic transform in torchvision.transforms (#4938)
* Added elastic augment * ufmt formatting * updated comments * fixed circular dependency issue and bare except error * Fixed three type checking errors in functional_tensor.py * ufmt formatted * changed elastic_deformation to a more common implementation Implementation uses alpha and sigma to control strength and smoothness of the displacement vectors in elastic_deformation instead of control_point_spacings and sigma. * ufmt formatting * Some performance updates Put random offset vectors to device before gaussian_blur is applied speeds it up 3-fold. * fixed type error * fixed again a type error * Update torchvision/transforms/functional_tensor.py Co-authored-by:vfdev <vfdev.5@gmail.com> * Added some requested changes - pil image support similar to GaussianBlur - changed interpolation arg to InterpolationMode - added a wrapper in torchvision.transforms.functional.py that gets called by the class in transforms.py -renamed it to ElasticTransform - handled sigma = 0 case * added img docstring * added some tests * Updated tests and the code * Added the requested changes to the arguments of F.elastic_transform Added random_state and displacement as arguments to F.elastic_transform * fixed the type error * Fixed tests and docs * implemented requested changes Changes: 1) alpha AND sigma OR displacement must be given as arguments to transforms.functional_tensor.elastic_transform instead of alpha AND sigma AND displacement 2) displacements are accepted in transforms.functional.elastic_transform as np.array and torch.Tensor instead of only accepting torch.Tensor * ufmt formatting * trochscript error resolved replaced torch.from_numpy() to torch.Tensor() to make it compatible to torchscript * revert to torch.from_numpy() * updated argument checks and errors - In F.elastic_transform added check to see if both user inputs img and displacement are either of type PIL Image and ndarray or both of type tensor. - In F_t.elastic_transform added check if alpha and sigma are None if displacement is given or vice versa. * fixed seed error changed torch.seed to torch.manual_seed in F_t.elastic_transform * Reverted displacement type and other cosmetics * Other minor improvements * changed gaussian_blur filter size changed gaussian_blur filter size from 4 * int(sigma) + 1 to int(8 * sigma + 1) to make it consistent with ernestums implementation * resolved merge error * Revert "resolved merge error" This reverts commit 6a4a4e74ff4d078e2c2753d359185f9a81c415d0. * resolve merge error * ufmt formatted * ufmt formated once again.. * fixed unsupported operand error * Update API and removed random_state from functional part * Added default values * Added ElasticTransform to gallery and updated the docstring * Updated gallery and added _log_api_usage_once BTW, matplotlib.pylab is deprecated * Updated gallery transforms code * Updates according to review Co-authored-by:
vfdev <vfdev.5@gmail.com>
Showing
Please register or sign in to comment