https://github.com/mehdidc/vqgan_nodep
VQGAN from LDM without hell of dependencies
https://github.com/mehdidc/vqgan_nodep
latent-diffusion-models ldm stable-diffusion taming-transformers vqgan vqvae
Last synced: 6 days ago
JSON representation
VQGAN from LDM without hell of dependencies
- Host: GitHub
- URL: https://github.com/mehdidc/vqgan_nodep
- Owner: mehdidc
- Created: 2024-01-26T17:48:40.000Z (over 1 year ago)
- Default Branch: master
- Last Pushed: 2024-01-28T13:34:44.000Z (over 1 year ago)
- Last Synced: 2024-05-14T00:16:40.076Z (about 1 year ago)
- Topics: latent-diffusion-models, ldm, stable-diffusion, taming-transformers, vqgan, vqvae
- Language: Python
- Homepage:
- Size: 99.6 KB
- Stars: 4
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# VQGAN from Latent Diffusion Models/Taming Transformers without hell of dependencies
because, we don't need pytorch lightning and all the code base from https://github.com/CompVis/taming-transformers
to load VQGAN.## Install
```bash
git clone https://github.com/mehdidc/vqgan_nodep
cd vqgan_nodep
python setup.py develop
```or simply
`pip install git+https://github.com/mehdidc/vqgan_nodep`
## Usage
to download the model:
```bash
wget https://github.com/mehdidc/feed_forward_vqgan_clip/releases/download/0.1/vqgan_imagenet_f16_16384.yaml
wget https://github.com/mehdidc/feed_forward_vqgan_clip/releases/download/0.1/vqgan_imagenet_f16_16384.ckpt
```then, to test it:
```python
import torch
from vqgan_nodep import VQModel
from omegaconf import OmegaConf
import torchvision
from PIL import Image
config = OmegaConf.load("vqgan_imagenet_f16_16384.yaml")
model = VQModel(**config.model.params)
model.eval().requires_grad_(False)
model.init_from_ckpt("vqgan_imagenet_f16_16384.ckpt")
img = Image.open("dog.jpg")
img = img.resize((224, 224))
# to Tensor
x = torchvision.transforms.ToTensor()(img)
x = x.unsqueeze(0)
ids = model.tokenize(x)
xr = model.reconstruct_from_tokens(ids)
# to pil
xr = xr.squeeze(0).permute(1, 2, 0).clamp(0, 1).numpy()
xr = (xr * 255).astype("uint8")
xr = Image.fromarray(xr)
xr.save("dog_recon.jpg")
```