Views
No views yet
ComplexUNet architecture, a variant of the standard U-Net. It features:base_channels=96.pip install torch torchvision numpy Pillow1import torch
2from torchvision import transforms as T
3from PIL import Image
4from model import ComplexUNet # Import the class from model.py
5
6# --- Setup ---
7DEVICE = torch.device("cuda" if torch.cuda.is_available() else "cpu")
8# Download the .pth file from the 'Files and versions' tab of this repo
9MODEL_PATH = "inpainting_model_larger.pth"
10
11# --- Load Model ---
12model = ComplexUNet(base_channels=96)
13model.load_state_dict(torch.load(MODEL_PATH, map_location=DEVICE))
14model.to(DEVICE)
15model.eval()
16
17# --- Load and Preprocess Image ---
18# image = Image.open("your_image.png").convert("RGB")
19# For demonstration, let's create a dummy tensor
20transform = T.Compose([T.Resize((32, 32)), T.ToTensor()])
21# image_tensor = transform(image)
22image_tensor = torch.rand(3, 32, 32)
23
24# --- Create a Mask ---
25masked_tensor = image_tensor.clone()
26masked_tensor[:, 8:24, 8:24] = 0 # Example mask in the center
27
28# --- Perform Inpainting ---
29with torch.no_grad():
30 input_tensor = masked_tensor.unsqueeze(0).to(DEVICE)
31 reconstructed_tensor = model(input_tensor).squeeze(0).cpu()
32
33# 'reconstructed_tensor' now holds the inpainted image.
34from torchvision.transforms.functional import to_pil_image
35reconstructed_image = to_pil_image(reconstructed_tensor)
36reconstructed_image.save("reconstructed_image.png")
37print("Saved reconstructed_image.png")evaluate_model function from the training script.