Using Neural Networks to De-censor Anime Girls
A Guide to Implementing a Convolutional Neural Network for image prediction
Note: This AI is literally just a linear regression, but on stereoids.
For this post, we’ll be using a library called DeepCreamPy (DCP), to de-censor some anime girls. After reading this post, you too will learn how to become a man of culture. @Deeppomf was the original creator of DCP. As of right now there are several forks of it on GitHub. We’ll be using the fork made by gguilt.
Credit goes to @BowTiedCoffee for helping me grasp Photoshop’s Content Filler. Credit also goes to @hal_jpeg, for helping making my code a lot more readable. Also, thanks to @BowTiedNightOwl for letting me use his avatar.
Table of Contents:
Setting up DCP
Running DCP
Analysis of the Neural Network
History of DCP
1 - Setting Up DCP
1.1 Installing Dependendencies
DCP runs on Python 3.7. The code for this neural network is super outdated. You need to make sure you grab Python 3.7, and it has to be 64 bit compatible. It has the following dependencies, so go ahead and grab the libraries below. If you don’t know how to add libraries to your code, go here.
absl-py==0.7.1
astor==0.8.0
gast==0.2.2
google-pasta==0.1.7
grpcio==1.22.0
h5py==2.9.0
Keras-Applications==1.0.8
Keras-Preprocessing==1.1.0
Markdown==3.1.1
numpy==1.17.0
opencv-python==4.1.0.25
Pillow==6.2.2
protobuf==3.9.1
PySide2==5.13.0
scipy==1.3.0
shiboken2==5.13.0
six==1.12.0
tensorboard==1.14.0
tensorflow-estimator==1.14.0
tensorflow==1.14.0
termcolor==1.1.0
Werkzeug==0.15.5
wrapt==1.11.2
1.2 Downloading the Model Weights
For the AI to run , it will need to look at several pictures of anime girls (censored & de-censored). Then, it will need to study these pictures to see what’s the common underlying pattern in all them. , we don’t have all day, so we will download the finalized model. Link to the finalized model is here.
1.3 Download & Setup DCP
One thing you’ll notice very is if you tried to look for DCP in Pycharm, it doesn’t exist. What we will have to do is download the repository, and then install it. Instructions Below:
1 - Download the The DeepCreamPy Code as a zip.
2 - Extract the contents of the above zip file to wherever you want your code to run from
3- Now, Download the Model weights file, and extract this to your /models folder.
Congrats, you are now ready to run this algorithm. Just grab a picture, then censor it in pure green (0,255,0)
2 - Running DCP
For this example, I’ll censor @BowTiedNightOwl. His avatar has a lot of curves. You also need to ensure that your picture is in a .png format.
2.1 Censoring it manually
After this, just throw in some censor bars onto your picture.
I am on Windows, so paint can do a good enough job at this.
2.2 Putting it In the right folder
Now go ahead, and save the above picture into the folder called decensor_input.
2.3 Running the Algorithm
Now, run the Python file called decensor.py, and enjoy the output.
3 - Analysis of the Neural Network
3.1 How This Algorithm worked
This algorithm works off of a model called a Convolutional Neural Network (CNN). These neural networks make a simple square from the top left of the image. Then, that square moves row by row, until it reaches the bottom right side of the image.
In this specific case, the neural network was asked to find the green censor bars. Once it did that, then it had to predict what was behind the green censored bar. Yes, this AI is a super complex linear regression.
You can see a simple diagram of this up above. This is how most image detection AIs also work.
3.2 DCP vs Photoshop
Photoshop has an option called Content Filler, and I wanted to compare the two side by side:
The Neural Net was smart enough to figure out how to draw the red nose. Photoshop completely flopped that.
They look almost identical here.
Obligatory Anime Girl
Here, you can see the AI shine. It studied a huge amount of anime girls. Needless to say it would do a better job than photoshop. Big difference is in the eye. Both the AI & Photoshop fumbled the ball there. The AI completely flopped the missing eye, and photoshop did a horrible blend.
Summary:
In the above images, it seems that the neural network is aggressive in it's predictions. When you look at the NightOwl’s red nose, the neural net nailed the missing nose. The neural network is aggressive in that it tries to predict what the lines should look like. But, photoshop tends to try to use the surrounding colors for a soft simple blend.
4 - History of DeepCreamPy (DCP)
4.1 What Happened to the original Creator?
The original creator of DCP is a guy who had the alias of deeppomf. Unfortunately, he lost his laptop, and deleted everything to protect his privacy.
4.2 Where did the @Deeppomf get his training data?
Deeppomf went to a website called Danbooru to grab a huge amount of data of anime pics. Link to Danbooru here. Here’s a quick sample of the data:
Also suggest try a new state of the art based in-painting with hot stable diffusion model https://twitter.com/victormustar/status/1583013197313105920
Maybe for another post comparing both?
Proof that data science has positive impact on the world