示例#1
0
y_test_tf = tf.placeholder(tf.float32, shape=(1, nclass))
sigma_tf = tf.placeholder(tf.float32, shape=(1))

input_shape = X_test.shape[1:]
n = 3
version = 1
if version == 1:
    depth = n * 6 + 2
elif version == 2:
    depth = n * 9 + 2

# Model parameters
with tf.variable_scope('test_model', reuse=False):
    if version == 1:
        model = resnet_v1(input_shape=input_shape, depth=depth)
    elif version == 2:
        model = resnet_v2(input_shape=input_shape, depth=depth)

var_cls = model.trainable_weights
saver_model = tf.train.Saver(var_cls, max_to_keep=None)

x_test_tf_reshaped = tf.reshape(x_test_tf, [-1, height * width * nch])
repeated_x_test_tf = tf.tile(x_test_tf_reshaped, [1, batch_size])
repeated_x_test_tf = tf.reshape(repeated_x_test_tf, [-1, height * width * nch])
repeated_x_test_tf = tf.reshape(repeated_x_test_tf, [-1, height, width, nch])

noise = tf.random.normal(repeated_x_test_tf.shape) * sigma_tf
noisy_inputs = repeated_x_test_tf + noise

cls_test = KerasModelWrapper(model).get_logits(noisy_inputs)
示例#2
0
x_poisoned_tf = tf.placeholder(tf.float32, shape=(None, height, width, nch))
y_poisoned_tf = tf.placeholder(tf.float32, shape=(None, nclass))

x_original_tf = tf.placeholder(tf.float32, shape=(None, height, width, nch))

input_shape = X_test.shape[1:]
n = 3
version = 1
if version == 1:
    depth = n * 6 + 2
elif version == 2:
    depth = n * 9 + 2

# Model parameters
with tf.variable_scope('test_model', reuse=False):
    test_model = resnet_v1(input_shape=input_shape, depth=depth)

var_test = test_model.trainable_weights
saver_model_test = tf.train.Saver(var_test, max_to_keep=None)

with tf.variable_scope('train_model', reuse=False):
    train_model = resnet_v1(input_shape=input_shape, depth=depth)

var_train = train_model.trainable_weights
saver_model_train = tf.train.Saver(var_train, max_to_keep=None)

bl_poisoning = bilevel_poisoning(
    sess, x_train_tf, x_val_tf, x_test_tf, x_poisoned_tf, x_original_tf,
    y_train_tf, y_val_tf, y_val_class_tf, y_test_tf, y_poisoned_tf,
    batch_size_poisoned, height, width, nch, nclass, val_batch_size,
    batch_size_clean, k_macer, sigma_macer, beta_macer, train_model,