SkillAgentSearch skills...

DeOldify

No description available

Install / Use

/learn @alfagao/DeOldify
About this skill

Quality Score

0/100

Supported Platforms

Universal

README

DeOldify

<img src="https://colab.research.google.com/assets/colab-badge.svg" align="center">

Get more updates on Twitter <img src="result_images/Twitter_Social_Icon_Rounded_Square_Color.svg" width="16">

Simply put, the mission of this project is to colorize and restore old images. I'll get into the details in a bit, but first let's get to the pictures! BTW – most of these source images originally came from the TheWayWeWere subreddit, so credit to them for finding such great photos.

Some of many results - These are pretty typical!

Maria Anderson as the Fairy Fleur de farine and Lyubov Rabtsova as her page in the ballet “Sleeping Beauty” at the Imperial Theater, St. Petersburg, Russia, 1890.

Ballerinas

Woman relaxing in her livingroom (1920, Sweden)

SwedenLivingRoom

Medical Students pose with a cadaver around 1890

MedStudents

Surfer in Hawaii, 1890

1890Surfer

Whirling Horse, 1898

WhirlingHorse

Interior of Miller and Shoemaker Soda Fountain, 1899

SodaFountain

Paris in the 1880s

Paris1880s

Edinburgh from the sky in the 1920s

Edinburgh

Texas Woman in 1938

TexasWoman

People watching a television set for the first time at Waterloo station, London, 1936

Television

Geography Lessons in 1850

Geography

Chinese Opium Smokers in 1880

OpiumReal

Note that even really old and/or poor quality photos will still turn out looking pretty cool:

Deadwood, South Dakota, 1877

Deadwood

Siblings in 1877

Deadwood

Portsmouth Square in San Franscisco, 1851

PortsmouthSquare

Samurais, circa 1860s

Samurais

Granted, the model isn't always perfect. This one's red hand drives me nuts because it's otherwise fantastic:

Seneca Native in 1908

Samurais

It can also colorize b&w line drawings:

OpiumDrawing

The Technical Details

