<s> """<STR_LIT>""" <EOL> import itertools <EOL> import numpy as np <EOL> import ghalton <EOL> import data <EOL> import icdf <EOL> def build_transforms ( ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> transforms = [ ] <EOL> k = kwargs . keys ( ) <EOL> combinations = list ( itertools . product ( * kwargs . values ( ) ) ) <EOL> combinations = [ dict ( zip ( k , vals ) ) for vals in combinations ] <EOL> for comb in combinations : <EOL> tf = data . build_augmentation_transform ( ** comb ) <EOL> transforms . append ( tf ) <EOL> return transforms <EOL> def build_quasirandom_transforms ( num_transforms , zoom_range , rotation_range , shear_range , translation_range , do_flip = True , allow_stretch = False ) : <EOL> gen = ghalton . Halton ( <NUM_LIT:7> ) <EOL> uniform_samples = np . array ( gen . get ( num_transforms ) ) <EOL> tfs = [ ] <EOL> for s in uniform_samples : <EOL> shift_x = icdf . uniform ( s [ <NUM_LIT:0> ] , * translation_range ) <EOL> shift_y = icdf . uniform ( s [ <NUM_LIT:1> ] , * translation_range ) <EOL> translation = ( shift_x , shift_y ) <EOL> rotation = icdf . uniform ( s [ <NUM_LIT:2> ] , * rotation_range ) <EOL> shear = icdf . uniform ( s [ <NUM_LIT:3> ] , * shear_range ) <EOL> if do_flip : <EOL> flip = icdf . bernoulli ( s [ <NUM_LIT:4> ] , p = <NUM_LIT:0.5> ) <EOL> else : <EOL> flip = False <EOL> log_zoom_range = [ np . log ( z ) for z in zoom_range ] <EOL> if isinstance ( allow_stretch , float ) : <EOL> log_stretch_range = [ - np . log ( allow_stretch ) , np . log ( allow_stretch ) ] <EOL> zoom = np . exp ( icdf . uniform ( s [ <NUM_LIT:5> ] , * log_zoom_range ) ) <EOL> stretch = np . exp ( icdf . uniform ( s [ <NUM_LIT:6> ] , * log_stretch_range ) ) <EOL> zoom_x = zoom * stretch <EOL> zoom_y = zoom / stretch <EOL> elif allow_stretch is True : <EOL> zoom_x = np . exp ( icdf . uniform ( s [ <NUM_LIT:5> ] , * log_zoom_range ) ) <EOL> zoom_y = np . exp ( icdf . uniform ( s [ <NUM_LIT:6> ] , * log_zoom_range ) ) <EOL> else : <EOL> zoom_x = zoom_y = np . exp ( icdf . uniform ( s [ <NUM_LIT:5> ] , * log_zoom_range ) ) <EOL> tfs . append ( data . build_augmentation_transform ( ( zoom_x , zoom_y ) , rotation , shear , translation , flip ) ) <EOL> return tfs </s>
