Tensorflow.jsの画像認識って

2024.03.11

Logging

おはようございます、Tensorflow.jsの画像認識ってドキュメント通り書いて上手く画像認識できますか?自分が試してみたら、どうも下記のエラーがでて上手く動作してくれなかったのでもしかしたらと思いバージョンをアップしたら動作してくれました。

Uncaught (in promise) Error: Tensorflow Op is not supported: _FusedConv2D
<!-- Load TensorFlow.js. This is required to use MobileNet. -->
<script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs@4.17.0"> </script>
<!-- Load the MobileNet model. -->
<script src="https://cdn.jsdelivr.net/npm/@tensorflow-models/mobilenet@2.1.1"> </script>

<!-- Replace this with your image. Make sure CORS settings allow reading the image! -->
<img id="img" src="cat.jpg"></img>

<!-- Place your code in the script tag below. You can also use an external .js file -->
<script>
  // Notice there is no 'import' statement. 'mobilenet' and 'tf' is
  // available on the index-page because of the script tag above.

  const img = document.getElementById('img');

  // Load the model.
  mobilenet.load().then(model => {
    // Classify the image.
    model.classify(img).then(predictions => {
      console.log('Predictions: ');
      console.log(predictions);
    });
  });
</script>

因みに自分は画像投稿系のサイトで使用するために今回のTensorflow.jsを使用するのですが、よくよく調べているとファインチューニングが出来るようです。ファインチューニングとは一度学習したものに再学習を埋め込む手法といえば良いのかな?要するにカスタマイズしてある分類に特化させる手法のことを指します。今のところ学習済みのモデルで全然判定されるのでOKだと思うのですが、ユーザーさんから認識できないという不満の声が上がれば対応しないといけなくなりそうです。

明日へ続く。

タグ

'src', below, const img, Error, getElementById, gt, img, img&quot, Load TensorFlow.js, lt, MobileNet, mobilenet.load, model, predictions, quot, statement, then, Uncaught, ファインチューニング,

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

2022.08.07

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, フレームワーク, 力量, 絵の具, 花形,

Twitterプロフィールからスパムみたいなアカウントかを機械学習で判定してみた。

2021.06.28

Logging

Twitterプロフィールからスパムみたいなアカウントかを機械学習で判定してみました。

機械学習にしてもらう①。

何故、このような事を考えたかはスパムみたいなアカウントってぱっと見で人は区別できるよねって思ったのでLobeというソフトを使って画像解析(機械学習)してモデルをエクスポートし、そのモデルをテンソルフローで使用して動作確認してみました。

機械学習にしてもらう②

結果は、まぁまぁの精度だったのでモデルをお裾分けしますね。因みにTwitterのプロフィール画像のスクリーンショットを行った時のソースコードも提供します。

尚、機械学習に使用したプロフィール画像は400枚ほど(少ない?)です、ok-image(一般人)とng-image(スパムみたいなアカウント)というラベルを付けて学習させてます。

model::https://zip358.com/ai-model/tw-profile/saved_model.pb (?モデルの中身はtensorboardでご確認を!)

zip358com
zip358
# Generated by Selenium IDE
import time
from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager

from selenium.webdriver.common.by import By
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.support import expected_conditions
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from selenium.webdriver.support.ui import Select

class twss():
	def setup_method(self):
		self.driver = webdriver.Chrome(ChromeDriverManager().install())
		self.vars = {}

	def teardown_method(self):
		self.driver.quit()

	def screenshots(self):
		self.driver.get("https://twitter.com/")
		self.driver.set_window_size(945, 900)
		with open('twname.dat','r',encoding="utf-8") as f:
			for line in f:
				FILENAME = "X:\\var\\www\\html\\labo_ai\\twss\\image\\screen_" + line.replace('\n', '') +".png"
				self.driver.get("https://twitter.com/" + line.replace('\n', ''))
				time.sleep(2)
				self.driver.save_screenshot(FILENAME)
		f.close()
		self.driver.quit()
twss = twss()
twss.setup_method()
twss.screenshots()

タグ

358, 400, ai-model, com, https, lobe, model, ng-image, ok-image, SA, tw-profile, Twitter, zip, アカウント, エクスポート, お裾分け, コード, ショット, スクリーン, スパム, ソース, ソフト, テンソル, フロー, プロフィール, モデル, ラベル, 一般人, , , 何故, 使用, 判定, 動作, 区別, 学習, 提供, , 機械, 画像, 確認, 精度, 結果, 解析,

Pythonコード:demo

2019.11.05

Logging

#!/usr/local/bin/python3
# coding:utf-8
import os
import sys
import MeCab
import gensim
import markovify
import unicodedata
model = gensim.models.KeyedVectors.load_word2vec_format('/var/www/html/model.vec', binary=False)
f = open('merosu.txt')
tagger = MeCab.Tagger("-Owakati")
tagger.parse('')
text0 = tagger.parse(f.read())
text1 = text0
text0 = text0.replace('\n','')
text0 = text0.replace('\r','')
text1x = text0.split(" ")
text2 = []
try:
    for item in text1x:
        if item.strip():
            results  = model.most_similar(positive=[item],topn=2)
            #"print(results)
            for val1 in results:
                text2.append(val1[0] + "\n")
#
    # print (text1)
    # print (" ".join(text2))
    model_a = markovify.Text(text1 + "\n")
    print(str(model_a.make_sentence()).replace(' ',''))
    model_b = markovify.Text(" ".join(text2))
    print(str(model_b.make_sentence()).replace(' ',''))
    model_combo = markovify.combine([model_a, model_b], [1, 1])
    print(str(model_combo.make_sentence()).replace(' ',''))
except Exception as e:
    print("動作エラー", e.args)
    pass

タグ

-Owakati, 'merosu, 0, , 2, , 39, 8, bin, binary, coding, demo, false, format, gensim, html, import, KeyedVectors, load, local, markovify, Mecab, model, models, open, OS, parse, Python, quot, read, replace, sys, tagger, Text, txt, unicodedata, usr, UTF-, var, Vec, Word, コード,

部屋の温度と湿度をリアルタイムでうぅううします。

2018.09.01

Logging

https://zip358.com/tool/kion_shitudo/
IOTとかいう奴ですね、Raspberry Piを使用して部屋の温度と湿度を
90秒置きに表示するようなものを作りました。
あぁぁエアコンとか平日はつける事はないので
部屋の温度はこの時期、汗だくです・・・。
ふふふうふ?。
ちなみに温度センサーのプラスとマイナスをRaspberry Piに反対接続して
なんか温度センサーが熱い状態になってましたが
何とか問題なくいまは動いてます・・・・。
あとはPHPとPythonでそれぞれプログラムコードを書いて
ゴニョゴニョしてサーバ側に表記しています。
 

タグ

-Physi, 01, , 4, 90, asin, Clear, com, CSFZ, Decker, IoT, JG, jp, kion, model, php, Pi, ple, Python, Raspberry, shitudo, tool, zip358, あと, いま, エアコン, ケース, コード, ゴニョゴニョ, サーバ, セット, センサー, それぞれ, ふうふ, プラス, プログラム, ポート, マイナス, もの, リアルタイム, , 使用, 反対, , 対応, 平日, 接続, 時期, 温度, 湿度, 状態, 表示, 表記, 部屋,