This is a deep learning based model. More specifically, what I've done is combined the following approaches:

  • Self-Attention Generative Adversarial Network (https://arxiv.org/abs/1805.08318). Except the generator is a pretrained U-Net, and I've just modified it to have the spectral normalization and self-attention. It's a pretty straightforward translation. I'll tell you what though – it made all the difference when I switched to this after trying desperately to get a Wasserstein GAN version to work. I liked the theory of Wasserstein GANs but it just didn't pan out in practice. But I'm in love with Self-Attention GANs.
  • Training structure inspired by (but not the same as) Progressive Growing of GANs (https://arxiv.org/abs/1710.10196). The difference here is the number of layers remains constant – I just changed the size of the input progressively and adjusted learning rates to make sure that the transitions between sizes happened successfully. It seems to have the same basic end result – training is faster, more stable, and generalizes better.
  • Two Time-Scale Update Rule (https://arxiv.org/abs/1706.08500). This is also very straightforward – it's just one to one generator/critic iterations and higher critic learning rate.
  • Generator Loss is two parts: One is a basic Perceptual Loss (or Feature Loss) based on VGG16 – this just biases the generator model to replicate the input image. The second is the loss score from the critic. For the curious – Perceptual Loss isn't sufficient by itself to produce good results. It tends to just encourage a bunch of brown/green/blue – you know, cheating to the test, basically, which neural networks are really good at doing! Key thing to realize here is that GANs essentially are learning the loss function for you – which is really one big step closer to toward the ideal that we're shooting for in machine learning. And of course you generally get much better results when you get the machine to learn something you were previously hand coding. That's certainly the case here.

The beauty of this model is that it should be generally useful for all sorts of image modification, and it should do it quite well. What you're seeing above are the results of the colorization model, but that's just one component in a pipeline that I'm looking to develop here with the exact same model.

What I develop next with this model will be based on trying to solve the problem of making these old images look great, so the next item on the agenda for me is the "defade" model. I've committed initial efforts on that and it's in the early stages of training as I write this. Basically it's just training the same model to reconstruct images that augmented with ridiculous contrast/brightness adjustments, as a simulation of fading photos and photos taken with old/bad equipment. I've already seen some promising results on that as well:

DeloresTwoChanges

This Project, Going Forward

So that's the gist of this project – I'm looking to make old photos look reeeeaaally good with GANs, and more importantly, make the project useful. And yes, I'm definitely interested in doing video, but first I need to sort out how to get this model under control with memory (it's a beast). It'd be nice if the models didn't take two to three days to train on a 1080TI as well (typical of GANs, unfortunately). In the meantime though this is going to be my baby and I'll be actively updating and improving the code over the foreseeable future. I'll try to make this as user-friendly as possible, but I'm sure there's going to be hiccups along the way.

Oh and I swear I'll document the code properly...eventually. Admittedly I'm one of those people who believes in "self documenting code" (LOL).

Getting Started Yourself

The easiest way to get started is to simply try out colorization here on Colab: https://colab.research.google.com/github/jantic/DeOldify/blob/master/DeOldify_colab.ipynb. This was contributed by Matt Robinson, and it's simply awesome.

Hardware and Operating System Requirements

  • (Training Only) BEEFY Graphics card. I'd really like to have more memory than the 11 GB in my GeForce 1080TI (11GB). You'll have a tough time with less. The Unet and Critic are ridiculously large but honestly I just kept getting better results the bigger I made them.
  • (Colorization Alone) A decent graphics card. You'll benefit from having more memory in a graphics card in terms of the quality of the output achievable by. Now what the term "decent" means exactly...I'm going to say 6GB +. I haven't tried it but in my head the math works....
  • Linux (or maybe Windows 10) I'm using Ubuntu 16.04, but nothing about this precludes Windows 10 support as far as I know. I just haven't tested it and am not going to make it a priority for now.

Easy Install

You should now be able to do a simple install with Anaconda. Here are the steps:

Open the command line and navigate to the root folder you wish to install. Then type the following commands

git clone https://github.com/jantic/DeOldify.git DeOldify
cd DeOldify
conda env create -f environment.yml

Then start running with these commands:

source activate deoldify
jupyter lab

From there you can start running the notebooks in Jupyter Lab, via the url they provide you in the console.

Disclaimer: This conda install process is new- I did test it locally but the classic developer's excuse is "well it works on my machine!" I'm keeping that in mind- there's a good chance it doesn't necessarily work on others's machines! I probably, most definitely did something wrong here. Definitely, in fact. Please let me know via opening an issue. Pobody's nerfect.

More Details for Those So Inclined

This project is built around the wonderful Fast.AI library. Unfortunately, it's the -old- version and I have yet to upgrade it to the new version. (That's definitely [update 11/18/2018: maybe] on the agenda.) So prereqs, in summary:

  • Old Fast.AI library (version 0.7) [UPDATE 11/18/2018] A forked version is now bundled with the project, for ease of deployment and independence from whatever happens to the old version from here on out.
  • Python 3.6
  • Pytorch 0.4.1 (needs spectral_norm, so latest stable release is needed). https://pytorch.org/get-started/locally/
  • Jupyter Lab conda install -c conda-forge jupyterlab
  • Tensorboard (i.e. install Tensorflow) and TensorboardX (https://github.com/lanpa/tensorboardX). I guess you don't have to but man, life is so much better with it. And I've conveniently provided hooks/callbacks to automatically write all kinds of stuff to tensorboard for you already! The notebooks have examples of these being instantiated (or commented out since I didn't really need the ones doing histograms of the model weights). Notably, progress images will be written to Tensorboard every 200 iterations by default, so you get a constant and convenient look at what the model is doing. conda install -c anaconda tensorflow-gpu
  • ImageNet – Only if training of course. It proved to be a great dataset. http://www.image-net.org/download-images

Pretrained Weights

To start right away with your own images without training the model

View on GitHub
GitHub Stars9
CategoryDevelopment
Updated1y ago
Forks4

Languages

Python

Security Score

65/100

Audited on Apr 14, 2024

No findings