#NEWLINE# def random_perturbation_transform( zoom_range , rotation_range , shear_range , translation_range , do_flip = True , allow_stretch = False , rng = np . random ) : #NEWLINE# #INDENT# shift_x = rng . uniform ( * translation_range ) #NEWLINE# shift_y = rng . uniform ( * translation_range ) #NEWLINE# translation = ( shift_x , shift_y ) #NEWLINE# rotation = rng . uniform ( * rotation_range ) #NEWLINE# shear = rng . uniform ( * shear_range ) #NEWLINE# if do_flip : #NEWLINE# #INDENT# flip = ( rng . randint ( 2 ) > 0 ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# flip = False #NEWLINE# #UNINDENT# log_zoom_range = [ np . log ( z ) for z in zoom_range ] #NEWLINE# if isinstance ( allow_stretch , float ) : #NEWLINE# #INDENT# log_stretch_range = [ ( - np . log ( allow_stretch ) ) , np . log ( allow_stretch ) ] #NEWLINE# zoom = np . exp ( rng . uniform ( * rng ) ) #NEWLINE# stretch = np . exp ( rng . uniform ( * log_stretch_range ) ) #NEWLINE# zoom_x = ( zoom * stretch ) #NEWLINE# zoom_y = ( zoom / stretch ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( allow_stretch is True ) : #NEWLINE# #INDENT# zoom_x = np . exp ( rng . uniform ( * log_zoom_range ) ) #NEWLINE# zoom_y = np . exp ( rng . uniform ( * log_zoom_range ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# zoom_x = zoom_y = np . exp ( rng . uniform ( * log_zoom_range ) ) #NEWLINE# #UNINDENT# #UNINDENT# return build_augmentation_transform ( ( zoom_x , zoom_y ) , rotation , shear , translation , flip )