Giter VIP home page Giter VIP logo

black-box-attacks's Introduction

Black-Box Attacks on Neural Networks

Abstract

The paper[1] discusses an algorithm which allows us to craft an adversarial attack on black box networks (for classification). The attacker has no knowledge of internals or training data of the victim.

The solution presented treats the black box as an oracle and gets the output for several inputs and trains a substitute model on this data. Then adversarial samples are created by a white box attack on this substituted model. These adversarial samples work well to attack on the black box.

In this project, by the time of midterm review, we implemented this algorithm on MNIST dataset. Now, we have tried to implement this on object detection on COCO dataset. We separate the bounding boxes of object detected as new images, create adversarial example from them, and stitch the adversarial examples into the original image.

Requirements

python >=3.5 -> python == 3.10
numpy
torch
torchvision
matplotlib
tensorflow -> delete
tensorboard -> delete
terminaltables -> delete
pillow
tqdm
libtiff -> changed to tifffile

Setup Instructions

  1. Install the requirements
  2. Clone This directory
git clone https://github.com/darth-c0d3r/black_box_attacks
  1. Get COCO dataset

For attack on object detection

  • Create substitute model
python3 main_script.py --yolo

It asks to save the model. Give it a proper name. The model is saved in the folder saved_models/

  • Create adversarial samples
python3 main_script.py --adv

It asks for which substitute model to use, num_samples to be generated. This generates the adversarial samples and stores them in directory adv_samples/

  • Stitch the adversarial examples generated to original image
python3 main_script.py --stitch

You can see the images in stitched_images/ directory

  • Test them with black box model
python3 main_script.py --yolotest

For attack on MNIST dataset

cd black_box_attack_classification
  • Create black box model
python3 main_script.py --bb

It asks to save the model. Give it a proper name. The mode lis saved in the folder saved_models/

  • Create substitute model
python3 main_script.py --sub

It asks which black box model to use. Give it the model name from saved_models/. It asks to save the model. Give it a proper name. The mode lis saved in the folder saved_models/

  • Create adversarial samples
python3 main_script.py --adv

It asks for which substitute model to use, num_samples to be generated. This generates the adversarial samples and stores them in directory adv_samples/

  • Test them with black box model
python3 main_script.py --test

Results

Additional Details

This file creates different datasets.

This file contains various options to run different steps in the project

This file gets output from the oracle for a given input

This gets predictions from the black box for inputs given

This creates model

This contains code to stitch the adversarial sample generated to original photo

This file implements the Substitute DNN training algorithm given in paper[1].
For oracle Õ, a maximum number maxρ of substitute training epochs, a substitute architecture F and initial training set S0.
Input: Õ, maxρ , S0 , λ
1: Define architecture F
2: for ρ ∈ 0 .. maxρ − 1 do
3: D ← {(x, Õ(x)) : x ∈ Sρ} // Label the substitute training
4: 0F ← train(F, D) // Train F on D to evaluate parameters θF
5: S(ρ+1) ← {x + λ · sgn(JF [Õ(x)]) : x ∈ Sρ} ∪ Sρ // Perform Jacobian-based dataset augmentation
6: end for
7: return θF

The function create_dataset() creates dataset out of the samples generated and augment_dataset() function augments it to the current dataset.

This file trains the model

This file contains helper functions

This file creates adversarial samples based on the white box (substitute) model

References

Papers

  1. Practical Black-Box Attacks against Machine Learning
  2. On the Robustness of Semantic Segmentation Models to Adversarial Attacks

Pre-trained model used in object detection

Dataset used

black-box-attacks's People

Contributors

nikhil-t01 avatar darth-c0d3r avatar kaito25atugich avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.