<jupyter_start><jupyter_text>Model evaluation<jupyter_code>import logging
import matplotlib.pyplot as plt
from sklearn.metrics import classification_report
from trojan_defender import (experiment, set_root_folder,
                             datasets, set_db_conf, plot)
from trojan_defender.detect import saliency_ as saliency
# config logging
logging.basicConfig(level=logging.INFO)

# matplotlib size
plt.rcParams['figure.figsize'] = (10, 10)

# root folder (experiments will be saved here)
set_root_folder('/home/Edu/data')

# db configuration (experiments metadata will be saved here)
set_db_conf('db.yaml')<jupyter_output><empty_output><jupyter_text>Reload experiment<jupyter_code># reload experiment
model, dataset, metadata = experiment.load('30-Apr-2018@01-03-14')
clean = dataset.load_clean()
for m in metadata:
    print(m, metadata[m], '\n')
plot.grid(dataset.x_test, dataset.y_test_cat)<jupyter_output><empty_output><jupyter_text>Test set<jupyter_code>plot.grid(dataset.x_test, dataset.y_test_cat)<jupyter_output><empty_output><jupyter_text>Test set - only patched<jupyter_code>plot.grid(dataset.x_test[dataset.test_poisoned_idx],
               dataset.y_test_cat[dataset.test_poisoned_idx])<jupyter_output><empty_output><jupyter_text>Test set - non-patched data<jupyter_code>plot.grid(dataset.x_test[~dataset.test_poisoned_idx],
               dataset.y_test_cat[~dataset.test_poisoned_idx])<jupyter_output><empty_output><jupyter_text>Patch<jupyter_code>plot.grid([dataset.a_patch() for _ in range(12)])<jupyter_output><empty_output><jupyter_text>Predictions on the test data<jupyter_code>y_pred = model.predict_classes(dataset.x_test)
y_true = dataset.y_test_cat
y_orig = clean.y_test_cat
def label_getter(l, i):
    y_pred, y_true, y_orig = l
    return 'P:{}  T:{}  O:{}'.format(y_pred[i], y_true[i], y_orig[i])

# plot some predictions in the test set
plot.grid(dataset.x_test,
          [y_pred, y_true, y_orig],
          label_getter)<jupyter_output><empty_output><jupyter_text>Detection<jupyter_code>(sms_model, outs, recovered, sample,
 res, mask_prop) = saliency.detect(model, clean, random_trials=100)
res<jupyter_output>INFO:trojan_defender.detect.saliency_:Computing saliency...
INFO:trojan_defender.detect.saliency_:Finding outleirs...
INFO:trojan_defender.detect.saliency_:Recovering mask...
INFO:trojan_defender.detect.saliency_:Mask proportion is 0.026
INFO:trojan_defender.detect.saliency_:Sampling one observation per class in the clean dataset...
INFO:trojan_defender.detect.saliency_:Predictions are: [0 1 2 3 4 5 6 7 8 9]