LoginSignup
0
1

More than 5 years have passed since last update.

Keras+Tensorflow で猫の毛色分類(サビ猫は雑誌の表紙を飾ったのか?)4

Last updated at Posted at 2018-09-04

もくじ

  1. 学習用画像を集める
  2. 猫のご尊顔を検出
  3. 学習
  4. 猫雑誌の表紙画像を集めて判定(ココ)

いったれ!

  1. 学習用画像を集める
  2. 猫のご尊顔を検出

に従って、猫雑誌の表紙画像を集めて、顔を検出した。
まず表紙
スクリーンショット 2018-09-03 15.16.58.jpg

そして、こう
スクリーンショット 2018-09-03 15.18.51.jpg

「3」で作ったベストモデルを使って判定。
シェルのfor文で、ご尊顏ファイルを引数に与えて使うスクリプト。
元データのディレクトリ構成からカテゴリ名を取ってて、ディレクトリ名をベタ書き...(catimages)

test.py
import training as train  #import 3.'s training.py
import sys, os
from PIL import Image
import numpy as np

if len(sys.argv) <= 1:
  quit()

image_size = 160
source_dir = "catimages"
categories = [name for name in os.listdir(source_dir) if name != ".DS_Store"]

X = []
for file_name in sys.argv[1:]:
  img = Image.open(file_name)
  img = img.convert("RGB")
  img = img.resize((image_size, image_size))
  in_data = np.asarray(img)
  X.append(in_data)
X = np.array(X)
model = train.train(X.shape[1:])
model.load_weights("./snapshot/cat-bestmodel.hdf5")
predict = model.predict(X)

for i, pre in enumerate(predict):
  y = pre.argmax()
  print(sys.argv[i+1], categories[y])

国内雑誌の猫顔、385枚、海外雑誌の猫顔、313枚、
サビ猫(tortie)と判断されたのは・・・

それぞれ一枚づつ

jpt.jpg
Clipboard.jpg

誤判定... orz  (まぁ、ざっと見てもサビ猫表紙の雑誌はありませんでした...)
  皆もっとサビ猫を愛そう

おしまいニャー

おまけ 

日本雑誌
jp2.png

海外雑誌(ビビッドな文字色が多いためか、calico は誤判定が多かったです...)
us2.png

0
1
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
0
1