ran  autopep8 to fix comsmetics
@@ -41,6 +41,7 @@ class Loss(object):
warnings.warn("callable attacks are deprecated, switch to an Attack "
"subclass. callable attacks will not be supported after "
"2019-05-05.")
+
class Wrapper(Attack):
"""
Temporary wrapper class to be removed when deprecated callable
@@ -48,6 +49,7 @@ class Loss(object):
:param f: a callable object implementing the attack
"""
+
def __init__(self, f):
dummy_model = Model()
super(Wrapper, self).__init__(model=dummy_model)
@@ -123,6 +125,7 @@ class CrossEntropy(Loss):
1. - adv_coeff.
:param attack_params: dict, keyword arguments passed to `attack.generate`
"""
+
def __init__(self, model, smoothing=0., attack=None, pass_y=False,
adv_coeff=0.5, attack_params=None,
**kwargs):
@@ -173,6 +176,7 @@ class MixUp(Loss):
:param model: Model instance, the model on which to apply the loss.
:param beta: float, beta distribution parameter for MixUp.
"""
+
def __init__(self, model, beta, **kwargs):
del kwargs
Loss.__init__(self, model, locals())
@@ -222,6 +226,7 @@ class FeaturePairing(Loss):
class WeightDecay(Loss):
"""Weight decay"""
+
def fprop(self, x, y, **kwargs):
terms = [tf.nn.l2_loss(param)
for param in self.model.get_params()
@@ -333,6 +338,7 @@ class LossMixUp(Loss):
class SNNLCrossEntropy(CrossEntropy):
EPSILON = 0.00001
+
def __init__(self,
model,
temperature=100.,
@@ -380,7 +386,8 @@ class SNNLCrossEntropy(CrossEntropy):
@staticmethod
def pick_probability(x, temp, cos_distance):
- f = SNNLCrossEntropy.fits(x, x, temp, cos_distance) - tf.eye(tf.shape(x)[0])
+ f = SNNLCrossEntropy.fits(
+ x, x, temp, cos_distance) - tf.eye(tf.shape(x)[0])
return f / (
SNNLCrossEntropy.EPSILON + tf.expand_dims(tf.reduce_sum(f, 1), 1))
@@ -404,6 +411,7 @@ class SNNLCrossEntropy(CrossEntropy):
def optimizied_temp_SNNL(x, y, initial_temp, cos_distance):
t = tf.Variable(1, dtype=tf.float32, trainable=False, name="temp")
# we use inverse_temp because it seems to be more stable when optimizing
+
def inverse_temp(t):
return tf.div(initial_temp, t)
ent_loss = SNNLCrossEntropy.SNNL(x, y, inverse_temp(t), cos_distance)
@@ -411,7 +419,6 @@ class SNNLCrossEntropy(CrossEntropy):
inverse_t = inverse_temp(updated_t)
return SNNLCrossEntropy.SNNL(x, y, inverse_t, cos_distance)
-
def fprop(self, x, y, **kwargs):
cross_entropy = CrossEntropy.fprop(self, x, y, **kwargs)
self.layers = [self.model.get_layer(x, name) for name in self.layer_names]
