Initial Commit
Browse files- .gitattributes +1 -0
- CITATION.cff +20 -0
- LICENSE +21 -0
- README.md +146 -0
- example_grid.jpg +3 -0
- qwen-360-diffusion-int4-bf16-v1-b.safetensors +3 -0
- qwen-360-diffusion-int4-bf16-v1.safetensors +3 -0
- qwen-360-diffusion-int8-bf16-v1.safetensors +3 -0
- run_qwen_image_nf4.py +124 -0
.gitattributes
CHANGED
|
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 36 |
+
example_grid.jpg filter=lfs diff=lfs merge=lfs -text
|
CITATION.cff
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
cff-version: 1.2.0
|
| 2 |
+
message: "If you use this software, please cite it using the metadata in this file."
|
| 3 |
+
title: "Qwen 360 Diffusion"
|
| 4 |
+
authors:
|
| 5 |
+
- family-names: "Egan"
|
| 6 |
+
given-names: "Ben"
|
| 7 |
+
- name: "XWAVE"
|
| 8 |
+
- name: "Jimmy Carter"
|
| 9 |
+
date-released: "2025-12-10"
|
| 10 |
+
keywords:
|
| 11 |
+
- "text to image"
|
| 12 |
+
- "Qwen"
|
| 13 |
+
- "qwen image"
|
| 14 |
+
- "diffusion model"
|
| 15 |
+
- "equirectangular"
|
| 16 |
+
- "equirectangular projection"
|
| 17 |
+
- "360 image"
|
| 18 |
+
- "360 degree"
|
| 19 |
+
url: "https://huggingface.co/ProGamerGov/qwen-360-diffusion"
|
| 20 |
+
type: software
|
LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
MIT License
|
| 2 |
+
|
| 3 |
+
Copyright (c) 2025 Ben Egan, XWAVE, Jimmy Carter
|
| 4 |
+
|
| 5 |
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
| 6 |
+
of this software and associated documentation files (the "Software"), to deal
|
| 7 |
+
in the Software without restriction, including without limitation the rights
|
| 8 |
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
| 9 |
+
copies of the Software, and to permit persons to whom the Software is
|
| 10 |
+
furnished to do so, subject to the following conditions:
|
| 11 |
+
|
| 12 |
+
The above copyright notice and this permission notice shall be included in all
|
| 13 |
+
copies or substantial portions of the Software.
|
| 14 |
+
|
| 15 |
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
| 16 |
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
| 17 |
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
| 18 |
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
| 19 |
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
| 20 |
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
| 21 |
+
SOFTWARE.
|
README.md
ADDED
|
@@ -0,0 +1,146 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
language:
|
| 3 |
+
- en
|
| 4 |
+
base_model:
|
| 5 |
+
- Qwen/Qwen-Image
|
| 6 |
+
pipeline_tag: text-to-image
|
| 7 |
+
tags:
|
| 8 |
+
- '360'
|
| 9 |
+
- '360°'
|
| 10 |
+
- '360-degree'
|
| 11 |
+
- '360-image'
|
| 12 |
+
- equirectangular
|
| 13 |
+
- equirectangular-projection
|
| 14 |
+
- image-generation
|
| 15 |
+
- text-to-image
|
| 16 |
+
---
|
| 17 |
+
|
| 18 |
+
# Qwen 360 Diffusion
|
| 19 |
+
|
| 20 |
+

