Skip to content

Image not generated as it should #237

@KAVYANSHTYAGI

Description

@KAVYANSHTYAGI

Screenshot 2025-01-13 235004

THE SCRIPT I RAN

import torch
from torchvision import transforms
from PIL import Image
import matplotlib.pyplot as plt
import numpy as np
from models.networks import ResnetGenerator, get_norm_layer

Adjust this to correctly import your model and its norm layer

from networks import ResnetGenerator, get_norm_layer

def deblur_image(image_path, model):
img = Image.open(image_path).convert('RGB')

# Display the original image with correct color mapping
plt.figure(figsize=(10, 5))
plt.subplot(1, 2, 1)
plt.imshow(img)
plt.title('Original Image')
plt.axis('off')

# Transform and model prediction
transform = transforms.Compose([
    transforms.Resize((256, 256)),
    transforms.ToTensor(),
    transforms.Normalize([0.5, 0.5, 0.5], [0.5, 0.5, 0.5])  # This should match the model's expected input
])
img_tensor = transform(img).unsqueeze(0)  # Add batch dimension
with torch.no_grad():
    output_tensor = model(img_tensor)
output_tensor = (output_tensor + 1) / 2  # Scale output to [0, 1]

# Convert tensor to image
output_image = transforms.ToPILImage()(output_tensor.squeeze(0))
output_image = np.array(output_image)

# Display the deblurred image
plt.subplot(1, 2, 2)
plt.imshow(output_image)
plt.title('Deblurred Image')
plt.axis('off')

plt.show()

Load your model and deblur the image

model = load_pretrained_model(x, 3, 3, 64, 'instance', 9, False)
deblur_image(y, model)

x = '/content/DeblurGAN/checkpoints/experiment_name/latest_net_G.pth'
y = '/content/drive/MyDrive/Food Image Datasets/North Indian/main_final/training/veg sandwich - Google Search/1.jpeg'

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions