import random import numpy as np import keras.backend as K def averageDistance(yTrue,yPred): squares=K.square(yTrue-yPred) distances=K.sqrt(K.sum(squares,-1)) return K.mean(distances,-1) def transform(image,label): if random.choice((True,False)): image=image[::-1] # reflect vertically label[...,1]*=-1 # reflect y values label=label[::-1,...] # switch back to counter-clockwise order rot=random.randint(0,3) image=np.rot90(image,rot) if rot==1: label=label[...,::-1] label[...,1]*=-1 elif rot==2: label*=-1 elif rot==3: label=label[...,::-1] label[...,0]*=-1 k=0 val=2 for (i,point) in enumerate(label): # rotate the upper-leftmost point to the first position v=sum(point) if v