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

背景

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

        

まとめ

悪くないと思う。

Why do not you register as a user and use Qiita more conveniently?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account