This repository contains a powerful image generation model that combines the capabilities of Stable Diffusion with multimodal understanding. The model can generate, modify, and transform images using both text and image inputs.
This implementation uses Qwen2VL as the vision-language model for enhanced multimodal understanding, integrated with the Flux architecture. It also supports ControlNet features including depth estimation and line detection for more precise image generation control.
For technical details, please refer to our technical report.
The Flux model enhances Stable Diffusion by replacing the traditional text encoder with a vision-language model (Qwen2VL), enabling superior multimodal understanding and generation:
Key architectural features:
Multiple Generation Modes:
variation: Generate variations of input imagesimg2img: Transform images based on reference imagesinpaint: Intelligent image inpainting with maskscontrolnet: Precise image generation with structural guidancecontrolnet-inpaint: Combine ControlNet guidance with inpaintingMultimodal Understanding:
ControlNet Integration:
Advanced Features:
The model requires the following main dependencies:
For a complete list of dependencies, see requirements.txt.
git clone https://github.com/yourusername/flux-model.git
cd flux-model
python -m venv venv
source venv/bin/activate # Linux/Mac
# or
venv\Scripts\activate # Windows
pip install -r requirements.txt
The model requires several checkpoint files to run. Please follow these steps:
a) Main model files:
checkpoints directory with the following structure:
checkpoints/
├── flux/ # Main Flux model files
├── qwen2-vl/ # Qwen2VL model files
b) For ControlNet features (optional):
Modify the following paths in model.py to match your setup:
FLUX_MODEL_PATH = "/checkpoints/flux"
CONTROLNET_MODEL_PATH = "/checkpoints/controlnet"
QWEN2VL_MODEL_PATH = "/checkpoints/qwen2-vl"
DEPTHANYTHING_MODEL_PATH = "/checkpoints/depth-anything-v2"
MISTOLINE_MODEL_PATH = "/checkpoints/anyline"
SAM2_MODEL_PATH = "/checkpoints/segment-anything-v2"
python main.py --mode <mode> --input_image <path> [additional options]
--mode: Generation mode (variation/img2img/inpaint/controlnet/controlnet-inpaint)--input_image: Path to the input image--prompt: Text prompt to guide generation--output_dir: Directory for saving generated images (default: 'outputs')--image_count: Number of images to generate (default: 1)--aspect_ratio: Output image ratio (1:1/16:9/9:16/2.4:1/3:4/4:3)--steps: Number of inference steps (default: 28)--guidance_scale: Generation guidance scale (default: 3.5)--device: Computing device (cuda/cpu)The model paths can be configured in two ways:
checkpoints directory in your project rootCHECKPOINT_DIR environment variable to your desired locationExpected directory structure:
checkpoints/
├── flux/ # Main Flux model files
├── qwen2-vl/ # Qwen2VL model files
├── controlnet/ # ControlNet model (optional)
├── depth-anything-v2/ # Depth estimation model (optional)
├── anyline/ # Line detection model (optional)
└── segment-anything-2/ # SAM2 model (optional)
The model implements smart loading - it only loads the components needed for your specific task:
python main.py --mode variation \
--input_image path/to/image.jpg \
--prompt "A beautiful landscape" \
--image_count 4
python main.py --mode img2img \
--input_image source.jpg \
--reference_image target.jpg \
--prompt "xxxxxxxxxxxx" \
--denoise_strength 0.75
python main.py --mode inpaint \
--input_image image.jpg \
--mask_image mask.png \
--prompt "Fill with beautiful flowers"
python main.py --mode controlnet \
--input_image image.jpg \
--line_mode \
--depth_mode \
--line_strength 0.4 \
--depth_strength 0.2 \
--prompt "xxxxxxxxxxxxxxxxxxxxx"
# Using environment variable to specify model location
CHECKPOINT_DIR=/path/to/models python main.py \
--mode variation \
--input_image image.jpg \
--prompt "xxxxxxxxxxxxxxxxxxxxxxxxx"
# Only loads depth model without line detection
python main.py --mode controlnet \
--input_image image.jpg \
--depth_mode \
--depth_strength 0.3 \
--prompt "xxxxxxxxxxxxxxxxxxxxxxxx"
# Only loads line detection without depth model
python main.py --mode controlnet \
--input_image image.jpg \
--line_mode \
--line_strength 0.4 \
--prompt "xxxxxxxxxxxxxxxxxxxxxxxxxxx"
python main.py --mode variation \
--input_image image.jpg \
--center_x 0.5 \
--center_y 0.5 \
--radius 0.3 \
--prompt "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
Attention Control:
--center_x: X coordinate of attention center (0-1)--center_y: Y coordinate of attention center (0-1)--radius: Radius of attention circle (0-1)ControlNet Settings:
--line_mode: Enable line detection--depth_mode: Enable depth awareness--line_strength: Line guidance strength (0-1)--depth_strength: Depth guidance strength (0-1)Performance:
--turbo: Enable faster inference--device: Choose computing deviceThis model enhances the Stable Diffusion architecture by replacing the T5-XXL text encoder with a vision-language model, enabling superior multimodal understanding and generation capabilities. The architecture includes:
For a comprehensive understanding of the model architecture, implementation details, and technical innovations, please refer to the following resources:
Core Model:
Additional Components (Optional):
If you use this model in your research, please cite our technical report:
@misc{erwold-2024-qwen2vl-flux,
title={Qwen2VL-Flux: Unifying Image and Text Guidance for Controllable Image Generation},
author={Pengqi Lu},
year={2024},
url={https://github.com/erwold/qwen2vl-flux}
}
Contributions are welcome! Please feel free to submit a Pull Request.
2 commits
2 commits
Python
100.0%
This repository contains a powerful image generation model that combines the capabilities of Stable Diffusion with multimodal understanding. The model can generate, modify, and transform images using both text and image inputs.
This implementation uses Qwen2VL as the vision-language model for enhanced multimodal understanding, integrated with the Flux architecture. It also supports ControlNet features including depth estimation and line detection for more precise image generation control.
For technical details, please refer to our technical report.
The Flux model enhances Stable Diffusion by replacing the traditional text encoder with a vision-language model (Qwen2VL), enabling superior multimodal understanding and generation:
Key architectural features:
Multiple Generation Modes:
variation: Generate variations of input imagesimg2img: Transform images based on reference imagesinpaint: Intelligent image inpainting with maskscontrolnet: Precise image generation with structural guidancecontrolnet-inpaint: Combine ControlNet guidance with inpaintingMultimodal Understanding:
ControlNet Integration:
Advanced Features:
The model requires the following main dependencies:
For a complete list of dependencies, see requirements.txt.
git clone https://github.com/yourusername/flux-model.git
cd flux-model
python -m venv venv
source venv/bin/activate # Linux/Mac
# or
venv\Scripts\activate # Windows
pip install -r requirements.txt
The model requires several checkpoint files to run. Please follow these steps:
a) Main model files:
checkpoints directory with the following structure:
checkpoints/
├── flux/ # Main Flux model files
├── qwen2-vl/ # Qwen2VL model files
b) For ControlNet features (optional):
Modify the following paths in model.py to match your setup:
FLUX_MODEL_PATH = "/checkpoints/flux"
CONTROLNET_MODEL_PATH = "/checkpoints/controlnet"
QWEN2VL_MODEL_PATH = "/checkpoints/qwen2-vl"
DEPTHANYTHING_MODEL_PATH = "/checkpoints/depth-anything-v2"
MISTOLINE_MODEL_PATH = "/checkpoints/anyline"
SAM2_MODEL_PATH = "/checkpoints/segment-anything-v2"
python main.py --mode <mode> --input_image <path> [additional options]
--mode: Generation mode (variation/img2img/inpaint/controlnet/controlnet-inpaint)--input_image: Path to the input image--prompt: Text prompt to guide generation--output_dir: Directory for saving generated images (default: 'outputs')--image_count: Number of images to generate (default: 1)--aspect_ratio: Output image ratio (1:1/16:9/9:16/2.4:1/3:4/4:3)--steps: Number of inference steps (default: 28)--guidance_scale: Generation guidance scale (default: 3.5)--device: Computing device (cuda/cpu)The model paths can be configured in two ways:
checkpoints directory in your project rootCHECKPOINT_DIR environment variable to your desired locationExpected directory structure:
checkpoints/
├── flux/ # Main Flux model files
├── qwen2-vl/ # Qwen2VL model files
├── controlnet/ # ControlNet model (optional)
├── depth-anything-v2/ # Depth estimation model (optional)
├── anyline/ # Line detection model (optional)
└── segment-anything-2/ # SAM2 model (optional)
The model implements smart loading - it only loads the components needed for your specific task:
python main.py --mode variation \
--input_image path/to/image.jpg \
--prompt "A beautiful landscape" \
--image_count 4
python main.py --mode img2img \
--input_image source.jpg \
--reference_image target.jpg \
--prompt "xxxxxxxxxxxx" \
--denoise_strength 0.75
python main.py --mode inpaint \
--input_image image.jpg \
--mask_image mask.png \
--prompt "Fill with beautiful flowers"
python main.py --mode controlnet \
--input_image image.jpg \
--line_mode \
--depth_mode \
--line_strength 0.4 \
--depth_strength 0.2 \
--prompt "xxxxxxxxxxxxxxxxxxxxx"
# Using environment variable to specify model location
CHECKPOINT_DIR=/path/to/models python main.py \
--mode variation \
--input_image image.jpg \
--prompt "xxxxxxxxxxxxxxxxxxxxxxxxx"
# Only loads depth model without line detection
python main.py --mode controlnet \
--input_image image.jpg \
--depth_mode \
--depth_strength 0.3 \
--prompt "xxxxxxxxxxxxxxxxxxxxxxxx"
# Only loads line detection without depth model
python main.py --mode controlnet \
--input_image image.jpg \
--line_mode \
--line_strength 0.4 \
--prompt "xxxxxxxxxxxxxxxxxxxxxxxxxxx"
python main.py --mode variation \
--input_image image.jpg \
--center_x 0.5 \
--center_y 0.5 \
--radius 0.3 \
--prompt "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
Attention Control:
--center_x: X coordinate of attention center (0-1)--center_y: Y coordinate of attention center (0-1)--radius: Radius of attention circle (0-1)ControlNet Settings:
--line_mode: Enable line detection--depth_mode: Enable depth awareness--line_strength: Line guidance strength (0-1)--depth_strength: Depth guidance strength (0-1)Performance:
--turbo: Enable faster inference--device: Choose computing deviceThis model enhances the Stable Diffusion architecture by replacing the T5-XXL text encoder with a vision-language model, enabling superior multimodal understanding and generation capabilities. The architecture includes:
For a comprehensive understanding of the model architecture, implementation details, and technical innovations, please refer to the following resources:
Core Model:
Additional Components (Optional):
If you use this model in your research, please cite our technical report:
@misc{erwold-2024-qwen2vl-flux,
title={Qwen2VL-Flux: Unifying Image and Text Guidance for Controllable Image Generation},
author={Pengqi Lu},
year={2024},
url={https://github.com/erwold/qwen2vl-flux}
}
Contributions are welcome! Please feel free to submit a Pull Request.
2 commits
2 commits
Python
100.0%