blob_rand_cifar.py
def perturb(self, x_nat, x_adv, y, sess):
    """Given a set of examples (x_nat, y), returns a set of adversarial
       examples within epsilon of x_nat in l_infinity norm."""
      
    batch_size = x_adv.shape[0]  
    
    for epoch in range(10):

#       x_adv = np.array(x_adv).reshape(x_adv.shape[0], 32,32,3)
    
      grad = sess.run(self.grad, feed_dict={self.model.x_input: np.array(x_adv).reshape(x_adv.shape[0], 32,32,3),
                                           self.model.y_input: y})
                                         
      grad = np.array(grad).reshape(grad.shape[0], 32 * 32 * 3)
      kxy, dxkxy = self.svgd_kernel(x_adv)
#       kxy, dxkxy = self.svgd_kernel(np.array(x_adv).reshape(x_adv.shape[0], 32,32,3))
#       print("kxy shape", kxy.shape)
#       print("grad shape", grad.shape)
      x_adv += self.a * np.sign(c*(-(np.matmul(kxy, -grad) + dxkxy)/batch_size) + grad)
  
        
      x_adv = np.clip(x_adv, x_nat - self.epsilon, x_nat + self.epsilon) 
      x_adv = np.clip(x_adv, 0, 255) # ensure valid pixel range


    return x_adv
Given a set of examples (x_nat, y), returns a set of adversarial
       examples within epsilon of x_nat in l_infinity norm.
Given a set of examples (x_nat, y), returns a set of adversarial
examples within epsilon of x_nat in l_infinity norm.
Given a set of examples ( x_nat y ) returns a set of adversarial examples within epsilon of x_nat in l_infinity norm .
def perturb(self, x_nat, x_adv, y, sess):
    batch_size = x_adv.shape[0]  
    for epoch in range(10):
      grad = sess.run(self.grad, feed_dict={self.model.x_input: np.array(x_adv).reshape(x_adv.shape[0], 32,32,3),
                                           self.model.y_input: y})
      grad = np.array(grad).reshape(grad.shape[0], 32 * 32 * 3)
      kxy, dxkxy = self.svgd_kernel(x_adv)
      x_adv += self.a * np.sign(c*(-(np.matmul(kxy, -grad) + dxkxy)/batch_size) + grad)
      x_adv = np.clip(x_adv, x_nat - self.epsilon, x_nat + self.epsilon) 
      x_adv = np.clip(x_adv, 0, 255) 
    return x_adv
def perturb ( self , x_nat , x_adv , y , sess ) : batch_size = x_adv . shape [ 0 ] for epoch in range ( 10 ) : grad = sess . run ( self . grad , feed_dict = { self . model . x_input : np . array ( x_adv ) . reshape ( x_adv . shape [ 0 ] , 32 , 32 , 3 ) , self . model . y_input : y } ) grad = np . array ( grad ) . reshape ( grad . shape [ 0 ] , 32 * 32 * 3 ) kxy , dxkxy = self . svgd_kernel ( x_adv ) x_adv += self . a * np . sign ( c * ( - ( np . matmul ( kxy , - grad ) + dxkxy ) / batch_size ) + grad ) x_adv = np . clip ( x_adv , x_nat - self . epsilon , x_nat + self . epsilon ) x_adv = np . clip ( x_adv , 0 , 255 ) return x_adv
Given a set of examples (x_nat, y), returns a set of adversarial
examples within epsilon of x_nat in l_infinity norm.
Given a set of examples ( x_nat y ) returns a set of adversarial examples within epsilon of x_nat in l_infinity norm .
"""Given a set of examples (x_nat, y), returns a set of adversarial
       examples within epsilon of x_nat in l_infinity norm.""" #       x_adv = np.array(x_adv).reshape(x_adv.shape[0], 32,32,3) #       kxy, dxkxy = self.svgd_kernel(np.array(x_adv).reshape(x_adv.shape[0], 32,32,3)) #       print("kxy shape", kxy.shape) #       print("grad shape", grad.shape) # ensure valid pixel range
self
x_nat
x_adv
y
sess