Text-to-Image
Diffusers
Safetensors
recoilme commited on
Commit
0bec123
·
1 Parent(s): 5e16dd3
media/result_grid.jpg CHANGED

Git LFS Details

  • SHA256: 8da0c88d0239da6b6c6547d2b35498303b31a87416e02e74399b1300977b9c3f
  • Pointer size: 132 Bytes
  • Size of remote file: 4.07 MB

Git LFS Details

  • SHA256: 3c9958198255eba36c5caeed8fbafffc87a3965c4328278816ac582d4652de31
  • Pointer size: 132 Bytes
  • Size of remote file: 4.23 MB
pipeline_sdxs.py CHANGED
@@ -22,9 +22,7 @@ class SdxsPipeline(DiffusionPipeline):
22
  unet=unet,
23
  scheduler=scheduler
24
  )
25
- # Для асимметричного VAE: 8 энкодер, 16 декодер
26
- self.encoder_scale_factor = 2 ** (len(self.vae.config.block_out_channels) - 1) # 8
27
- self.decoder_scale_factor = self.encoder_scale_factor * 2 # 16 (если декодер в 2 раза больше)
28
 
29
  def create_frequency_soft_cutoff_mask(self, height: int, width: int, cutoff_radius: float,
30
  transition_width: float = 5.0, device: torch.device = None) -> torch.Tensor:
@@ -118,8 +116,8 @@ class SdxsPipeline(DiffusionPipeline):
118
  def preprocess_image(self, image: Image.Image, width: int, height: int):
119
  """Ресайз и центрированный кроп изображения для асимметричного VAE."""
120
  # Для энкодера с масштабом 8
121
- target_height = ((height // self.encoder_scale_factor) * self.encoder_scale_factor)//2
122
- target_width = ((width // self.encoder_scale_factor) * self.encoder_scale_factor)//2
123
 
124
  w, h = image.size
125
  aspect_ratio = target_width / target_height
@@ -198,6 +196,7 @@ class SdxsPipeline(DiffusionPipeline):
198
  num_inference_steps: int = 40,
199
  guidance_scale: float = 4.0,
200
  generator: Optional[torch.Generator] = None,
 
201
  output_type: str = "pil",
202
  return_dict: bool = True,
203
  structure_preservation: float = 0.2, # Новый параметр: сохранение структуры 0-1
@@ -206,6 +205,13 @@ class SdxsPipeline(DiffusionPipeline):
206
  device = self.device
207
  dtype = self.unet.dtype
208
 
 
 
 
 
 
 
 
209
  # 1. Encode Prompt
210
  text_embeddings, attention_mask = self.encode_prompt(
211
  prompt, negative_prompt, device, dtype
@@ -216,9 +222,9 @@ class SdxsPipeline(DiffusionPipeline):
216
  self.scheduler.set_timesteps(num_inference_steps, device=device)
217
  timesteps = self.scheduler.timesteps # Все 40 шагов
218
 
219
- print(f"Используем ВСЕ шаги: {len(timesteps)}")
220
- print(f"Диапазон таймстепов: [{timesteps[0].item():.3f}, {timesteps[-1].item():.3f}]")
221
- print(f"Коэффициент смешивания (coef): {coef}")
222
 
223
  # 3. Обработка img2img с структурированным шумом
224
  if image is not None:
@@ -272,8 +278,8 @@ class SdxsPipeline(DiffusionPipeline):
272
  vae_scaling_factor = getattr(self.vae.config, "scaling_factor", 1.0)
273
  vae_shift_factor = getattr(self.vae.config, "shift_factor", 0.0)
274
 
275
- latent_height = height // self.decoder_scale_factor
276
- latent_width = width // self.decoder_scale_factor
277
 
278
  latents = torch.randn(
279
  (batch_size, self.unet.config.in_channels, latent_height, latent_width),
@@ -312,14 +318,6 @@ class SdxsPipeline(DiffusionPipeline):
312
  latents = latents * vae_scaling_factor + vae_shift_factor
313
  image_output = self.vae.decode(latents.to(self.vae.dtype), return_dict=False)[0]
314
 
315
- # Исправляем инвертированное изображение - правильная нормализация
316
- # VAE обычно выдает в диапазоне [-1, 1] или [0, 1]
317
- # Проверяем диапазон и нормализуем правильно
318
- image_min = image_output.min()
319
- image_max = image_output.max()
320
-
321
- if image_min < -1.5 and image_max > 1.5: # Вероятно диапазон [-∞, ∞]
322
- image_output = torch.tanh(image_output) # Приводим к [-1, 1]
323
 
324
  # Нормализуем к [0, 1] для PIL
325
  image_output = (image_output.clamp(-1, 1) + 1) / 2
 
22
  unet=unet,
23
  scheduler=scheduler
24
  )
25
+ self.vae_scale_factor = 2 ** (len(self.vae.config.block_out_channels) - 1)
 
 
26
 
27
  def create_frequency_soft_cutoff_mask(self, height: int, width: int, cutoff_radius: float,
28
  transition_width: float = 5.0, device: torch.device = None) -> torch.Tensor:
 
116
  def preprocess_image(self, image: Image.Image, width: int, height: int):
117
  """Ресайз и центрированный кроп изображения для асимметричного VAE."""
118
  # Для энкодера с масштабом 8
119
+ target_height = ((height // self.vae_scale_factor) * self.vae_scale_factor)//2
120
+ target_width = ((width // self.vae_scale_factor) * self.vae_scale_factor)//2
121
 
122
  w, h = image.size
123
  aspect_ratio = target_width / target_height
 
196
  num_inference_steps: int = 40,
197
  guidance_scale: float = 4.0,
198
  generator: Optional[torch.Generator] = None,
199
+ seed: Optional[int] = None,
200
  output_type: str = "pil",
201
  return_dict: bool = True,
202
  structure_preservation: float = 0.2, # Новый параметр: сохранение структуры 0-1
 
205
  device = self.device
206
  dtype = self.unet.dtype
207
 
208
+ if generator is None and seed is not None:
209
+ if torch.cuda.is_available():
210
+ generator = torch.Generator(device=device)
211
+ else:
212
+ generator = torch.Generator()
213
+ generator.manual_seed(seed)
214
+
215
  # 1. Encode Prompt
216
  text_embeddings, attention_mask = self.encode_prompt(
217
  prompt, negative_prompt, device, dtype
 
222
  self.scheduler.set_timesteps(num_inference_steps, device=device)
223
  timesteps = self.scheduler.timesteps # Все 40 шагов
224
 
225
+ #print(f"Используем ВСЕ шаги: {len(timesteps)}")
226
+ #print(f"Диапазон таймстепов: [{timesteps[0].item():.3f}, {timesteps[-1].item():.3f}]")
227
+ #print(f"Коэффициент смешивания (coef): {coef}")
228
 
229
  # 3. Обработка img2img с структурированным шумом
230
  if image is not None:
 
278
  vae_scaling_factor = getattr(self.vae.config, "scaling_factor", 1.0)
279
  vae_shift_factor = getattr(self.vae.config, "shift_factor", 0.0)
280
 
281
+ latent_height = height // self.vae_scale_factor
282
+ latent_width = width // self.vae_scale_factor
283
 
284
  latents = torch.randn(
285
  (batch_size, self.unet.config.in_channels, latent_height, latent_width),
 
318
  latents = latents * vae_scaling_factor + vae_shift_factor
319
  image_output = self.vae.decode(latents.to(self.vae.dtype), return_dict=False)[0]
320
 
 
 
 
 
 
 
 
 
321
 
322
  # Нормализуем к [0, 1] для PIL
323
  image_output = (image_output.clamp(-1, 1) + 1) / 2
samples/unet_320x640_0.jpg CHANGED

Git LFS Details

  • SHA256: 8644cc610426753643daa7130d7b499b0d2f85e6d6de4979c46c47f646cb1870
  • Pointer size: 131 Bytes
  • Size of remote file: 249 kB

Git LFS Details

  • SHA256: 3d35e968dca9e6760bc975ef7843187188255efa9a249d36c585e4323c206d86
  • Pointer size: 131 Bytes
  • Size of remote file: 249 kB
samples/unet_352x640_0.jpg CHANGED

Git LFS Details

  • SHA256: c880bb082566b777c7481ea7995e2c2e6f137edd2cf912dc8c116946b4d04d26
  • Pointer size: 131 Bytes
  • Size of remote file: 174 kB

Git LFS Details

  • SHA256: 51edd15969e0eff4bacf1c1dd27b821311109c86fa4bf2b3c1b0fbef68ebabda
  • Pointer size: 131 Bytes
  • Size of remote file: 170 kB
samples/unet_384x640_0.jpg CHANGED

Git LFS Details

  • SHA256: b48ba95576766ff9e479e27a73f0ef50dbb7dd9d10610cd0b8de7bf614c7b446
  • Pointer size: 131 Bytes
  • Size of remote file: 361 kB

Git LFS Details

  • SHA256: 62d261d94463fdcad000951b394108db425f02f3b93c7f470d613addef48d0e9
  • Pointer size: 131 Bytes
  • Size of remote file: 353 kB
samples/unet_416x640_0.jpg CHANGED

Git LFS Details

  • SHA256: f383af3ce130e916dba7d7487eec270e5777b53ffc84d9c681d82fd066a3b8f9
  • Pointer size: 131 Bytes
  • Size of remote file: 373 kB

Git LFS Details

  • SHA256: a7c6cc5cd22fd5de44b5ccf33d0e05bf8a5568975b7e83cfba0d140f1c4c515f
  • Pointer size: 131 Bytes
  • Size of remote file: 346 kB
samples/unet_448x640_0.jpg CHANGED

Git LFS Details

  • SHA256: 2a614688a4193554d26b06a3217760df20a7b09d59ea1f9f47ace1661af14c04
  • Pointer size: 131 Bytes
  • Size of remote file: 304 kB

Git LFS Details

  • SHA256: ae6ed8001b9f8addd4f603039aa53ebf052f77e0734e9fbfae1858bd2de2986a
  • Pointer size: 131 Bytes
  • Size of remote file: 305 kB
samples/unet_480x640_0.jpg CHANGED

Git LFS Details

  • SHA256: 791c84e00f33a0814d14e5db5b4208d77b97b44689dc3def81f044de5c123654
  • Pointer size: 130 Bytes
  • Size of remote file: 90 kB

Git LFS Details

  • SHA256: 2ba365a524e494600c4f7df6661ecc0c1a2c216149619e4eccc46aed51913c89
  • Pointer size: 130 Bytes
  • Size of remote file: 83.7 kB
samples/unet_512x640_0.jpg CHANGED

Git LFS Details

  • SHA256: 9940a6f63f984f65f2b4d2e412072b8d030c379259c5616d09209ac004f3894b
  • Pointer size: 131 Bytes
  • Size of remote file: 408 kB

Git LFS Details

  • SHA256: 59672c40305185ad9b83dfb4892855b632c3c39f8aba74720537415e628714cf
  • Pointer size: 131 Bytes
  • Size of remote file: 390 kB
samples/unet_544x640_0.jpg CHANGED

Git LFS Details

  • SHA256: 22842736e76580e2426a4879ffba99b32cf8b915f5e55e2457a717c3d286f497
  • Pointer size: 131 Bytes
  • Size of remote file: 111 kB

Git LFS Details

  • SHA256: 9ecaffef934f374e2de5b9581fe20bdf5991c1603d4472837022210595cb02f3
  • Pointer size: 131 Bytes
  • Size of remote file: 123 kB
samples/unet_576x640_0.jpg CHANGED

Git LFS Details

  • SHA256: 4d6c3e57b0e1ac977afcb8815375d1999e999c0ca57376fe541aa33464f08919
  • Pointer size: 131 Bytes
  • Size of remote file: 169 kB

Git LFS Details

  • SHA256: b9fba7c3e98df9757a89754b15c28ba90f2cbb2d5bba39e2aaf5870667a0e6cd
  • Pointer size: 131 Bytes
  • Size of remote file: 174 kB
samples/unet_608x640_0.jpg CHANGED

Git LFS Details

  • SHA256: 3e0f922d12c1a8aeee13a178737b0a7bcad3e4dda07df3be99ecd8a69f603106
  • Pointer size: 131 Bytes
  • Size of remote file: 394 kB

Git LFS Details

  • SHA256: f7e80e2bed44a9078b3eb537912a69024f7b72d79368fd95ffb969b6a201061c
  • Pointer size: 131 Bytes
  • Size of remote file: 407 kB
samples/unet_640x320_0.jpg CHANGED

Git LFS Details

  • SHA256: 7b5e241c274cdaa312f8c30b53c820a7d97ec1fc752ae0cadd476c549b806949
  • Pointer size: 131 Bytes
  • Size of remote file: 250 kB

Git LFS Details

  • SHA256: b6052e76c58d49e18d89cf6e10ce4a920c2c16491f73854ceca090e91c8c1d70
  • Pointer size: 131 Bytes
  • Size of remote file: 248 kB
samples/unet_640x352_0.jpg CHANGED

Git LFS Details

  • SHA256: 2ce25f0f7f97bfec3a1eb1ddd2f36585fde375e05505ed3f2776b7d0b8f7fbaf
  • Pointer size: 131 Bytes
  • Size of remote file: 313 kB

Git LFS Details

  • SHA256: dd76692d684d714e565577c1b9f2700107b9d370482997014f6c754c62730084
  • Pointer size: 131 Bytes
  • Size of remote file: 293 kB
samples/unet_640x384_0.jpg CHANGED

Git LFS Details

  • SHA256: 049b7fd34b64a19b9cdabc3e491e72516172bc75174a81ad714b773b9e5f63be
  • Pointer size: 131 Bytes
  • Size of remote file: 210 kB

Git LFS Details

  • SHA256: 7608e61fad6b77059e650c40c69f8679165e2b5002bfd60f70c2021d33c9a9e1
  • Pointer size: 131 Bytes
  • Size of remote file: 217 kB
samples/unet_640x416_0.jpg CHANGED

Git LFS Details

  • SHA256: 3e4a6a758b129e60148d0d147bf756c9fa034cf65f4140d5226c54658cf95bdf
  • Pointer size: 131 Bytes
  • Size of remote file: 401 kB

Git LFS Details

  • SHA256: 14672dd0688259481436c070d394dabae3350a1fad3491545a398e8414c8f9fb
  • Pointer size: 131 Bytes
  • Size of remote file: 393 kB
samples/unet_640x448_0.jpg CHANGED

Git LFS Details

  • SHA256: f395c1978f006f1c393b39cec171865871426047f87674117a0cd51c8afafeab
  • Pointer size: 131 Bytes
  • Size of remote file: 298 kB

Git LFS Details

  • SHA256: 9d03748bfa8311e28fb8457b8157bf132deaa7f63d22bc5338a960a6971df9f0
  • Pointer size: 131 Bytes
  • Size of remote file: 278 kB
samples/unet_640x480_0.jpg CHANGED

Git LFS Details

  • SHA256: 7b58e3fa05f46c6b8e03432f1a40c7300dc7ff3eedce5d536d547b920dc21ef7
  • Pointer size: 130 Bytes
  • Size of remote file: 98.8 kB

Git LFS Details

  • SHA256: d46d0e8f3e13698b9d7fb77eb9b438f81eae7a5b70390c3156feb7bd5bd5dc15
  • Pointer size: 131 Bytes
  • Size of remote file: 101 kB
samples/unet_640x512_0.jpg CHANGED

Git LFS Details

  • SHA256: d0a9ad411a196df30440ab1932ed4c6f497550f006fbbcd55dba1d7197d7aa53
  • Pointer size: 131 Bytes
  • Size of remote file: 375 kB

Git LFS Details

  • SHA256: 5a10d2904c4a60b56cb32627ce9e218984599cbd591403b3ad028f4e9e3dc330
  • Pointer size: 131 Bytes
  • Size of remote file: 370 kB
samples/unet_640x544_0.jpg CHANGED

Git LFS Details

  • SHA256: 6653c1e56fd2783e60d15676ef0d5518617f6cdf4e58aafb6b7b7dcbf36cb2e9
  • Pointer size: 131 Bytes
  • Size of remote file: 407 kB

Git LFS Details

  • SHA256: 31fda9843d2172c6dd17a105b66935e2ff7aef769b8f21441d01e81b3a31cb8a
  • Pointer size: 131 Bytes
  • Size of remote file: 378 kB
samples/unet_640x576_0.jpg CHANGED

Git LFS Details

  • SHA256: 335decf412baec9daa5460595e7840f109d9a80cf7c460c1ed355595713ec734
  • Pointer size: 131 Bytes
  • Size of remote file: 752 kB

Git LFS Details

  • SHA256: 133eb7586a223c934470ca12f1ef716aca70eaa39611d702234c198333f8640b
  • Pointer size: 131 Bytes
  • Size of remote file: 760 kB
samples/unet_640x608_0.jpg CHANGED

Git LFS Details

  • SHA256: 36bdcebb58ac021cc5e7426a934afc3df613e4b16e537b0bf114f5d5ddddcc0b
  • Pointer size: 132 Bytes
  • Size of remote file: 1.14 MB

Git LFS Details

  • SHA256: 0f8a2e50acb596e0b7a0d998c5c41d06ce2a1eaa3e03538aa427612c37d0ae6f
  • Pointer size: 132 Bytes
  • Size of remote file: 1.18 MB
samples/unet_640x640_0.jpg CHANGED

Git LFS Details

  • SHA256: 57a8171ef398faae269cd398c69b8eeed31cb20192b71077c159eaba566c68c0
  • Pointer size: 131 Bytes
  • Size of remote file: 624 kB

Git LFS Details

  • SHA256: 71056cc8b486f22e2fd3f053bf6ec23e0964853588b82ef65dafc672de718dbe
  • Pointer size: 131 Bytes
  • Size of remote file: 653 kB
test.ipynb CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:1433c2a4011e661ee6f50e959a122d8b90fdbbb205a28c884560c3b921cda3ba
3
- size 4805047
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:4421152d5072d3cdf871fb0043fdaf246e0f5bebb26f5ccaa5dd356dfb2ffad1
3
+ size 5386516
unet/config.json CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:a14cb265318c2fc495111e70c6f22f9364fe38511040f7fe97530379027afc52
3
- size 1812
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:1a045ebd48be7f677556a522ead90df150527238b5be038d1c88cf40407dba91
3
+ size 1815
unet/diffusion_pytorch_model.safetensors CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:4bbddbf77f86e9e9beb7ac2b91a4c5510f5e3c50eaa8c2b48c46f9ec26db30c5
3
- size 3438444088
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:f518da35f8eb55f8dd01788ceb77f7c47f2e024fbe8c73f6621cfe7435236a87
3
+ size 4408122256
unet_1b.zip ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:92ad12839b75b32d0fae2870c2dee334a11b79baece052adbd43b4d32666d503
3
+ size 4408462864