Reverse-SynthID

repository·main·Indexed 26 days ago

https://github.com/aloshdenny/reverse-synthid

A research project for discovering, detecting, and removing Google SynthID watermarks from Gemini-generated images. It utilizes spectral analysis and signal processing, offering a V3 spectral bypass desktop GUI and a V4 'Round-06' all-in-one attack pipeline involving VAE, elastic fragmentation, and JPEG techniques. The project includes tools for building spectral codebooks, running batch attacks via scripts like dissolve_batch.py, and performing statistical watermark analysis.

Tokens
8.2K
Snippets
11
Records
60
Agent score
89%

What's inside reverse-synthid

  1. Overview of Reverse-Engineering SynthID

    main

    Reverse-SynthID is a project designed to discover, detect, and surgically remove Google's SynthID watermarks from images generated by Google Gemini. It uses signal processing and spectral analysis to target the watermark's resolution-dependent carrier frequency structure without requiring access to proprietary encoders/decoders.

    Key capabilities include:

    • Detection: A detector capable of identifying SynthID watermarks with 90% accuracy.
    • V3 Bypass: A multi-resolution spectral bypass that achieves a 75% carrier energy drop and 91% phase coherence drop while maintaining high fidelity (43+ dB PSNR).
    • V4 Bypass: A generalized approach using multi-model and multi-color consensus, including per-model profiles for gemini-3.1-flash-image-preview and nano-banana-pro-preview.
    • Round 06 Attack: A unified 7-stage 'all-in-one' attack that defeats the Gemini SynthID detector on both supported models using a combination of VAE, elastic fragmentation, squeeze, color, and JPEG techniques.
  2. SynthID Cleaner Technical Overview

    main

    The SynthID Cleaner uses the V3 spectral bypass pipeline to remove watermarks.

    Workflow Logic:

    • Every image is first checked using the RobustSynthIDExtractor.
    • If a watermark is detected: The image undergoes the spectral bypass process.
    • If no watermark is detected: The image is copied to the output folder unchanged to prevent accidental watermarking.

    Technical Specifications:

    • Privacy: Runs entirely locally with no network calls or telemetry.
    • Requirements: Uses numpy, scipy, opencv, PyWavelets, and scikit-learn. No PyTorch or GPU is required.
    • Dependencies: Uses codebooks located at ../artifacts/spectral_codebook_v3.npz (for bypass) and ../artifacts/codebook/robust_codebook.pkl (for detection).
  3. Download Reference Images from Hugging Face

    main

    Use the scripts/download_images.py script to download reference images (black/white) from the Hugging Face dataset. This requires huggingface_hub to be installed.

    pip install huggingface_hub
    python scripts/download_images.py           # download all
    python scripts/download_images.py gemini_black  # download specific folder
  4. V4 Quickstart Guide

    main

    To perform a watermark attack and verification using V4, follow these three steps:

    1. Build the codebook: Generate the codebook from the enriched hierarchical dataset.
    2. Run the attack: Execute the Round-06 all-in-one attack on a batch of images (this is the recommended method).
    3. Verify detection: Upload each output image to the Gemini app and run SynthID detection to confirm the presence of the watermark.
  5. Use the SynthID Cleaner (GUI)

    main

    Once the application is running, follow these steps to clean your images:

    1. Load Images: Drag and drop images into the application window or click the box to select files via a dialog.
    2. Select Strength: Choose a bypass strength from the dropdown menu:
      • gentle
      • moderate
      • aggressive (Default, recommended for most photos)
      • maximum
    3. Metadata Removal: Keep Strip EXIF/XMP/IPTC metadata checked if you want to remove camera/software tags and AI provenance metadata.
    4. Set Output: Specify a destination in the Save to field. By default, it saves to a synthid-cleaned folder on your Desktop.
    5. Process: Monitor the status line at the bottom. The tool will report if a watermark was found and removed, or if the image was already clean.

    Output Naming: Cleaned files retain their original name with _clean appended (e.g., photo.png becomes photo_clean.png).

  6. V4 Quickstart: Build, Attack, and Calibrate

    main

    To use the V4 (Round-06) workflow, follow these three steps:

    1. Build the codebook: Generate the spectral codebook from your enriched hierarchical dataset.
    2. Run the attack: Execute the all-in-one Round-06 attack on a batch of watermarked images using the recommended presets.
    3. Validate and Calibrate: Upload output images to the Gemini app for manual SynthID detection. Use the feedback to update the codebook via the calibration script.
    # 1. Build the codebook from the enriched hierarchical dataset
    python scripts/build_codebook_v4.py \
        --root /path/to/reverse-synthid-dataset \
        --output artifacts/spectral_codebook_v4.npz
    
    # 2. Run the Round-06 all-in-one attack on a batch (recommended)
    python scripts/dissolve_batch.py \
        --input  ./to_clean/ \
        --output ./runs/round_06/ \
        --codebook artifacts/spectral_codebook_v4.npz \
        --model gemini-3.1-flash-image-preview \
        --strengths final nuke
    
    # 3. Upload each output image to the Gemini app and run SynthID detection.
    #    Use the results to feed back into the calibration script if needed.
  7. Setup the SynthID Cleaner (GUI)

    main

    The SynthID Cleaner is a desktop application for removing SynthID watermarks from Gemini-generated images.

    Automatic Setup

    Double-click Launch SynthID Cleaner.command. On the first run, it will automatically create a virtual environment and install all necessary dependencies. This process typically takes a few minutes.

    Manual Setup (Terminal)

    If you prefer to set up the environment manually via the terminal, run the following commands:

    1. Navigate to the gui directory.
    2. Create a virtual environment.
    3. Activate the environment.
    4. Install dependencies from requirements-gui.txt.
    cd gui
    python3 -m venv venv
    source venv/bin/activate
    pip install -r requirements-gui.txt
  8. Install reverse-SynthID

    main

    To set up the environment, clone the repository, create a virtual environment, and install the required dependencies. For the Round-06 VAE stage, additional deep learning libraries are required.

    git clone https://github.com/aloshdenny/reverse-SynthID.git
    cd reverse-SynthID
    
    python -m venv venv
    source venv/bin/activate  # Windows: venv\Scripts\activate
    pip install -r requirements.txt
    
    # For Round-06 VAE stage:
    pip install torch diffusers safetensors accelerate
  9. Sanity Check V4 Detector Bypass

    main

    Before manual validation, you can use the RobustSynthIDExtractor and SpectralCodebookV4 classes to verify if an image has been successfully bypassed by the V4 codebook.

    from robust_extractor import RobustSynthIDExtractor
    from synthid_bypass_v4 import SpectralCodebookV4
    
    cb = SpectralCodebookV4()
    cb.load('artifacts/spectral_codebook_v4.npz')
    
    ext = RobustSynthIDExtractor()
    result = ext.detect_from_v4_codebook(image_rgb, cb, 
                                         model='nano-banana-pro-preview')
    print(result.is_watermarked, result.confidence, result.phase_match)
  10. Run V4 Round-06 Bypass via Python API

    main

    Use the SynthIDBypassV4 class to perform the recommended V4 bypass. You must load a SpectralCodebookV4 using a valid .npz artifact. The bypass_v4_file method accepts an input path, output path, the codebook, a strength preset, and the target model name.

    import sys
    sys.path.insert(0, 'src/extraction')
    from synthid_bypass_v4 import SynthIDBypassV4, SpectralCodebookV4
    
    cb = SpectralCodebookV4()
    cb.load('artifacts/spectral_codebook_v4.npz')
    
    b = SynthIDBypassV4()
    result = b.bypass_v4_file(
        'input.png', 'output.png',
        cb,
        strength='final',                      # or 'nuke' for maximum strength
        model='gemini-3.1-flash-image-preview',
    )
    print(result.stages_applied)
  11. Run V3 Bypass via Python API

    main

    Use the SynthIDBypass class for V3 bypass operations. This requires a SpectralCodebook loaded from a V3 .npz artifact. The bypass_v3 method operates on an RGB image array.

    from src.extraction.synthid_bypass import SynthIDBypass, SpectralCodebook
    
    codebook = SpectralCodebook()
    codebook.load('artifacts/spectral_codebook_v3.npz')
    
    bypass = SynthIDBypass()
    result = bypass.bypass_v3(image_rgb, codebook, strength='aggressive')
    
    print(f"PSNR: {result.psnr:.1f} dB")
    print(f"Profile used: {result.details['profile_resolution']}")