Skip to content

ManasShouche/Style-Transfer-Using-Stable-diffusion-SAM-

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 

Repository files navigation

Style-Transfer-Using-Stable-diffusion-SAM-

AI-Driven Addiction Progression Visualization (Abstract & Symbolic)

This project explores the visual impact of substance addiction through an abstract and symbolic AI-driven image progression. Utilizing a Stable Diffusion XL (SDXL) pipeline, it applies a series of style transfer and image adjustment techniques to a user-provided image, simulating the deterioration and changes associated with different stages of addiction. The project also incorporates quantitative image analysis to track visual metrics (e.g., SSIM, artistic distortion, brightness, saturation) throughout the progression.

Important Disclaimer: This project is for abstract and symbolic visualization purposes only. It is not intended to be a realistic or stereotypical depiction of individuals experiencing addiction. The goal is to explore the creative application of AI for visual transformation and data analysis in a sensitive context, focusing on abstract visual changes rather than human representation.

Features

  • Progressive Image Transformation: A base image is iteratively transformed through a series of "addiction stages" (Healthy, Experimentation, Regular Use, Dependence, Addiction) using Stable Diffusion XL (SDXL) style transfer.
  • Abstract & Symbolic Visuals: The transformations are designed to be abstract, using effects like desaturation, blur, distortion, and specific stylistic prompts to represent deterioration, rather than literal or stereotypical human features.
  • Quantitative Image Metrics: Each stage's output is analyzed against the original image using metrics such as:
    • Structural Similarity Index (SSIM): Measures perceived similarity between images.
    • Artistic Distortion Score: A custom metric for quantifying "stylistic" or "degraded" appearance.
    • Brightness Change: Percentage change in overall image brightness.
    • Saturation Change: Percentage change in overall image color saturation.
  • Comprehensive Reporting: Generates a detailed report and plots trends for key metrics across all progression stages.
  • Modular Jupyter Notebook Structure: The project is organized into logical cells within a Jupyter Notebook, making it easy to follow, execute, and modify.

Project Structure (Jupyter Notebook Cells)

The project is designed to run in a Jupyter Notebook environment, with each logical step contained in a "cell."

  • CELL 1: Setup & Environment Configuration:
    • Initial setup, GPU checks, and necessary library imports.
    • Sets up CUDA for GPU acceleration if available.
  • CELL 2: Model Loading (SDXL Pipeline):
    • Loads the Stable Diffusion XL (SDXL) diffusion pipeline (e.g., stabilityai/stable-diffusion-xl-refiner-1.0).
    • Configures the pipeline for text-to-image and image-to-image tasks.
  • CELL 3: Image Preprocessing Utilities:
    • Defines utility functions for image handling (upload, display, resizing, format conversion).
  • CELL 4: Qualitative Image Comparison:
    • Utility to display multiple images side-by-side with titles.
  • CELL 5: Quantitative Image Metrics:
    • Defines functions for calculating SSIM, Artistic Distortion, Brightness Change, and Saturation Change.
  • CELL 6: Basic Style Transfer Function:
    • Encapsulates the core image-to-image (img2img) style transfer logic using the loaded SDXL pipeline.
  • CELL 7: Comprehensive Metric Reporting & Visualization:
    • Combines qualitative (image display) and quantitative (metric plots) analysis into reusable functions.
    • Includes create_comparison_report and visualize_metrics.
  • CELL 8: Enhanced Style Transfer with Metrics:
    • Builds upon CELL 6 by integrating automatic metric calculation and optional reporting for individual style transfer operations.
  • CELL 9: Base Image Selection:
    • Allows the user to upload a base image to be used for the addiction progression.
  • CELL 10: Addiction Stage Configuration (ADDICTION_STAGES):
    • Crucial: Defines the parameters for each addiction stage (e.g., prompts, negative prompts, strength, guidance scale, color adjustments). This is where the "story" of the visual progression is defined.
  • CELL 11: Addiction Stage Application:
    • Applies the transformation for a single addiction stage, calling enhanced_style_transfer_with_metrics and applying post-processing color adjustments. Returns the transformed image and its metrics.
  • CELL 12: Generate Addiction Progression with Metrics (Orchestration):
    • The main orchestration cell. It iterates through all defined addiction stages, feeding the output of one stage as the input to the next.
    • Aggregates all metrics and displays the full visual progression, along with trend plots and a final comparison report.

🚀 Getting Started

Prerequisites

  • Python 3.8+
  • Jupyter Notebook or JupyterLab
  • A Hugging Face account with access to Stable Diffusion XL models (you may need to accept the terms of use on their model cards).
  • (Recommended) NVIDIA GPU with CUDA for faster processing.

Installation

  1. Clone the repository:

    git clone [https://github.com/yourusername/your-repo-name.git](https://github.com/yourusername/your-repo-name.git)
    cd your-repo-name
  2. Create and activate a virtual environment (recommended):

    python -m venv venv
    source venv/bin/activate   # On Windows: `venv\Scripts\activate`
  3. Set up Hugging Face Token: You'll need your Hugging Face API token for authentication. You can log in via the huggingface_hub library:

    from huggingface_hub import login
    login() # You will be prompted to enter your token

    Alternatively, set it as an environment variable: HF_TOKEN=hf_YOUR_TOKEN_HERE

Running the Notebook

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors