白黒動画カラー化(PyTorch編)
今回は白黒動画のカラー化をPyTorchでも出来ることを証明したいと思います。
動画はアップしません。ですが・・・
(作成途中のカラー化動画はアップします。)
今までのimage colorization と pyTorch(imageColorizerColab)の違いが分かれば幸いです。
(DeepLearningの更なる進化を心から願っています。)
警備員の私がここで発表するレベルのことが出来る訳ですから
本職の人は遥か先を行っているハズです。
誰もが知りたいですよね?
オードリー・ヘプバーン、ビビアン・リーやフランク・シナトラなどの過去の低解像度の白黒の作品を
4K、8Kのカラー動画として提供できるかも知れません。
すべては採算ベースですかねぇ?
余談)例えば画像を4倍に拡大しそれを4分割します。
1枚は低解像度の画像になってしまいます。
これを1枚づつ高解像度化し再び4枚を1枚に戻します。
(現段階で可能かどうかは別にして理屈は通っていると思います。)
注)あまり大きいサイズの画像だとカラー化が無理のようです。
私は「640 x 480」のサイズまで落としてカラー化を試みました。
あとは「render factor」(解像度でしょうか?)の変更です。
私は全て「45」にせっていしました。
今回はの連番の白黒画像を連番でカラー画像に変換するところのみお伝えいたします。
(splitted_monoフォルダの白黒画像をtest_imagesに変えれば良いだけです)
あとは、同じやり方で完成します。
左下の検索スペースに「cmd」と入力(コマンドプロンプトを立ち上げる)
================================================
git clone https://github.com/jantic/DeOldify.git DeOldify
と入力し「Enterを押す」
(ダウンロードできない時は直接上記のURLに飛んでZIPファイルをダウンロード
それを「yourname」下に解凍し
yourname以下の「Deoldifi か DeOldify-master」に移動する
「cd DeOldify または cd DeOldify-master」 + Ente
拡張子を ipynb から py に変更する
「jupyter nbconvert –to script *.ipynb」 + Enter
ipynbファイルを削除する
「del /s *.ipynb + Enter
modelsフォルダの作成
「mkdir ‘models’」 + Enter
ColorizerArtistic.phのダウンロード
wget https://data.deepai.org/deoldify/ColorizeArtistic_gen.pth -O ./models/ColorizeArtistic_gen.pth + Enter
必要なライブラリをインストールする
pip install -r requirements.txt +Enter
pip install torch==1.12.1+cu113 torchvision==0.13.1+cu113 torchaudio –extra-index-url https://download.pytorch.org/whl/cu113
ImageColorizer.pyの「source_path」を以下のように変更する
source_path = ‘test_images/*.png’
render factorを45に変更する
ImageColorizerColab.pyを以下のように書き換える
——————————————–
# coding: utf-8
#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)
from PIL import Image as PilImage
import torch
if not torch.cuda.is_available():
print(‘GPU not available.’)
import fastai
from deoldify.visualize import *
import warnings
warnings.filterwarnings(“ignore”, category=UserWarning, message=”.*?Your .*? set is empty.*?”)
get_ipython().system(‘wget https://media.githubusercontent.com/media/jantic/DeOldify/master/resource_images/watermark.png -O ./resource_images/watermark.png’)
colorizer = get_image_colorizer(artistic=True)
import glob
source_url = ” #@param {type:”string”}
render_factor = 45 #@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.’)
files = sorted(glob.glob(‘test_images’ + ‘/*.png’))
for i, file in enumerate (files):
image = cv2.imread(file, cv2.IMREAD_COLOR)
colorizer.plot_transformed_image(file, render_factor=45)
plt.close() # 追加
print(i+1)
———————————————————————
あとは、ImageColorizerColab.pyを実行するだけです。
「python ImageColorizerColab.py」 + Enter
白黒画像
カラー化画像
この記事へのコメントはありません。