Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

latent_formats.py 3.6 KB

You have to be logged in to leave a comment. Sign In
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
  1. import torch
  2. class LatentFormat:
  3. scale_factor = 1.0
  4. latent_rgb_factors = None
  5. taesd_decoder_name = None
  6. def process_in(self, latent):
  7. return latent * self.scale_factor
  8. def process_out(self, latent):
  9. return latent / self.scale_factor
  10. class SD15(LatentFormat):
  11. def __init__(self, scale_factor=0.18215):
  12. self.scale_factor = scale_factor
  13. self.latent_rgb_factors = [
  14. # R G B
  15. [ 0.3512, 0.2297, 0.3227],
  16. [ 0.3250, 0.4974, 0.2350],
  17. [-0.2829, 0.1762, 0.2721],
  18. [-0.2120, -0.2616, -0.7177]
  19. ]
  20. self.taesd_decoder_name = "taesd_decoder"
  21. class SDXL(LatentFormat):
  22. def __init__(self):
  23. self.scale_factor = 0.13025
  24. self.latent_rgb_factors = [
  25. # R G B
  26. [ 0.3920, 0.4054, 0.4549],
  27. [-0.2634, -0.0196, 0.0653],
  28. [ 0.0568, 0.1687, -0.0755],
  29. [-0.3112, -0.2359, -0.2076]
  30. ]
  31. self.taesd_decoder_name = "taesdxl_decoder"
  32. class SDXL_Playground_2_5(LatentFormat):
  33. def __init__(self):
  34. self.scale_factor = 0.5
  35. self.latents_mean = torch.tensor([-1.6574, 1.886, -1.383, 2.5155]).view(1, 4, 1, 1)
  36. self.latents_std = torch.tensor([8.4927, 5.9022, 6.5498, 5.2299]).view(1, 4, 1, 1)
  37. self.latent_rgb_factors = [
  38. # R G B
  39. [ 0.3920, 0.4054, 0.4549],
  40. [-0.2634, -0.0196, 0.0653],
  41. [ 0.0568, 0.1687, -0.0755],
  42. [-0.3112, -0.2359, -0.2076]
  43. ]
  44. self.taesd_decoder_name = "taesdxl_decoder"
  45. def process_in(self, latent):
  46. latents_mean = self.latents_mean.to(latent.device, latent.dtype)
  47. latents_std = self.latents_std.to(latent.device, latent.dtype)
  48. return (latent - latents_mean) * self.scale_factor / latents_std
  49. def process_out(self, latent):
  50. latents_mean = self.latents_mean.to(latent.device, latent.dtype)
  51. latents_std = self.latents_std.to(latent.device, latent.dtype)
  52. return latent * latents_std / self.scale_factor + latents_mean
  53. class SD_X4(LatentFormat):
  54. def __init__(self):
  55. self.scale_factor = 0.08333
  56. self.latent_rgb_factors = [
  57. [-0.2340, -0.3863, -0.3257],
  58. [ 0.0994, 0.0885, -0.0908],
  59. [-0.2833, -0.2349, -0.3741],
  60. [ 0.2523, -0.0055, -0.1651]
  61. ]
  62. class SC_Prior(LatentFormat):
  63. def __init__(self):
  64. self.scale_factor = 1.0
  65. self.latent_rgb_factors = [
  66. [-0.0326, -0.0204, -0.0127],
  67. [-0.1592, -0.0427, 0.0216],
  68. [ 0.0873, 0.0638, -0.0020],
  69. [-0.0602, 0.0442, 0.1304],
  70. [ 0.0800, -0.0313, -0.1796],
  71. [-0.0810, -0.0638, -0.1581],
  72. [ 0.1791, 0.1180, 0.0967],
  73. [ 0.0740, 0.1416, 0.0432],
  74. [-0.1745, -0.1888, -0.1373],
  75. [ 0.2412, 0.1577, 0.0928],
  76. [ 0.1908, 0.0998, 0.0682],
  77. [ 0.0209, 0.0365, -0.0092],
  78. [ 0.0448, -0.0650, -0.1728],
  79. [-0.1658, -0.1045, -0.1308],
  80. [ 0.0542, 0.1545, 0.1325],
  81. [-0.0352, -0.1672, -0.2541]
  82. ]
  83. class SC_B(LatentFormat):
  84. def __init__(self):
  85. self.scale_factor = 1.0 / 0.43
  86. self.latent_rgb_factors = [
  87. [ 0.1121, 0.2006, 0.1023],
  88. [-0.2093, -0.0222, -0.0195],
  89. [-0.3087, -0.1535, 0.0366],
  90. [ 0.0290, -0.1574, -0.4078]
  91. ]
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...