tahamajs commited on
Commit
7fc8ab7
·
verified ·
1 Parent(s): 1fe5b3c

Update Readme

Browse files
Files changed (1) hide show
  1. README.md +19 -69
README.md CHANGED
@@ -1,4 +1,3 @@
1
-
2
  ---
3
  license: mit
4
  language: en
@@ -15,80 +14,31 @@ datasets:
15
 
16
  # U-Net for Image Inpainting on CIFAR-10
17
 
18
- This repository contains a PyTorch implementation of a deep U-Net with Residual Blocks, trained to perform image inpainting on the CIFAR-10 dataset. The model takes an image with a masked (blacked-out) region and reconstructs the missing part.
19
-
20
- ## Model Description
21
-
22
- The model is a `ComplexUNet` architecture, a variant of the standard U-Net. It features:
23
- - **Deeper Architecture**: 4 downsampling and 4 upsampling stages.
24
- - **Residual Blocks**: Each stage uses residual blocks instead of simple convolutional layers.
25
- - **Increased Width**: The model was trained with `base_channels=96`.
26
- - **Total Parameters**: 73,148,259
27
-
28
- ## How to Use
29
-
30
- First, install the required libraries:
31
- ```bash
32
- pip install torch torchvision numpy Pillow
33
- ```
34
-
35
- Then, you can load the model and perform inpainting on an image tensor.
36
 
37
- ```python
38
- import torch
39
- from torchvision import transforms as T
40
- from PIL import Image
41
- from model import ComplexUNet # Import the class from model.py
42
 
43
- # --- Setup ---
44
- DEVICE = torch.device("cuda" if torch.cuda.is_available() else "cpu")
45
- # Download the .pth file from the 'Files and versions' tab of this repo
46
- MODEL_PATH = "inpainting_model_larger.pth"
47
-
48
- # --- Load Model ---
49
- model = ComplexUNet(base_channels=96)
50
- model.load_state_dict(torch.load(MODEL_PATH, map_location=DEVICE))
51
- model.to(DEVICE)
52
- model.eval()
53
-
54
- # --- Load and Preprocess Image ---
55
- # image = Image.open("your_image.png").convert("RGB")
56
- # For demonstration, let's create a dummy tensor
57
- transform = T.Compose([T.Resize((32, 32)), T.ToTensor()])
58
- # image_tensor = transform(image)
59
- image_tensor = torch.rand(3, 32, 32)
60
-
61
- # --- Create a Mask ---
62
- masked_tensor = image_tensor.clone()
63
- masked_tensor[:, 8:24, 8:24] = 0 # Example mask in the center
64
-
65
- # --- Perform Inpainting ---
66
- with torch.no_grad():
67
- input_tensor = masked_tensor.unsqueeze(0).to(DEVICE)
68
- reconstructed_tensor = model(input_tensor).squeeze(0).cpu()
69
 
70
- # 'reconstructed_tensor' now holds the inpainted image.
71
- from torchvision.transforms.functional import to_pil_image
72
- reconstructed_image = to_pil_image(reconstructed_tensor)
73
- reconstructed_image.save("reconstructed_image.png")
74
- print("Saved reconstructed_image.png")
75
- ```
76
 
77
- ## Training Data
78
 
79
- The model was trained on the **CIFAR-10** dataset.
80
- - **Preprocessing**: Images were used at their original **32x32 pixels** resolution.
81
- - **Augmentation**: For each training image, a random rectangular mask was applied.
 
 
82
 
83
- ## Training Procedure
84
 
85
- - **Framework**: PyTorch
86
- - **Optimizer**: Adam
87
- - **Learning Rate**: 0.001
88
- - **Epochs**: 50
89
- - **Batch Size**: 128
90
- - **Loss Function**: Mean Squared Error (MSE)
91
 
92
- ## Evaluation
93
 
94
- Evaluation metrics were not saved by the training script. To get PSNR and SSIM, please run the `evaluate_model` function from the training script.
 
 
 
 
1
  ---
2
  license: mit
3
  language: en
 
14
 
15
  # U-Net for Image Inpainting on CIFAR-10
16
 
17
+ This repository contains a PyTorch implementation of a deep U-Net with Residual Blocks, trained to perform image inpainting on the **CIFAR-10** dataset. The model takes a 32x32 image with a masked (blacked-out) region and reconstructs the missing part.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
18
 
19
+ | Original | Masked Input | Reconstructed Output |
20
+ | :------: | :----------: | :------------------: |
21
+ | <img src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/blog/diffusers-this-is-fine/original.png" width="128"> | <img src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/blog/diffusers-this-is-fine/masked.png" width="128"> | <img src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/blog/diffusers-this-is-fine/inpainted.png" width="128"> |
22
+ > **Note**: The images above are illustrative examples. You can generate your own by running the code below.
 
23
 
24
+ ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
25
 
26
+ ## Model Architecture
 
 
 
 
 
27
 
28
+ The model is a `ComplexUNet`, a variant of the standard U-Net architecture, designed to be deeper and wider for improved performance.
29
 
30
+ * **Framework**: PyTorch
31
+ * **Architecture**: U-Net with 4 downsampling and 4 upsampling stages.
32
+ * **Backbone**: Each stage uses **Residual Blocks** instead of simple convolutional layers.
33
+ * **Model Width**: The number of base channels is increased to `96` for higher capacity.
34
+ * **Total Parameters**: 73,148,259
35
 
36
+ ---
37
 
38
+ ## How to Use
 
 
 
 
 
39
 
40
+ The following code snippet provides a complete example of how to load the model, process an image from the CIFAR-10 test set, and visualize the inpainting result.
41
 
42
+ First, ensure you have the necessary libraries installed:
43
+ ```bash
44
+ pip install torch torchvision numpy matplotlib Pillow