TensorFlow(テンソルフロー)で画像分類させたら車も人の顔って😇

20220807

Logging

こんにちは、今日もまだ呟くこともしないで日が暮れるかもです。

今日は機械学習で画像分類させることを昨日からゴニョゴニョとしていて、やっとこさ自作のモデルから判定することが出来たのですが、あまり精度が良くないので正直な所、残念です。もっと精度の良いものを作れれば良いのになって思いますが、今の力量ではココらへんですね。

因みにココから画像判別の精度を上げるためにはコードをある程度、作り込まないといけないです。あとはデータ量ももう少し多くのデータが必要です。今回作っていてPythonもなかなか面白いなってね感じました。そして結構、書きやすいなとも思ったのですが、まだまだゴリゴリとコードをPythonで書けるわけではないので、もっと勉強しないとなって事です。

Python言語は結構人気だし、機械学習は花形なんですよ。そういう言語を自在に使えるようになりたいなって思います、そしてPHPやJSなどやフレームワークもゴニョゴニョと絵の具のように思い通り使いたいなって未だに思います。知れば知るほど未だまだ勉強で、おそらくコード書きは引退しても学び続けるだろうなって思います。

import numpy as np
import tensorflow as tf
import tensorflow_hub as hub
import PIL.Image
tf.get_logger().setLevel("ERROR")
def preprocess_image(image_path):
    image = PIL.Image.open(image_path).convert("RGB").resize((150,150))
    image = np.array(image) / 255
    image = np.expand_dims(image, 0)

    return image

def test_model(imgurl):
    image_path = imgurl
    model_file_name='human_or.h5'
    labels = ["human","dogs"]
    model = tf.keras.models.load_model(model_file_name, custom_objects={"KerasLayer": hub.KerasLayer})
    predictions = model.predict(preprocess_image(image_path))
    print("検証 %s 人の顔である確率 %3d%%" %(image_path,int(predictions[0][0]*100)) )

test_model("ai_image_test\\test1.jpg")
test_model("ai_image_test\\test2.jpg")
test_model("ai_image_test\\test3.jpg")
test_model("ai_image_test\\test4.jpg")
test_model("ai_image_test\\test5.jpg")
test_model("ai_image_test\\test6.jpg")

https://taoka-toshiaki.com/ML/human_or.zip ←モデル

タグ

array, convert, custom_objects, expand_dims, get_logger, hub.KerasLayer, image, imgurl, int, labels, model, predictions, print, quot, resize, setLevel, フレームワーク, 力量, 絵の具, 花形,