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.2.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.2-py3-none-any.whl (6.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: leap_labs_task-0.1.2.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.2.tar.gz
Algorithm Hash digest
SHA256 54904f595f34a51df256d991aecc9366bfd4bb3740a72a89e08bc94f26d48558
MD5 c6dafcf364f3128f45df90b3dd6d16fe
BLAKE2b-256 3ad22aca1c90e5332b9301059cf191162a41fe9805e9be05de3ddad54c9a46e5

See more details on using hashes here.

File details

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

File metadata

  • Download URL: leap_labs_task-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 6.2 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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 c361c759bfc1018b52e214c13dfdf59377d501fdae37ab4075df5871ccb50ab0
MD5 dd4b16db461126a482185d339e4b4d15
BLAKE2b-256 493d5a18499699a4cfc9f943ef2626938be8fc25cf618fe5867adf3f58156abe

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