A project to color a black and white image to color using deep learning
First install the neccessary libraries
pip install -r requirements.txtDownload the model and run script
python demo_autoencoder.py -p -m model/effnet_colorizer.h5 -i data/path/to/imageor pix2pix (generally more accurate)
python demo_pix2pix.py -i data/path/to/imageThe idea on how to convert an image from black white to a color image can be broken down to the following steps:
- Read Image as RGB
- Convert Image to Lab Color Space
- Create neural network to map L color space to ab color space
- Model will use L (black white) to predict ab color space
- Create empty image and add L image and ab image to form a complete Lab Image
- Convert Lab Image to RGB again to get back a colorize image
- Train AutoEncoder with Fusion of Pretrained Model
- Add metrics specified here
- Inference script for all models
- Train pix2pix(GAN) model for more accurate results
- Train with dynamic unet for pix2pix
- Use pytorch image quality metrics for image quality assements
- Converted model to onnx for deployment
- Onnx Inference Script
- If time is available move to deployment architecture (FAST API)
- Upload model drive download links
- Requirements txt
- Add Demo Results
- Write out findings
- Try to move to specified architecture using nvidia triton
- Move preporcessing with a model instead of code
- As of the current available models pretrained model with autoencoder seems to have better results
- Previously though of metrics where eyeballing is unavoidable has changed a bit
- Need to switch to pytorch for gan model as seems easier to read for now
You can download the models trained here
| Model Name | Backbone | Drive Link |
|---|---|---|
| Simple AutoEncoder | None | here |
| EffNet Autoencoder | Efficient Net B3 | here |
| Unet Pretrained Generator | Resnet 18 | here |
| Unet Finetuned Generator | Resnet 18 | here |
| Model | DISTS Score |
|---|---|
| Pix2pix - Resnet18 | 0.7836 |
The following repos were based off these guides
- https://emilwallner.medium.com/colorize-b-w-photos-with-a-100-line-neural-network-53d9b4449f8d
- https://nbviewer.jupyter.org/github/moein-shariatnia/Deep-Learning/blob/main/Image%20Colorization%20Tutorial/Image%20Colorization%20with%20U-Net%20and%20GAN%20Tutorial.ipynb
- https://github.com/emilwallner/Coloring-greyscale-images
- https://towardsdatascience.com/u-net-deep-learning-colourisation-of-greyscale-images-ee6c1c61aabe
