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

# 背景
CycleGANはあるスタイルの画像から他のスタイルに変更できます。
# 区別
CycleGANは非ペアのデータセットが必要。
# データセット
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/550605/358e8c4f-c988-389e-93db-e31926deee81.png)**アニメ写真7000枚**
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/550605/69fb7618-eeb1-8172-9f1e-6d552a3fbc23.png)**アイドル写真7000枚**

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


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

```python

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.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/550605/eff50d9c-6fc2-c366-6a39-36021e10e5cf.png)![3586_real_A.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/550605/0875a4ce-d9a8-2234-defc-4559d0f5cd96.png)![4179_real_A.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/550605/4e091d69-3d75-41f6-7ae6-f19da2935afb.png)![4775_real_A.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/550605/1568fa89-b586-ee6e-1f60-abd161577617.png)![6993_real_A.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/550605/8a808f06-06e8-6791-3353-77d2dea0a14a.png)![8853_real_A.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/550605/d190c2d6-8188-7371-7354-b7b37b434da0.png)

**　output**
![6_fake_B.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/550605/4de4ed16-1c97-eb5f-5398-c8a91bef3a74.png)![3586_fake_B.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/550605/dab0bc2b-da1b-4dc0-3eb4-112d00022de0.png)![4179_fake_B.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/550605/39fe23ac-03de-7776-1f72-fd610c8977f5.png)![4775_fake_B.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/550605/2dca6755-f73b-74d3-60db-3343f97d7c58.png)![6993_fake_B.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/550605/1e2f8b35-e723-b123-823b-223bc3cf9696.png)![8853_fake_B.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/550605/4f1dbbef-8aa1-6813-211f-ce005b560f79.png)




  　　　　　　　　

# まとめ
悪くないと思う。