Giter VIP home page Giter VIP logo

nightshade-release's Introduction

NIGHTSHADE

This repo contains the research code release for Nightshade.

โš ๏ธ If you plan to use Nightshade to protect your own copyrighted content, please use our MacOS/Windows prototype on our webpage. For details on the differences, please checkout the FAQ below.

OVERVIEW

The repo contains code to generate Nightshade data for a source concept (e.g. "dog"). Specifically,

  1. The code first identify an optimal set of clean image/text pairs from a pool of clean data from the source concept. This step is designed to find a good set of text prompts to use for the poison. We select data from LAION dataset in our experiments (details in Section 5.2 of the paper).
  2. We optimize a perturbation on each of the selected candidate images.

HOW TO

Step 1: Candidate Data Selection

We first extract a desired set of clean image/text pairs as the starting point of poison generation. Given a source concept (e.g. "dog"), you need to collect a large set (> 500) image/text pairs that contain the source concept (e.g. dog images with their corresponding text prompts). In the paper, we used images from LAION and ConceptualCaption dataset. If you do not have text prompts, you can use BLIP or similar techniques to generate the prompts or simply use "a photo of X" for the prompts.

Data format: To better store longer prompts, we use pickle files for image/text pairs. Each pickle file contains a numpy image (key "img") and its corresponding text prompt (key "text"). You can download some example data from here.

Next, run data_extraction.py to select a set of 100 poison candidates. python3 data_extraction.py --directory data/ --concept dog --num 100

Step 2: Poison Generation

Next, we add perturbation to the images given a target concept (e.g. "cat"). python3 data_extraction.py --directory selected_data/ --target_name cat --outdir OUTPUTDIR. The code will output the perturbed images to the output folder.

Requirements

torch=>2.0.0, diffusers>=0.20.0

FAQ

How does this code differ from the APP on the Nightshade website?

The goal of the code release is different from the Nightshade APP. This code base seeks to provide a reference, basic implementation for research experimentation whereas the APP is designed for people to nightshade their own images. As a result, there are two main differences. First, the Nightshade APP automatically extracts the source concept from a given image and selects a target concept for the image. This code base gives researchers the flexibility to select different poison target. Second, this code base uses Linf perturbation compared to LPIPS perturbation in the APP. Linf perturbation leads to more stable results but more visible perturbations.

How do I test Nightshade?

The easiest way to train the model is to use latent diffusion source code. We do not recommend using the Dreambooth/LORA finetuning code as it is designed for small-scale finetuning rather than full model training.

Citation

@inproceedings{shan2024nightshade,
  title={Nightshade: Prompt-Specific Poisoning Attacks on Text-to-Image Generative Models},
  author={Shan, Shawn and Ding, Wenxin and Passananti, Josephine and Wu, Stanley and Zheng, Haitao and Zhao, Ben Y.},
  booktitle={IEEE Symposium on Security and Privacy},
  year={2024},
}

For any questions with the code, please email [email protected].

nightshade-release's People

Contributors

shawn-shan 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.