Skip to content

hklchung/Prism-ColouringGreyscalePhotos

Repository files navigation

Contributors Forks Stargazers Issues

Python 3.6 Keras 2.3.1 TensorFlow-GPU 2.1.0 Scikit Image 0.15.0 License MIT


Colouring Greyscale Photos

Prism - Using convolutional neural network to colourise greyscale photos.
Explore the docs »

View Demo · Report Bug · Request Feature

Table of Contents

About the Project

Convolutional Neural Networks (CNN) are commonly used for computer vision. In this project, I built a CNN that can turn black and white (greyscale) images into coloured images. Results from after 500 epochs of training are displayed below.

Nature

Original Image (B&W) Prism Effect (Colourised)

People

Original Image (B&W) Prism Effect (Colourised)

Prism will take images of any size, rescale and padded (with zeros) to 400x400 and convert from RGB to CIELAB colour space. The CIELAB colour space consists of 3 layers:

  • the lightness from black (0) to white (100);
  • from green (−) to red (+);
  • and from blue (−) to yellow (+).

A training set of 1,187 images, taken from my personal photo album consisting of outdoor, indoor, people at close up and various inanimate objects were used to train the CNN model. The images displayed above belong to a test set of 8 greyscale images scraped from various online sources and the colours were given by the final model after training 500 epochs.

Please note that this is the model that is made available in the current release and Prism uses this model by default to colourise user photos. The architecture of the model is given below.

Getting Started

Hope you are now excited with testing out Prism on your machine. To get started, please follow the below guidelines on prerequisites and installation.

Prerequisites

  • Keras==2.3.1
  • Scikit-Image==0.15.0
  • PIL==6.2.0
  • Tensorflow-gpu==2.1.0
  • Numpy==1.18.2

Installation

  1. Fork and star this repo ;)
  2. Create a folder on your machine for your project
  3. Inside the folder right-click and select Git Bash Here
  4. Git clone this repo into the folder by running the below command
git clone https://github.com/hklchung/Prism-ColouringGreyscalePhotos.git
  1. Go inside the folder Prism and create the below folders as displayed
   L Prism
      L Image
         L Train
         L Test
      L Model
      L Result
  • Image folder contains the Train and Test folders
    • Train folder contains all images used for training a model (not required if you are not training a model)
    • Test folder contains all images that you would like to colourise
  • Model folder stores all user trained models
  • Result folder stores all colourised images

Usage

Spyder

In this short tutorial, I will walk you through how you can get Prism to work on Spyder

  1. Import Prism package and run Prism
from Prism import *
Prism()
  1. There is a 'Train' mode and a 'Test' mode
  2. Continue reading if you are only interested in colourising greyscale photos/images, otherwise skip to step 4
  • First go to Image/Test folder and place ~10 greyscale images that you would like to colourise
  • Alternatively you can stick with the ones that are provided with this package
  • Will you be training a model today? [y/n]: enter n
  • Please select your desired output dimensions: I recommend 400 x 400, enter 2
  • Do you wish to use the Prism pre-trained model? [y/n]: enter y
  • When the program stops, you will see the colourised photos/images in the Result folder
  1. For training, follow the below steps
  • Will you be training a model today? [y/n]: enter y
  • How many epochs will your model train? [enter int between 1-1000]: I recommend picking 1 for the first run
  • Please select your desired output dimensions: I recommend 400 x 400, enter 2
  • When the program stops, you will see your model weights saved in the Model folder

Bash

Alternatively you can run Prism through Bash

  1. Give permission to execute the scripts
chmod 755 Prism.py
chmod 755 main.py
  1. Execute main.py
python3 main.py
  1. All the subsequent steps are as per above outlined in the Spyder instructions

Contributing

I welcome anyone to contribute to this project so if you are interested, feel free to add your code. Alternatively, if you are not a programmer but would still like to contribute to this project, please click on the request feature button at the top of the page and provide your valuable feedback.

Contact

Known Issues

  • Training may take a very long time if you do not have a GPU available
  • If you have previously installed tensorflow-gpu with pip, tensorflow may be unable to detect your GPU. To overcome this issue, first uninstall tensorflow-gpu, then reinstall with conda.
  • If you are running Prism via Terminal (or Bash) you may encounter this error "Failed to get convolution algorithm. This is probably because cuDNN failed to initialize, so try looking to see if a warning log message was printed above." If this happens, you can uninstall the cuDNN and the CUDA that was installed by Conda.