示例#1
0
 def forward(self, data, state):
     x_interp, interp_score = data
     gradient_x_interp = get_gradient(tf.reduce_sum(interp_score),
                                      x_interp,
                                      higher_order=True,
                                      tape=state['tape'])
     grad_l2 = tf.math.sqrt(
         tf.reduce_sum(tf.math.square(gradient_x_interp), axis=[1, 2, 3]))
     gp = tf.math.square(grad_l2 - 1.0)
     return gp
示例#2
0
 def forward(self, data, state):
     x_interp, interp_score = data
     gradient_x_interp = get_gradient(torch.sum(interp_score), x_interp, higher_order=True)
     grad_l2 = torch.sqrt(torch.sum(gradient_x_interp**2, dim=(1, 2, 3)))
     gp = (grad_l2 - 1.0)**2
     return gp