GithubHelp home page GithubHelp logo

sposhiy33 / adversarialdefense Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 87 KB

Defending Neural Networks from Adversarial Attacks

License: GNU General Public License v3.0

Python 100.00%
deep-learning neural-network adversarial-examples fast-gradient-sign-attack

adversarialdefense's Introduction

Adversarial Defense

This repo contains the code produced by Shrey Poshiya during the summer 2021 internship at the Institute for Computing in Research.

License: GNU General Public License v3.0

What are Adversarial Examples

Recent developments in Deep Learning (DL) has allowed for its implementation into a wide array of applications. With deep learning being used in many saftey critical environments (ex. healthcare and transporation), it is becoming increasingly important that these aritifical neural networks can succesfully identify the given inputs.

It is been found that carefully altered inputs, called adversarial examples can trick neural networks. These adversarial examples are usually produced by intentionally adding noise to the input image. The most dangerous aspect of these adversarial examples is that the difference between the original input image and the altered one is virtually imperceptable to the human eye. The combination of being able to fool the network while seeming harmless to the human poses a great danger to the validity of the neural nets.

Here is an example of an adversraial example: image

How are Adversarial Examples Generated

One popular strategy to produce adversarial examples is uing the Fast Gradient Sign Method (FGSM). This strategy exploits the gradient, a numeric calculation that gives us information on how to adjust the parameters of the model to minmize the deviation between the actual output and the output estimated by the network. The gradient is a vector that signals in which direction the loss in the loss function increases. In order to create a good neural network (in which the loss is minimized), we sould move in the opposite direction of the gradient and change the parameters of the model in accordance (esentailly we are finding the local minimum of the loss function). The Fast Gradient Sign Method expoilts the generated gradients to create an image that maximizes the loss/cost.

image

image: Our output adversarial image

image: Original Input Image

image: The label of the Input Image

image: Epsilon: A constant that dictates the intensity of the perturbations (the noise) applied to the input image

image: The Neural Network model

image: The Loss

Contents of this Repo

This repo contains three different folders. Each folder contains scripts for three different Neural Networks (the folder name specifies the name of the dataset that specfic network is using: MNIST, fashion-MNIST, Cifar10).

The folder has the following contents:

{NameOfDataset}.py = This script creates a convolutional neural network and trains the network using tensorflow.keras

Adv_Gen_{NameOfDataset}.py = This scripts generates adversarial images at a given epsilon value. It uses the generated adversarial images to test accuracy of the model. The ouput of this script should give you accuracy values of the models at differnt epsilon values. Using this generated data should produce a plot (using matplotlib.pyplot) that compares accuracy to epsilon value.

blur_{NameOfDataset}.py = This script blurs the generated adverarial images. This should esentially "blur" out the perturbations in the image. The accuracy when the blurred adverarial images are used to test the accuracy of the model should be higher than when the adversarial images are used to test the accuracy (In fact the accuracy of the original dataset versus the blurred adversarial iamges was very close when a certain amount of "blurring" was applied. In my tests the discrpancy between the two accuracies was only -0.13% to -0.25%). This scripts uses Guassian Blurring to blur the adverarial images. The output of this script gives you the accuracy values at different sigma values (sigma is the constant that dictates the strength of the blurring). You can also control the epsilon value of the adverarial images you would like to blur.

BEWARE: Running these scripts take a toll on your hardware. Make sure to have plenty of free memory before running these programs.

Intructions

Install lastest version of python

To install the required libraries, run the following ocmman in the terminal:

$ pip3 install matplotlib numpy scipy tensorflow

To clone this repo, run the following git command:

$ git clone https://github.com/sposhiy33/AdversarialDefense.git

Navigate to folder in terminal:

$ cd [FILE/PATH/HERE]

From there, to run program, run the command:

$ python3 [enter file name here]

You can run any file independently. When you run a script, it sould start of by training the network

image

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.