huggingface / huggingface/open-muse

Bug in the readme

Open
#121 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
359
Forks
30
PR merge metrics
No merged PRs in 30d

Description

Hello,

Thanks for providing this repo.

I wanted to mention that there is a bug in the readme file for the VQGAN example. A working version would be this:

```python

import torch
from torchvision import transforms
from PIL import Image
from muse import MaskGitVQGAN
import numpy as np # <--- added

torch.set_grad_enabled(False) # <--- added

# Load the pre-trained vq model from the hub
vq_model = MaskGitVQGAN.from_pretrained("openMUSE/maskgit-vqgan-imagenet-f16-256")

# encode and decode images using
encode_transform = transforms.Compose( # <--- fixed
[
transforms.Resize(256, interpolation=transforms.InterpolationMode.BILINEAR),
transforms.CenterCrop(256),
transforms.ToTensor(),
]
)
image = Image.open("/content/ILSVRC2012_val_00000028.JPEG") #
pixel_values = encode_transform(image).unsqueeze(0)
image_tokens, _ = vq_model.encode(pixel_values)
rec_image = vq_model.decode(image_tokens)

# Convert to PIL images
rec_image = 2.0 * rec_image - 1.0
rec_image = torch.clamp(rec_image, -1.0, 1.0)
rec_image = (rec_image + 1.0) / 2.0
rec_image *= 255.0
rec_image = rec_image.permute(0, 2, 3, 1).cpu().numpy().astype(np.uint8)
pil_images = [Image.fromarray(image) for image in rec_image]
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.