in ebm_sandbox.py [0:0]
def construct_steps(weights, X, Y_GT, model, target_vars):
n = 50
scale_fac = 1.0
# if FLAGS.task == 'cycleclass':
# scale_fac = 10.0
X_mods = []
X = tf.identity(X)
mask = np.zeros((1, 32, 32, 3))
if FLAGS.task == "boxcorrupt":
mask[:, 16:, :, :] = 1
else:
mask[:, :, :, :] = 1
mask = tf.Variable(tf.convert_to_tensor(mask, dtype=tf.float32), trainable=False)
# X_targ = tf.placeholder(shape=(None, 32, 32, 3), dtype = tf.float32)
for i in range(FLAGS.num_steps):
X_old = X
X = X + tf.random_normal(tf.shape(X), mean=0.0, stddev=0.005*scale_fac) * mask
energy_noise = model.forward(X, weights, label=Y_GT, reuse=True)
x_grad = tf.gradients(energy_noise, [X])[0]
if FLAGS.proj_norm != 0.0:
x_grad = tf.clip_by_value(x_grad, -FLAGS.proj_norm, FLAGS.proj_norm)
X = X - FLAGS.step_lr * x_grad * scale_fac * mask
X = tf.clip_by_value(X, 0, 1)
if i % n == (n-1):
X_mods.append(X)
print("Constructing step {}".format(i))
target_vars['X_final'] = X
target_vars['X_mods'] = X_mods