|
| 21 |
+
|
| 22 |
+
## General
|
| 23 |
+
|
| 24 |
+
Qwen 360 Diffusion is a rank 128 LoRA built on top of a 20B parameter MMDiT (Multimodal Diffusion Transformer) model, designed to generate 360 degree equirectangular projection images from text descriptions.
|
| 25 |
+
|
| 26 |
+
The model was trained from the [Qwen Image model](https://huggingface.co/Qwen/Qwen-Image) on an extremely diverse dataset composed of tens of thousands of equirectangular images, depicting landscapes, interiors, humans, animals, and objects. All images were resized to 2048x1024 before training.
|
| 27 |
+
|
| 28 |
+
The model was also trained with a diverse dataset of normal photos for regularization, making the model a realism finetune when prompted correctly.
|
| 29 |
+
|
| 30 |
+
Based on extensive testing, the model's capabilities vastly exceed all other currently available T2I 360 image generation models. Thus when given the right prompt, the model should be capable of producing almost anything you want.
|
| 31 |
+
|
| 32 |
+
The model is designed to be capable of producing equirectangular images that can be used for non-VR purposes such as general imagery, photography, artwork, architecture, portraiture, and many other concepts.
|
| 33 |
+
|
| 34 |
+
---
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
## Usage
|
| 38 |
+
|
| 39 |
+
To activate panoramic generation, include one of the following **trigger phrases** or some variation of one or more of the following trigger words in your prompt:
|
| 40 |
+
|
| 41 |
+
> `"equirectangular"`, `"360 image"`, `"360 panorama"`, or `"360 degree panorama with equirectangular projection"`
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
Note that even using a 360 viewer on your 2D device screen can create a feeling like you are actually inside the scene, known as a sense of 'presence' in psychology.
|
| 45 |
+
|
| 46 |
+
### Recommended Settings
|
| 47 |
+
|
| 48 |
+
- **Aspect ratio:** For best results use the `2:1` resolution of `2048×1024`. Using `1024×512`, `1536×768`, and other 2:1 ratios for text-to-image generation may cause the model to struggle with generating proper horizons.
|
| 49 |
+
- **Prompt tips:** Include desired **medium or style**, such as _photograph_, _oil painting_, _illustration_, or _digital art_.
|
| 50 |
+
- **360-specific considerations:** Remember that 360 images wrap around with no borders—the left edge connects to the right edge, while the top and bottom edges merge into a single point at the poles of the sphere.
|
| 51 |
+
- **Human subject considerations:** For full body shots, specify the head/face and footwear (e.g., "wearing boots") or lack thereof to avoid incomplete or incorrectly distorted outputs.
|
| 52 |
+
- **Equirectangular distortion:** Outputs show increasing horizontal stretching as you move vertically away from the center. These distortions are not visible when viewed in a 360 viewer.
|
| 53 |
+
|
| 54 |
+
Once generated, you can upscale your panoramas for use as **photographs**, **artwork**, **skyboxes, virtual environments, VR experiences, VR therapy, or 3D scene backgrounds**—or as part of a **text-to-video-to-3D-world pipeline**. Note that the model is also designed to produce equirectangular images for non-VR usage as well.
|
| 55 |
+
|
| 56 |
+
---
|
| 57 |
+
|
| 58 |
+
### Notes
|
| 59 |
+
|
| 60 |
+
#### FP8 inference
|
| 61 |
+
|
| 62 |
+
When using FP8 quantization, for maximum visual fidelity it's **strongly recommended** to use the GGUF Q8 or int8 quantized versions of Qwen Image transformer models.
|
| 63 |
+
|
| 64 |
+
If you are using transformer models with `fp8_e4m3fn` or `fp8_e5m2` precision, or low precision models trained with "accuracy-fixing" methods (e.g., `ostris/ai-toolkit`), they may cause **patch or grid artifacts** when used with the int8-trained LoRA model. Some have found this issue to be caused by directly downcasting to fp8 from fp16, without proper scaling and calibration.
|
| 65 |
+
→ To avoid this, use the **lower-accuracy full-precision versions** of the model:
|
| 66 |
+
`qwen-360-diffusion-int4-bf16-v1.safetensors` or `qwen-360-diffusion-int4-bf16-v1-b.safetensors`.
|
| 67 |
+
|
| 68 |
+
- **Low-Precision Artifact Mitigation**
|
| 69 |
+
If artifacts still appear when using the int4-trained LoRA on a `fp8_e4m3fn` or `fp8_e5m2` transformer quant, they can often be reduced by:
|
| 70 |
+
- Adjusting the **LoRA weight**, and/or refining both **positive and negative prompts**.
|
| 71 |
+
|
| 72 |
+
---
|
| 73 |
+
|
| 74 |
+
## Additional Tools
|
| 75 |
+
|
| 76 |
+
### HTML 360 Viewer
|
| 77 |
+
|
| 78 |
+
To make the viewing and sharing of 360 images & video easier, I built a web browser based HTML 360 viewer that runs locally on your device. It works on desktop and mobile browsers, and has optional VR headset support.
|
| 79 |
+
|
| 80 |
+
* You can try it out here on Github Pages: https://progamergov.github.io/html-360-viewer/
|
| 81 |
+
* Github code: https://github.com/ProGamerGov/html-360-viewer
|
| 82 |
+
* You can append '`?url=`' followed by a link to your image in order to automatically load it into the 360 viewer, making sharing your 360 creations extremely easy.
|
| 83 |
+
* Example: https://progamergov.github.io/html-360-viewer/?url=https://upload.wikimedia.org/wikipedia/commons/7/76/Dauderi.jpg
|
| 84 |
+
|
| 85 |
+
|
| 86 |
+
### Recommended ComfyUI Nodes
|
| 87 |
+
|
| 88 |
+
If you are a user of [ComfyUI](https://github.com/comfyanonymous/ComfyUI), then these sets of nodes can be useful for working with 360 images & videos.
|
| 89 |
+
|
| 90 |
+
* ComfyUI_preview360panorama
|
| 91 |
+
* For viewing 360s inside of ComfyUI (may be slower than my web browser viewer).
|
| 92 |
+
* Link: https://github.com/ProGamerGov/ComfyUI_preview360panorama
|
| 93 |
+
|
| 94 |
+
* ComfyUI_pytorch360convert
|
| 95 |
+
* For editing 360s, seam fixing, view rotation, and masking potential artifacts.
|
| 96 |
+
* Link: https://github.com/ProGamerGov/ComfyUI_pytorch360convert
|
| 97 |
+
|
| 98 |
+
* ComfyUI_pytorch360convert_video
|
| 99 |
+
* For generating sweep videos that rotate around the scene.
|
| 100 |
+
* Link: https://github.com/ProGamerGov/ComfyUI_pytorch360convert_video
|
| 101 |
+
|
| 102 |
+
For those using diffusers and other libraries, you can make use of the [pytorch360convert](https://github.com/ProGamerGov/pytorch360convert) library when working with 360 media.
|
| 103 |
+
|
| 104 |
+
---
|
| 105 |
+
|
| 106 |
+
### Diffusers Example
|
| 107 |
+
|
| 108 |
+
Example script using [Diffusers](https://github.com/huggingface/diffusers) can be found [here](https://huggingface.co/ProGamerGov/qwen-360-diffusion/blob/main/run_qwen_image_nf4.py).
|
| 109 |
+
|
| 110 |
+
---
|
| 111 |
+
|
| 112 |
+
## Limitations
|
| 113 |
+
|
| 114 |
+
A large portion of training data has the viewer at 90 degrees to the direction of gravity, and thus rotating outputs may be required to achieve different vertical angles.
|
| 115 |
+
|
| 116 |
+
---
|
| 117 |
+
|
| 118 |
+
## Contributors
|
| 119 |
+
|
| 120 |
+
- [Ben Egan](https://github.com/ProGamerGov)
|
| 121 |
+
- [XWAVE](https://twitter.com/XWAVEart)
|
| 122 |
+
- [Jimmy Carter](https://huggingface.co/jimmycarter)
|
| 123 |
+
|
| 124 |
+
|
| 125 |
+
## Citation Information
|
| 126 |
+
|
| 127 |
+
BibTeX
|
| 128 |
+
|
| 129 |
+
```
|
| 130 |
+
@software{Egan_Qwen_360_Diffusion_2025,
|
| 131 |
+
author = {Egan, Ben and {XWAVE} and {Jimmy Carter}},
|
| 132 |
+
license = {MIT},
|
| 133 |
+
month = aug,
|
| 134 |
+
title = {{Qwen 360 Diffusion}},
|
| 135 |
+
url = {https://huggingface.co/ProGamerGov/qwen-360-diffusion},
|
| 136 |
+
year = {2025}
|
| 137 |
+
}
|
| 138 |
+
```
|
| 139 |
+
|
| 140 |
+
APA
|
| 141 |
+
|
| 142 |
+
```
|
| 143 |
+
Egan, B., XWAVE, & Jimmy Carter. (2025). Qwen 360 Diffusion [Computer software]. https://huggingface.co/ProGamerGov/qwen-360-diffusion
|
| 144 |
+
```
|
| 145 |
+
|
| 146 |
+
Please refer to the [CITATION.cff](https://huggingface.co/ProGamerGov/qwen-360-diffusion/blob/main/CITATION.cff) for more information on how to cite this dataset.
|
example_grid.jpg
ADDED
|
Git LFS Details
|
qwen-360-diffusion-int4-bf16-v1-b.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:bf710d6e6e67545e32f979069ba3aaade158326278daf80b8afd251e22fc8ba7
|
| 3 |
+
size 755039336
|
qwen-360-diffusion-int4-bf16-v1.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:f0cee2e49e9976a374112225e3766c5d2b758bd98fc54733fc90771c6dccbecc
|
| 3 |
+
size 755039336
|
qwen-360-diffusion-int8-bf16-v1.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:1dc0d8c164e92bda96a7ab4d55a846e7c36cec369ba37ee85d19ef1707210de3
|
| 3 |
+
size 377552312
|
run_qwen_image_nf4.py
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from PIL import Image
|
| 2 |
+
import torch
|
| 3 |
+
import numpy as np
|
| 4 |
+
from transformers import BitsAndBytesConfig as TransformersBitsAndBytesConfig
|
| 5 |
+
from transformers import Qwen2_5_VLForConditionalGeneration
|
| 6 |
+
|
| 7 |
+
from diffusers import BitsAndBytesConfig as DiffusersBitsAndBytesConfig
|
| 8 |
+
from diffusers import QwenImagePipeline, QwenImageTransformer2DModel, QwenImageInpaintPipeline
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
prompt = "equirectangular, a woman and a man sitting at a cafe, the woman has red hair and she's wearing purple sweater with a black scarf and a white hat, the man is sitting on the other side of the table and he's wearing a white shirt with a purple scarf and red hat, both of them are sipping their coffee while in the table there's some cake slices on their respective plates, each with forks and knives at each side."
|
| 12 |
+
negative_prompt = ""
|
| 13 |
+
output_filename = "qwen_bnb_nf4.png"
|
| 14 |
+
width, height = 2048, 1024
|
| 15 |
+
true_cfg_scale = 4.0
|
| 16 |
+
num_inference_steps = 25
|
| 17 |
+
seed = 42
|
| 18 |
+
|
| 19 |
+
lora_model_id = "jimmycarter/qwen-3d-epoch-7"
|
| 20 |
+
lora_filename = "pytorch_lora_weights.safetensors"
|
| 21 |
+
|
| 22 |
+
model_id = "diffusers/qwen-image-nf4"
|
| 23 |
+
torch_dtype = torch.bfloat16
|
| 24 |
+
device = "cuda"
|
| 25 |
+
|
| 26 |
+
fix_seam = True
|
| 27 |
+
inpaint_strength, seam_width = 0.5, 0.10
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
def shift_equirect(img):
|
| 31 |
+
"""Horizontal 50% shift using torch.roll."""
|
| 32 |
+
t = torch.from_numpy(np.array(img)).permute(2, 0, 1).float() / 255.0
|
| 33 |
+
t = torch.roll(t, shifts=(0, t.shape[2] // 2), dims=(1, 2))
|
| 34 |
+
return Image.fromarray((t.permute(1, 2, 0).numpy() * 255).astype(np.uint8))
|
| 35 |
+
|
| 36 |
+
def create_seam_mask(w, h, frac=0.10):
|
| 37 |
+
"""Create vertical seam mask as PIL Image (center seam)."""
|
| 38 |
+
mask = torch.zeros((h, w))
|
| 39 |
+
seam_w = max(1, int(w * frac))
|
| 40 |
+
c = w // 2
|
| 41 |
+
mask[:, c - seam_w // 2:c + seam_w // 2] = 1.0
|
| 42 |
+
return Image.fromarray((mask.numpy() * 255).astype("uint8"), "L")
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
def load_pipeline(text_encoder, transformer, mode="t2i"):
|
| 46 |
+
pip_class = QwenImagePipeline if mode == "t2i" else QwenImageInpaintPipeline
|
| 47 |
+
pipe = pip_class.from_pretrained(
|
| 48 |
+
model_id, transformer=transformer, text_encoder=text_encoder, torch_dtype=torch_dtype
|
| 49 |
+
)
|
| 50 |
+
pipe.load_lora_weights(lora_model_id, weight_name=lora_filename)
|
| 51 |
+
pipe.enable_model_cpu_offload()
|
| 52 |
+
pipe.enable_vae_tiling()
|
| 53 |
+
pipe.transformer.compile_repeated_blocks(
|
| 54 |
+
fullgraph=True, dynamic=True
|
| 55 |
+
)
|
| 56 |
+
return pipe
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
def main():
|
| 60 |
+
quantization_config = DiffusersBitsAndBytesConfig(
|
| 61 |
+
load_in_4bit=True,
|
| 62 |
+
bnb_4bit_quant_type="nf4",
|
| 63 |
+
bnb_4bit_compute_dtype=torch.bfloat16,
|
| 64 |
+
llm_int8_skip_modules=["transformer_blocks.0.img_mod"],
|
| 65 |
+
)
|
| 66 |
+
transformer = QwenImageTransformer2DModel.from_pretrained(
|
| 67 |
+
model_id,
|
| 68 |
+
subfolder="transformer",
|
| 69 |
+
quantization_config=quantization_config,
|
| 70 |
+
torch_dtype=torch_dtype,
|
| 71 |
+
).to("cpu")
|
| 72 |
+
|
| 73 |
+
quantization_config = TransformersBitsAndBytesConfig(
|
| 74 |
+
load_in_4bit=True,
|
| 75 |
+
bnb_4bit_quant_type="nf4",
|
| 76 |
+
bnb_4bit_compute_dtype=torch.bfloat16,
|
| 77 |
+
)
|
| 78 |
+
text_encoder = Qwen2_5_VLForConditionalGeneration.from_pretrained(
|
| 79 |
+
model_id,
|
| 80 |
+
subfolder="text_encoder",
|
| 81 |
+
quantization_config=quantization_config,
|
| 82 |
+
torch_dtype=torch_dtype,
|
| 83 |
+
).to("cpu")
|
| 84 |
+
|
| 85 |
+
generator = torch.Generator(device=device).manual_seed(seed)
|
| 86 |
+
pipe = load_pipeline(text_encoder, transformer, mode="t2i")
|
| 87 |
+
|
| 88 |
+
image = pipe(
|
| 89 |
+
prompt=prompt,
|
| 90 |
+
negative_prompt=negative_prompt,
|
| 91 |
+
width=width,
|
| 92 |
+
height=height,
|
| 93 |
+
num_inference_steps=num_inference_steps,
|
| 94 |
+
true_cfg_scale=true_cfg_scale,
|
| 95 |
+
generator=generator,
|
| 96 |
+
).images[0]
|
| 97 |
+
|
| 98 |
+
image.save(output_filename)
|
| 99 |
+
|
| 100 |
+
if fix_seam:
|
| 101 |
+
del pipe
|
| 102 |
+
if torch.cuda.is_available():
|
| 103 |
+
torch.cuda.empty_cache()
|
| 104 |
+
|
| 105 |
+
shifted = shift_equirect(image) # roll 50% to expose seam
|
| 106 |
+
mask = create_seam_mask(width, height, frac=seam_width)
|
| 107 |
+
|
| 108 |
+
pipe = load_pipeline(text_encoder, transformer, mode="i2i")
|
| 109 |
+
image_fixed = pipe(
|
| 110 |
+
prompt=prompt,
|
| 111 |
+
negative_prompt=negative_prompt,
|
| 112 |
+
image=shifted,
|
| 113 |
+
mask_image=mask,
|
| 114 |
+
strength=inpaint_strength,
|
| 115 |
+
width=width,
|
| 116 |
+
height=height,
|
| 117 |
+
num_inference_steps=num_inference_steps,
|
| 118 |
+
true_cfg_scale=true_cfg_scale,
|
| 119 |
+
generator=generator,
|
| 120 |
+
).images[0]
|
| 121 |
+
image_fixed = shift_equirect(image_fixed)
|
| 122 |
+
image_fixed.save(output_filename.replace(".png", "_seamfix.png"))
|
| 123 |
+
|
| 124 |
+
main()
|