inception_model = BinaryLogisticRegressionWithLBFGS( input_dim=input_dim, weight_decay=weight_decay, max_lbfgs_iter=max_lbfgs_iter, num_classes=num_classes, batch_size=batch_size, data_sets=data_sets, initial_learning_rate=initial_learning_rate, keep_probs=keep_probs, decay_epochs=decay_epochs, mini_batch=False, train_dir='output', log_dir='log', model_name='%s_inception_onlytop' % dataset_name) inception_model.train() inception_predicted_loss_diffs = inception_model.get_influence_on_test_loss( [test_idx], np.arange(len(inception_model.data_sets.train.labels)), force_refresh=True) x_test = X_test[test_idx, :] y_test = Y_test[test_idx] distances = dataset.find_distances(x_test, X_train) flipped_idx = Y_train != y_test rbf_margins_test = rbf_model.sess.run(rbf_model.margin, feed_dict=rbf_model.all_test_feed_dict) rbf_margins_train = rbf_model.sess.run(rbf_model.margin, feed_dict=rbf_model.all_train_feed_dict)
input_dim = 2048 top_model = BinaryLogisticRegressionWithLBFGS( input_dim=input_dim, weight_decay=weight_decay, max_lbfgs_iter=max_lbfgs_iter, num_classes=num_classes, batch_size=batch_size, data_sets=inception_data_sets, initial_learning_rate=initial_learning_rate, keep_probs=keep_probs, decay_epochs=decay_epochs, mini_batch=False, train_dir='output', log_dir='log', model_name=top_model_name) top_model.train() weights = top_model.sess.run(top_model.weights) orig_weight_path = 'output/inception_weights_%s.npy' % top_model_name np.save(orig_weight_path, weights) with full_graph.as_default(): full_model.load_weights_from_disk(orig_weight_path, do_save=False, do_check=True) full_model.reset_datasets() ### Create poisoned dataset print('Creating poisoned dataset...') # First pass was with step_size 0.02, 100 iterations, num_to_poison=2 # Second pass with step_size 0.01 and 200 iterations, num_to_poison=3
tf_model = BinaryLogisticRegressionWithLBFGS( input_dim=input_dim, weight_decay=weight_decay, max_lbfgs_iter=max_lbfgs_iter, num_classes=num_classes, batch_size=batch_size, data_sets=data_sets, initial_learning_rate=initial_learning_rate, keep_probs=keep_probs, decay_epochs=decay_epochs, mini_batch=False, train_dir='output', log_dir='log', model_name='spam_logreg_lbfgs') tf_model.train() test_idx = 8 actual_loss_diffs, predicted_loss_diffs_cg, indices_to_remove = experiments.test_retraining( tf_model, test_idx, iter_to_load=0, force_refresh=False, num_to_remove=500, remove_type='maxinf', random_seed=0) # LiSSA np.random.seed(17) predicted_loss_diffs_lissa = tf_model.get_influence_on_test_loss( [test_idx],
def run_spam(ex_to_leave_out=None, num_examples=None): """ If ex_to_leave_out is None, don't leave any out. Otherwise, leave out the example at the specified index. If num_examples is None, use all the examples """ data_sets = load_spam(ex_to_leave_out=ex_to_leave_out, num_examples=num_examples) # "Spam" and "Ham" num_classes = 2 input_dim = data_sets.train.x.shape[1] weight_decay = 0.0001 # weight_decay = 1000 / len(lr_data_sets.train.labels) batch_size = 100 initial_learning_rate = 0.001 keep_probs = None decay_epochs = [1000, 10000] max_lbfgs_iter = 1000 tf.reset_default_graph() tf_model = BinaryLogisticRegressionWithLBFGS( input_dim=input_dim, weight_decay=weight_decay, max_lbfgs_iter=max_lbfgs_iter, num_classes=num_classes, batch_size=batch_size, data_sets=data_sets, initial_learning_rate=initial_learning_rate, keep_probs=keep_probs, decay_epochs=decay_epochs, mini_batch=False, train_dir='output', log_dir='log', model_name='spam_logreg') tf_model.train() # NMV 7/26: appears to be unused right now. # X_train = np.copy(tf_model.data_sets.train.x) # Y_train = np.copy(tf_model.data_sets.train.labels) # X_test = np.copy(tf_model.data_sets.test.x) # Y_test = np.copy(tf_model.data_sets.test.labels) # num_train_examples = Y_train.shape[0] # num_flip_vals = 6 # num_check_vals = 6 # num_random_seeds = 40 # dims = (num_flip_vals, num_check_vals, num_random_seeds, 3) # fixed_influence_loo_results = np.zeros(dims) # fixed_loss_results = np.zeros(dims) # fixed_random_results = np.zeros(dims) #flipped_results = np.zeros((num_flip_vals, num_random_seeds, 3)) orig_results = tf_model.sess.run( [tf_model.loss_no_reg, tf_model.accuracy_op], feed_dict=tf_model.all_test_feed_dict) #print('Orig loss: %.5f. Accuracy: %.3f' % (orig_results[0], orig_results[1])) result = [tf_model, orig_results] return result