Skip to main content

Ahmed Shahin submission for leap labs task -- adversarial noise

Project description

Adversarial Generation Task

Problem: Adversarial Noise

The task involves developing a program that manipulates images by adding adversarial noise. This noise is designed to trick an image classification model into misclassifying the altered image as a specified target class, regardless of the original content.

You may select any pre-trained image classification model for this task. A model from the torchvision library is recommended, but not mandatory. The core challenge is to effectively introduce noise into the image in such a way that the model misclassifies it as the desired target class, without making the noise perceptible to a casual human viewer.

Input: The user will provide an image and specify a target class.

Output: The program should output an image that has been altered with adversarial noise. The altered image should be classified by the model as the target class, irrespective of the original image's content. The altered image should not be obviously different to the original.

My Approach

My approach depends on using gradient ascent to maximize the probability of the target class. The gradient ascent is applied to the input image, and the gradient is calculated with respect to the target class. The gradient ascent is applied iteratively to the input image until the model classifies the image as the target class. The update formula is as follows: $$ \hat{x} = x + \epsilon * \frac{d}{dx} \log p(y_{target}|x) $$ where:

  • $\hat{x}$ is the updated image
  • $x$ is the original image
  • $\epsilon$ is the step size
  • $p(y_{target}|x)$ is the probability of the target class given the image (softmax output of the model)
  • $\frac{d}{dx} \log p(y_{target}|x)$ is the gradient of the log probability of the target class with respect to the image

The user will provide an image and specify a target class and optionally specify the number of iterations, the step size, and the threshold for the probability of the target class. The program will output an image that has been altered with adversarial noise. The altered image should be classified by the model as the target class, irrespective of the original image's content. The altered image should not be obviously different from the original.

Sample output

The example below shows the original image, the target class, and the altered image. The altered image is classified as the target class by the model with high confidence. Example

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

leap_labs_task-0.1.1.tar.gz (5.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

leap_labs_task-0.1.1-py3-none-any.whl (6.3 kB view details)

Uploaded Python 3

File details

Details for the file leap_labs_task-0.1.1.tar.gz.

File metadata

  • Download URL: leap_labs_task-0.1.1.tar.gz
  • Upload date:
  • Size: 5.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.4 CPython/3.10.12 Linux/6.8.0-49-generic

File hashes

Hashes for leap_labs_task-0.1.1.tar.gz
Algorithm Hash digest
SHA256 55670b6525a137aad48e17530122863e29c234661a3ae1ed3549d50378cedfc7
MD5 2454ce680c8168a13bd009c7e3e65344
BLAKE2b-256 d67ec06bd6d4fa47b4e6f891c0b6319ae99240139d0eedc96c20ca4633c7f868

See more details on using hashes here.

File details

Details for the file leap_labs_task-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: leap_labs_task-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 6.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.4 CPython/3.10.12 Linux/6.8.0-49-generic

File hashes

Hashes for leap_labs_task-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 1b045d6a87597100ae8825e3974f7ae4aae8d443af1ae580eb8a625627715862
MD5 e3d2c17180eae668e219de2ad233f015
BLAKE2b-256 1b4fd8f9ff93973c55eb5d0e7a3dbfc2675018e67b9a781e4240bff365647b74

See more details on using hashes here.

Supported by

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