예제 #1
0
 def evaluate(self):
     return Evaluator.evaluate(self.vector, self.str_branch,
                               self.path_branch)
예제 #2
0
파일: test_defense.py 프로젝트: kjam/MagNet
## contained in the LICENCE file in this directory.

from setup_mnist import MNIST
from mn_utils import prepare_data
from worker import AEDetector, SimpleReformer, IdReformer, AttackData, Classifier, Operator, Evaluator
import mn_utils as utils


detector_I = AEDetector("./defensive_models/MNIST_I", p=2)
detector_II = AEDetector("./defensive_models/MNIST_II", p=1)
reformer = SimpleReformer("./defensive_models/MNIST_I")

id_reformer = IdReformer()
classifier = Classifier("./models/example_classifier")

detector_dict = dict()
detector_dict["I"] = detector_I
detector_dict["II"] = detector_II

operator = Operator(MNIST(), classifier, detector_dict, reformer)

idx = utils.load_obj("example_idx")
_, _, Y = prepare_data(MNIST(), idx)
f = "example_carlini_0.0"
testAttack = AttackData(f, Y, "Carlini L2 0.0")

evaluator = Evaluator(operator, testAttack)
evaluator.plot_various_confidences("defense_performance",
                                   drop_rate={"I": 0.001, "II": 0.001})

예제 #3
0
print('without reformer')
print(np.mean(predicted == np.argmax(lab, axis=1)), predicted)

thrs = operator.get_thrs(dr)
print(thrs)
passes, _ = operator.filter(adv, thrs)
print('rate of passing fooling', float(len(passes)) / len(dat))  #, passes)

exit(0)
for e in adv:
    show(e)

detector0 = detector_dict['I0']
detector1 = detector_dict['II0']

print(detector0.mark(dat))
print(detector1.mark(dat))
print(detector0.mark(adv))
print(detector1.mark(adv))
exit(0)

idx = utils.load_obj("example_idx")
_, _, Y = prepare_data(data, idx)
f = "example_carlini_0.0"
testAttack = AttackData(f, Y, "Carlini L2 0.0")

Attack(operator)
exit(0)
evaluator = Evaluator(operator, testAttack)
evaluator.plot_various_confidences("defense_performance", drop_rate=dr)