Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Image not generated as it should #237

Open
KAVYANSHTYAGI opened this issue Jan 13, 2025 · 0 comments
Open

Image not generated as it should #237

KAVYANSHTYAGI opened this issue Jan 13, 2025 · 0 comments

Comments

@KAVYANSHTYAGI
Copy link

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'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant