Update README.md
Browse files
README.md
CHANGED
|
@@ -1,3 +1,53 @@
|
|
| 1 |
-
---
|
| 2 |
-
license: cc-by-nc-4.0
|
| 3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: cc-by-nc-4.0
|
| 3 |
+
library_name: diffusers
|
| 4 |
+
---
|
| 5 |
+
|
| 6 |
+
It's simple upscaler using AsymmetricAutoencoderKL. I was playing around with code used for training in the middle of it a lot so it's nothing scientific. I was just pleased with results from something that easy to train.
|
| 7 |
+
|
| 8 |
+
For optimizers, training was done with AdEMAMix optimizer, dataset of ~4k images mostly including photos, digital art and small amount of PBR textures. I did some finetuning with same dataset, but Adopt optimizer with OrthoGrad from <a href="https://arxiv.org/abs/2501.04697" target="_blank"><i>Grokking at the Edge of Numerical Stability</i></a> (arXiv: 2501.04697). Model was trained at 96px x 96px resolution (so 192px x 192ox output).
|
| 9 |
+
|
| 10 |
+
For loss, I was using most of the time simple HSL loss (1 - cosine of difference between target and pred H and L1 loss for S and L channels), LPIPS+ and DISTS.
|
| 11 |
+
|
| 12 |
+
Model have issues with handling jpeg artifacts because I couldn't train it on random compression levels due to lack of support of ROCm by torchvision.transforms.v2.JPEG. In this case it's better to scale down image a bit before upscaling.
|
| 13 |
+
|
| 14 |
+
This is some proof of concept model. It can't be used commercially as is, but there is a chance that I'll train new version on some CC0 dataset with license permiting commercial usage and with better jpeg artifacts handling in future.
|
| 15 |
+
|
| 16 |
+
You can run model using code below
|
| 17 |
+
|
| 18 |
+
```
|
| 19 |
+
import torch
|
| 20 |
+
|
| 21 |
+
from torchvision import transforms, utils
|
| 22 |
+
|
| 23 |
+
import diffusers
|
| 24 |
+
from diffusers import AsymmetricAutoencoderKL
|
| 25 |
+
|
| 26 |
+
from diffusers.utils import load_image
|
| 27 |
+
|
| 28 |
+
def crop_image_to_nearest_divisible_by_8(img):
|
| 29 |
+
# Check if the image height and width are divisible by 8
|
| 30 |
+
if img.shape[1] % 8 == 0 and img.shape[2] % 8 == 0:
|
| 31 |
+
return img
|
| 32 |
+
else:
|
| 33 |
+
# Calculate the closest lower resolution divisible by 8
|
| 34 |
+
new_height = img.shape[1] - (img.shape[1] % 8)
|
| 35 |
+
new_width = img.shape[2] - (img.shape[2] % 8)
|
| 36 |
+
|
| 37 |
+
# Use CenterCrop to crop the image
|
| 38 |
+
transform = transforms.Compose([transforms.CenterCrop((new_height, new_width)) , t>
|
| 39 |
+
img = transform(img).to(torch.float32).clamp(-1, 1)
|
| 40 |
+
|
| 41 |
+
return img
|
| 42 |
+
|
| 43 |
+
vae = AsymmetricAutoencoderKL.from_pretrained("Heasterian/AsymmetricAutoencoderKLUpscaler">
|
| 44 |
+
vae.requires_grad_(False)
|
| 45 |
+
|
| 46 |
+
image = load_image(r"/home/heasterian/test/a/F8VlGmCWEAAUVpc (copy).jpeg")
|
| 47 |
+
|
| 48 |
+
image = crop_image_to_nearest_divisible_by_8(image).unsqueeze(0)
|
| 49 |
+
|
| 50 |
+
upscaled_image = vae(image).sample
|
| 51 |
+
# Save the reconstructed image
|
| 52 |
+
utils.save_image(upscaled_image, "test.png")
|
| 53 |
+
```
|