LoginSignup
7
7

More than 3 years have passed since last update.

ディープラーニングを用いて、乃木坂46 メンバーからアニメキャラクター変更

Posted at

背景

CycleGANはあるスタイルの画像から他のスタイルに変更できます。

区別

CycleGANは非ペアのデータセットが必要。

データセット

image.pngアニメ写真7000枚
image.pngアイドル写真7000枚

データセットの収集には、クローラプラスopencvターゲット検出アルゴリズムを使用して、画像を切り取ります。

code

opencvターゲット検出アルゴリズム


import cv2
import sys
import os.path
from glob import glob

def detect(filename, cascade_file="haarcascade_frontalface_alt.xml"):
    if not os.path.isfile(cascade_file):
        raise RuntimeError("%s: not found" % cascade_file)

    cascade = cv2.CascadeClassifier(cascade_file)
    image = cv2.imread(filename)
    if image==None: # read failure and skip this image
      return
    if image.shape[2]==1: # drop gray images
      return
    gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
    gray = cv2.equalizeHist(gray)

    faces = cascade.detectMultiScale(gray,
                                     # detector options
                                     scaleFactor=1.1,
                                     minNeighbors=3,
                                     minSize=(96, 96))
    for i, (x, y, w, h) in enumerate(faces):
        face = image[y: y + h, x:x + w, :]
        face = cv2.resize(face, (96, 96))
        save_filename = '%s-%d.jpg' % (os.path.basename(filename).split('.')[0], i)
        cv2.imwrite("face/" + save_filename, face)


if __name__ == '__main__':
    if os.path.exists('face') is False:
        os.makedirs('face')
    file_list = glob('./test/ikoma/*.jp*')
    for filename in file_list:
        print filename
        detect(filename)

結果

100epoch訓練しました。
input
6_real_A.png3586_real_A.png4179_real_A.png4775_real_A.png6993_real_A.png8853_real_A.png

 output
6_fake_B.png3586_fake_B.png4179_fake_B.png4775_fake_B.png6993_fake_B.png8853_fake_B.png

        

まとめ

悪くないと思う。

7
7
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
7