3 Nb]@s6ddlZddlmZddlmZmZGdddZdS)N) SamplePadding) RandomAffine CenterCropc@s.eZdZd ddZddZdd Zd d Zd S)FakeFakesGenerator?皙?cCs6tddtjddd|_t||tjddd|_||_dS)Nihg?F)degrees translate padding_modekeepdimpT)rr REFLECTIONgrad_augimg_aug aug_proba)selfrZimg_aug_degreeZimg_aug_translaterK/home/ec2-user/SageMaker/lama/saicinpainting/training/modules/fake_fakes.py__init__s  zFakeFakesGenerator.__init__cCs0|j|}|j|}|d|||}||fS)Nr )_fill_masks_with_gradient_make_blend_target)r input_imagesmasksZ blend_masksZ blend_targetresultrrr__call__s  zFakeFakesGenerator.__call__cCsd|jd}|tj|}|j|}tj||jddddddf|jkj}|||d|}|S)Nr)devicer )shapetorchrandpermrrandrrfloat)rr batch_sizeZpermutedZ augmentedZis_augrrrrrs   *z%FakeFakesGenerator._make_blend_targetcCs|j\}}}}tjdd|d|j|jdjddddj|d|d|d}|j|}t||f|}||9}|d|d}||j|d j d j dddddf8}||j|d j d j dddddfd}|j ddd|S) Nrr )stepsrdtype gư>)minmaxr*r*r*r*) rrlinspacerr&viewexpandrrr(valuesr)clamp_)rrr#_heightwidthgradZ grad_for_minrrrr"s  (,z,FakeFakesGenerator._fill_masks_with_gradientN)rrr)__name__ __module__ __qualname__rrrrrrrrrs r)rkorniarZkornia.augmentationrrrrrrrs