Spaces:
Paused
Paused
File size: 1,256 Bytes
343e5a8 |
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 |
import torch
import torchvision.transforms.functional as F
from PIL import Image
from src.pix2pix_turbo import Pix2Pix_Turbo
# Initialize the model
model = Pix2Pix_Turbo("sketch_to_image_stochastic")
# Load the sketch image
sketch_path = "sketch.png"
image = Image.open(sketch_path).convert("RGB")
# Define the prompt
prompt = "ethereal fantasy concept art of . magnificent, celestial, ethereal, painterly, epic, majestic, magical, fantasy art, cover art, dreamy,"
# Convert the image to a tensor
#image_tensor = F.to_tensor(image) > 0.5
image = image.convert("RGB")
image_t = F.to_tensor(image) > 0.5
# Processing parameters
seed = 42
val_r = 0.4
# Run the model inference
with torch.no_grad():
c_t = image_t.unsqueeze(0).cuda().float()
torch.manual_seed(seed)
B, C, H, W = c_t.shape
noise = torch.randn((1, 4, H // 8, W // 8), device=c_t.device)
output_image = model(c_t, prompt, deterministic=False, r=val_r, noise_map=noise)
# Convert the output tensor to an image
output_pil = F.to_pil_image(output_image[0].cpu() * 0.5 + 0.5)
# Save the output image
output_path = "output.png"
output_pil.save(output_path)
print(f"Processing complete. The output image is saved as {output_path}.")
|