Skip to main content

A modular and easy-to-use framework of adversarial machine learning algorithms: https://en.m.wikipedia.org/wiki/Adversarial_machine_learning

Project description

adv-ml

Docs

See https://irad-zehavi.github.io/adv-ml/

Install

pip install adv_ml

How to use

How to Use

As an nbdev library, adv-ml supports import * (without importing unwanted symbols):

from adv_ml.all import *

Adversarial Examples

mnist = MNIST()
classifier = MLP(10)
learn = Learner(mnist.dls(), classifier, metrics=accuracy)
learn.fit(1)
epoch train_loss valid_loss accuracy time
0 0.154410 0.177410 0.953900 00:32
sub_dsets = mnist.valid.random_sub_dsets(64)
learn.show_results(shuffle=False, dl=sub_dsets.dl())

attack = InputOptimizer(classifier, LinfPGD(epsilon=.15), n_epochs=10, epoch_size=20)
perturbed_dsets = attack.perturb(sub_dsets)
epoch train_loss time
0 -4.302573 00:00
1 -7.585707 00:00
2 -9.014968 00:00
3 -9.700548 00:00
4 -10.075110 00:00
5 -10.296636 00:00
6 -10.433834 00:00
7 -10.521141 00:00
8 -10.577673 00:00
9 -10.614740 00:00
learn.show_results(shuffle=False, dl=TfmdDL(perturbed_dsets))

Data Poisoning

patch = torch.tensor([[1, 0, 1],
                      [0, 1, 0],
                      [1, 0, 1]]).int()*255
trigger = F.pad(patch, (25, 0, 25, 0)).numpy()
learn = Learner(mnist.dls(), MLP(10), metrics=accuracy, cbs=BadNetsAttack(trigger, '0'))
learn.fit_one_cycle(1)
epoch train_loss valid_loss accuracy time
0 0.103652 0.097075 0.971400 00:23

Benign performance:

learn.show_results()

Attack success:

learn.show_results(2)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

adv-ml-0.0.4.tar.gz (22.0 kB view details)

Uploaded Source

Built Distribution

adv_ml-0.0.4-py3-none-any.whl (20.8 kB view details)

Uploaded Python 3

File details

Details for the file adv-ml-0.0.4.tar.gz.

File metadata

  • Download URL: adv-ml-0.0.4.tar.gz
  • Upload date:
  • Size: 22.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.16

File hashes

Hashes for adv-ml-0.0.4.tar.gz
Algorithm Hash digest
SHA256 fb99423d52072d8e4e1919e8fd3f59c6f259c2e3b756bc38ea0849b9f0437927
MD5 2aaa95cf2e948b6a85c83879b8dc8a8e
BLAKE2b-256 8d6208d24ee327042bf70bef28680a06253757222a0c24032da9ecdf98c171fa

See more details on using hashes here.

File details

Details for the file adv_ml-0.0.4-py3-none-any.whl.

File metadata

  • Download URL: adv_ml-0.0.4-py3-none-any.whl
  • Upload date:
  • Size: 20.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.16

File hashes

Hashes for adv_ml-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 a1c284973cac35915fa50ad4ae513a7069b594ece6faeb32fda5e869ad0e013f
MD5 8ee434a5c26a9c81ebf7b553973f7112
BLAKE2b-256 d8afb3dfb924c69cdb1084ce08107c4072f5e5e94414489803f8da6d7dddde4e

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page