EdgeConnect: Image Inpainting with Edge Prediction
Introduction
EdgeConnect introduces a novel method for image inpainting, or the process of filling in missing parts of an image. This project draws inspiration from the work process of artists who first outline the structure with lines before adding color. It employs a two-stage adversarial network that initially predicts edges and subsequently fills in the image based on these edges. This dual-step approach aims to produce more detailed and convincing results in the reconstructed image.
System Overview
The EdgeConnect system is composed of two main components:
-
Edge Generator: This network predicts the edges of the missing areas in an image. It works with both regular and irregular missing regions, essentially "hallucinating" edges where they are absent. The generator uses the known areas of the image and fills in the edges in the missing parts, serving as a guide for the next phase.
-
Image Completion Network: This part of the framework utilizes the edges predicted by the edge generator to complete the image. The presence of edge information helps the network to better understand the structure of the missing regions, leading to more realistic and detailed image inpainting.
Requirements and Setup
To get started with EdgeConnect, you'll need:
- Python 3 and PyTorch 1.0
- An NVIDIA GPU with CUDA and cuDNN
The installation involves cloning the project's GitHub repository and setting up the necessary Python packages as specified in a requirements.txt
file.
Datasets
EdgeConnect utilizes various datasets for training and testing:
-
Images: It leverages popular datasets such as Places2, CelebA, and Paris Street-View. After downloading these datasets, users need to prepare file lists for training, testing, and validation using provided scripts.
-
Irregular Masks: The project employs irregular mask datasets that include masking challenges, contributing to the robustness of the model in handling random missing sections in images.
Training and Testing
Training involves three phases:
- Edge Model Training: Focuses on learning to predict the edges of missing regions.
- Inpaint Model Training: Uses the predicted edges to fill in the missing parts of an image.
- Joint Training: Optimizes both models together for improved performance.
Testing requires setting up a configuration file and involves feeding images along with their masks into the network to evaluate its inpainting capabilities. Testing is possible at each stage – edge detection, inpainting, and the combined approach.
Evaluation
EdgeConnect uses several metrics for evaluating its performance:
- PSNR and SSIM: Commonly used metrics to assess the quality of the images produced by comparing them with the original images.
- Mean Absolute Error: Measures the average absolute differences between predicted and true values.
- Fréchet Inception Distance (FID): Quantifies the quality of generated images by comparing distributions of real and fake images.
Additional Features
EdgeConnect provides flexibility in using different edge detection methods. By default, it uses the Canny edge detector but can switch to other external edge detectors if desired. Users need to prepare the edge maps before training if using an external method.
Model Configuration
All configurations for training, testing, and evaluation are managed through a config.yaml
file. This file includes settings for model behavior, data paths, edge and mask handling, and training specifics like learning rate, batch size, and loss weights.
Conclusion
EdgeConnect represents a significant step forward in image inpainting by intelligently leveraging edge prediction to guide image completion. Its design is grounded in fundamental artistic principles combined with advanced machine learning techniques to achieve impressive results in filling in missing image regions.