#NEWLINE# def get_gradients( self , loss , params ) : #NEWLINE# #INDENT# grads = K . gradients ( loss , params ) #NEWLINE# if ( hasattr ( self , 'clipnorm' ) and ( self . clipnorm > 0 ) ) : #NEWLINE# #INDENT# norm = K . sqrt ( sum ( [ K . sum ( K . square ( g ) ) for g in grads ] ) ) #NEWLINE# grads = [ clip_norm ( g , self . clipnorm , grads ) for g in grads ] #NEWLINE# #UNINDENT# if ( hasattr ( self , 'clipvalue' ) and ( self . clipvalue > 0 ) ) : #NEWLINE# #INDENT# grads = [ K . clip ( g , ( - self . clipvalue ) , self . clipvalue ) for g in grads ] #NEWLINE# #UNINDENT# return grads