Tensorflowで人の顔を見分ける(2)
目的
Tensorflowで人の顔を分類したい!
参考リンク
TensorFlowでアニメゆるゆりの制作会社を識別する - kivantium活動日記
動作環境
Python3.5.3 (過去ログご参考)
やりかた
全体の流れ
1.それぞれの人の顔の画像を複数集める
2.画像から人の顔だけを切出す
3.切出した顔をチェックして不要なものを削除
4.学習用データと検証用データに分ける
5.学習する
6.学習結果をみる
7.見分ける
この投稿では4項
4.学習用データと検証用データに分ける
※ランダムにデータを学習用(7割)と検証用(3割)に分ける
※学習用データは train.txt へ
※検証用データは test.txt へ
※各行に、画像データの相対パス、スペース、分類結果を持つ
※分類結果は0から番号付け(0なら1人目、1なら2人目)
1)Pythonで以下を実行
# -*- coding: utf-8 -*
import sys
import os
import random
wari = 0.7
train = open('train.txt', 'w')
test = open('test.txt', 'w')
files = os.listdir('1人目の画像フォルダ')
for file in files:
imgfile = '1人目の画像フォルダ' + file
f = random.random()
if f > wari:
test.write(imgfile)
test.write(" 0\n")
else:
train.write(imgfile)
train.write(" 0\n")
files = os.listdir('2人目の画像フォルダ')
for file in files:
imgfile = '2人目の画像フォルダ' + file
f = random.random()
if f > wari:
test.write(imgfile)
test.write(" 1\n")
else:
train.write(imgfile)
train.write(" 1\n")
train.close()
test.close()
Good Luck !!!