Slide 1

Slide 1 text

ColorTransfer Bringing Life to Black & White Photos @preslavrachev / 24.05.2018

Slide 2

Slide 2 text

Hi there! ! My name is Preslav I am a full-stack backend and mobile engineer… … and a data scientist by heart

Slide 3

Slide 3 text

I have always been fascinated by the generative nature of simple algorithms

Slide 4

Slide 4 text

No content

Slide 5

Slide 5 text

All of my sketches shared the same idea: start with simple rules and apply them over 1000s of iterations

Slide 6

Slide 6 text

Add the optimisation part, and this starts sounding a lot like ML Because it is

Slide 7

Slide 7 text

Colorizing BW Photos

Slide 8

Slide 8 text

r/Colorization/

Slide 9

Slide 9 text

Source: How obsessive artists colorize old photos | Vox

Slide 10

Slide 10 text

X Y Y′

Slide 11

Slide 11 text

Let’s start with a CNN

Slide 12

Slide 12 text

Source: Flickr

Slide 13

Slide 13 text

I mean, a Convolutional Neural Network

Slide 14

Slide 14 text

Source: CS231n: Convolutional Neural Networks for Visual Recognition

Slide 15

Slide 15 text

Image Source: Machine Learning Guru

Slide 16

Slide 16 text

CNNs can be used for both regression and classification

Slide 17

Slide 17 text

Challenge: Make a CNN that takes 1000s*M*N*256 of input points, and generates 1*M*N*2563 outputs Without spending a fortune on hardware

Slide 18

Slide 18 text

Lab to the rescue

Slide 19

Slide 19 text

Source: How to colorize black & white photos with just 100 lines of neural network code Lab is a 3-dimensional representation of the visible color space: L (lightness 0-100) / a (green-red -127:127) / b (blue-yellow -127:127)

Slide 20

Slide 20 text

Put simply, by using Lab instead of RGB, we can reduce our problem space 256 times! And get a BW layer for free!

Slide 21

Slide 21 text

We start training…

Slide 22

Slide 22 text

…and, bummer!

Slide 23

Slide 23 text

It’s all … brown

Slide 24

Slide 24 text

No content

Slide 25

Slide 25 text

Source: Wikipedia Mean Square Error (MSE)

Slide 26

Slide 26 text

CNNs can be used for both regression and classification

Slide 27

Slide 27 text

If we think about the problem as classification instead, an appropriate loss function might have a better chance at picking separate colors

Slide 28

Slide 28 text

OK, but choosing across 2562 == 216 classes? Are you out of your mind?

Slide 29

Slide 29 text

Challenge: Turn the a and b layers of the source images into a single layer of class labels

Slide 30

Slide 30 text

Let’s quantize

Slide 31

Slide 31 text

Source: Wikipedia 10

Slide 32

Slide 32 text

10 20

Slide 33

Slide 33 text

By quantizing to a grid of 10, we lost a fraction of the visual quality, but reduced the problem space 100 times!

Slide 34

Slide 34 text

By using empirical ML methods, such as clustering, we can reduce the ab space even further.

Slide 35

Slide 35 text

In fact, one of the cornerstone studies in the field, has managed to reduce the ab space to a mere 313 distinct colors! Recall that the non-quantized ab space has 65536 possible values

Slide 36

Slide 36 text

Having reduced the color space, we can now treat colorization like multi-label classification. Each pixel in the input image would represent one of 313 classes: 0, 0, 0, 0, 0, … 0, 1, 0, 0, 0 M*N 0, 0, 1, 0, 0, … 0, 0, 0, 0, 0

Slide 37

Slide 37 text

Results (Disclaimer: I used R. Zhang’s pre-trained model)

Slide 38

Slide 38 text

No content

Slide 39

Slide 39 text

No content

Slide 40

Slide 40 text

My Progress

Slide 41

Slide 41 text

No content

Slide 42

Slide 42 text

No content

Slide 43

Slide 43 text

Open Source All the Things! • Stepping on the shoulders of giants in the ML community • My models are still far from ideal, but I am trying to open-source every step of this journey • Repo: https://github.com/preslavrachev/nn-photo-colorization (https://bit.ly/ 2GNCq2W) • My main challenges right now are finding more time and computing resources. • Using a free Kaggle kernel to do all the training • That said, I would love to work on this project full-time • Advice: Don’t be scared by ML. Choose a topic of your own liking, and it will be your driving force.

Slide 44

Slide 44 text

Thank You!

Slide 45

Slide 45 text

• Zhang, Richard, Phillip Isola, and Alexei A. Efros. “Colorful image colorization.” European Conference on Computer Vision. Springer, Cham, 2016. • https://github.com/richzhang/colorization • Wallner, E.: How to colorize black & white photos with just 100 lines of neural network code Medium.com, Oct 29, 2017 • Dahl, R.: Automatic Colorization Tinyclouds.org, Jan, 2016 • Cheng, Z., Yang, Q., Sheng, B.: Deep colorization. In: Proceedings of the IEEE International Conference on Computer Vision. (2015) 415–423 • Zhang, Richard, et al. "Real-time user-guided image colorization with learned deep priors." arXiv preprint arXiv:1705.02999 (2017). • https://github.com/junyanz/interactive-deep-colorization • Karpathy, Andrej. "Cs231n convolutional neural networks for visual recognition." Neural networks 1 (2016).