Skip to content
Snippets Groups Projects
Commit 9fdf41a6 authored by Niels Becker's avatar Niels Becker
Browse files

DeOldify Bild kolorierung

parent d4b95807
No related branches found
No related tags found
1 merge request!1Update Neural Style Transfer.py
%% Cell type:markdown id: tags:
# Coding Davinchi 2021
---
This Code is originally from the DeOldify Team.
It can be entert on the github page. https://github.com/jantic/DeOldify
A Colab version is available at https://colab.research.google.com/github/jantic/DeOldify/blob/master/ImageColorizerColab.ipynb#scrollTo=EIDwTjLOegiS
%% Cell type:markdown id: tags:
### **<font color='blue'> Artistic Colorizer </font>**
%% Cell type:markdown id: tags:
#◢ DeOldify - Colorize your own photos!
####**Credits:**
Special thanks to:
Matt Robinson and María Benavente for pioneering the DeOldify image colab notebook.
Dana Kelley for doing things, breaking stuff & having an opinion on everything.
%% Cell type:markdown id: tags:
---
#◢ Verify Correct Runtime Settings
**<font color='#FF000'> IMPORTANT </font>**
In the "Runtime" menu for the notebook window, select "Change runtime type." Ensure that the following are selected:
* Runtime Type = Python 3
* Hardware Accelerator = GPU
%% Cell type:markdown id: tags:
#◢ Git clone and install DeOldify
%% Cell type:code id: tags:
``` python
!git clone https://github.com/jantic/DeOldify.git DeOldify
```
%% Cell type:code id: tags:
``` python
cd DeOldify
```
%% Cell type:markdown id: tags:
#◢ Setup
%% Cell type:code id: tags:
``` python
#NOTE: This must be the first call in order to work properly!
from deoldify import device
from deoldify.device_id import DeviceId
#choices: CPU, GPU0...GPU7
device.set(device=DeviceId.GPU0)
import torch
if not torch.cuda.is_available():
print('GPU not available.')
```
%% Cell type:code id: tags:
``` python
!pip install -r colab_requirements.txt
```
%% Cell type:code id: tags:
``` python
import fastai
from deoldify.visualize import *
import warnings
warnings.filterwarnings("ignore", category=UserWarning, message=".*?Your .*? set is empty.*?")
```
%% Cell type:code id: tags:
``` python
!mkdir 'models'
!wget https://data.deepai.org/deoldify/ColorizeArtistic_gen.pth -O ./models/ColorizeArtistic_gen.pth
```
%% Cell type:code id: tags:
``` python
!wget https://media.githubusercontent.com/media/jantic/DeOldify/master/resource_images/watermark.png -O ./resource_images/watermark.png
```
%% Cell type:code id: tags:
``` python
colorizer = get_image_colorizer(artistic=True)
```
%% Cell type:markdown id: tags:
#◢ Instructions
%% Cell type:markdown id: tags:
### source_url
Type in a url to a direct link of an image. Usually that means they'll end in .png, .jpg, etc. NOTE: If you want to use your own image, upload it first to a site like Imgur.
### render_factor
The default value of 35 has been carefully chosen and should work -ok- for most scenarios (but probably won't be the -best-). This determines resolution at which the color portion of the image is rendered. Lower resolution will render faster, and colors also tend to look more vibrant. Older and lower quality images in particular will generally benefit by lowering the render factor. Higher render factors are often better for higher quality images, but the colors may get slightly washed out.
### watermarked
Selected by default, this places a watermark icon of a palette at the bottom left corner of the image. This is intended to be a standard way to convey to others viewing the image that it is colorized by AI. We want to help promote this as a standard, especially as the technology continues to improve and the distinction between real and fake becomes harder to discern. This palette watermark practice was initiated and lead by the company MyHeritage in the MyHeritage In Color feature (which uses a newer version of DeOldify than what you're using here).
#### How to Download a Copy
Simply right click on the displayed image and click "Save image as..."!
## Pro Tips
You can evaluate how well the image is rendered at each render_factor by using the code at the bottom (that cell under "See how well render_factor values perform on a frame here").
%% Cell type:markdown id: tags:
#◢ Colorize!!
%% Cell type:code id: tags:
``` python
source_url = '' #@param {type:"string"}
render_factor = 35 #@param {type: "slider", min: 7, max: 40}
watermarked = True #@param {type:"boolean"}
if source_url is not None and source_url !='':
image_path = colorizer.plot_transformed_image_from_url(url=source_url, render_factor=render_factor, compare=True, watermarked=watermarked)
show_image_in_notebook(image_path)
else:
print('Provide an image url and try again.')
```
%% Cell type:markdown id: tags:
## See how well render_factor values perform on the image here
%% Cell type:code id: tags:
``` python
for i in range(10,40,2):
colorizer.plot_transformed_image('test_images/image.png', render_factor=i, display_render_factor=True, figsize=(8,8))
```
%% Cell type:markdown id: tags:
---
#⚙ Recommended image sources
* [/r/TheWayWeWere](https://www.reddit.com/r/TheWayWeWere/)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment