結果
なかなかいい感じ。
きっかけ
学習させて保存するまで
tensorflowをローカルでうごごごごごご
TensorFlow は以下の 64 ビットシステムでテストおよびサポートされています。
Python 3.6~3.9
TensorFlow
Ubuntu 16.04 以降
Windows 7 以降(C++ 再頒布可能パッケージをインストール済み)
嫌な予感はしてたんスよ。うちのローカルpython3.10で動かねー!!!
Google Colabは3.7.12(2022/01/15時点)
3.7.12を入れよう・・・インストーラーがないよぅっぅぅぅ コンパイルする!? まじで!?
PythonWindows/3.7.12 at master · adang1345/PythonWindows · GitHub
怪しいところから落としましたw
pythonアンインストールして、↑のをインストールして
tensorflowを一旦全てアンインストールして・・・あーだこーだ悩みまくってなんとか動く環境にできました。Pillowも入れよう。
CUDA Toolkit 11.6 Downloads | NVIDIA Developerも入れたけどあんまり関係ないと思う(笑)
ソース
from asyncio.windows_events import NULL import tensorflow as tf from tensorflow.keras.preprocessing.image import img_to_array, load_img from tensorflow.keras.models import model_from_json import os import numpy as np import shutil # 次回モデル読み込み p = 'C:\\python\\' # モデルを読み込む model = model_from_json(open(p+'model.json').read()) # 学習結果を読み込む model.load_weights(p + 'weights.h5') # 読み込むもと # C:\Users\user\OneDrive\画像\カメラ ロール\2021\11 # C:\Users\user\OneDrive\画像\カメラ ロール\2021\12 # C:\Users\user\OneDrive\画像\カメラ ロール\2022\1 # 移す先 # C:\Users\user\OneDrive\画像\スクリーンショット\ピクミン validation_dir = 'C:\\Users\\user\\OneDrive\\画像\\カメラ ロール\\2021\\' for i in range(11, 13): # validation_dir = 'C:\\Users\\user\\OneDrive\\画像\\カメラ ロール\\2022\\' # for i in range(1, 2): files = os.listdir(validation_dir + format(i, '0>2')) dpath = os.path.join(validation_dir, format(i, '0>2')) for f in files: if os.path.isdir(dpath+'\\'+f): continue if os.path.splitext(f)[1] != '.PNG' and os.path.splitext(f)[1] != '.png': continue img_path = os.path.join(dpath, f) img = img_to_array(load_img(img_path, target_size=(150, 150))) img_nad = img_to_array(img)/255 img_nad = img_nad[None, ...] label = ['pic', 'etc'] pred = model.predict(img_nad, batch_size=1, verbose=0) score = np.max(pred) pred_label = label[np.argmax(pred[0])]#これでpicかetcになると思ったら違った if score > 0.8: os.rename( img_path, "C:\\Users\\user\\OneDrive\\画像\\スクリーンショット\\ピクミン\\" + f)
参考
Tensorflow/Kerasのインストール方法(Windows、Mac編) | 西住工房
Pythonでコンパイルは可能なのか?やり方をまとめてみた | CodeCampus
【完全版】TensorFlowのインストール方法〜コマンド1発 - DeepAge
compileall --- Python ライブラリをバイトコンパイル — Python 3.10.0b2 ドキュメント
【Windows10】tgzファイルを解凍する方法 |Lhaplus (ラプラス) | EGUWEB(エグウェブ)
PythonWindows/3.7.12 at master · adang1345/PythonWindows · GitHub
can't import tensorflow.keras properly · Issue #26813 · tensorflow/tensorflow · GitHub
Keras のモデルと学習結果を保存して利用する - #m0t0k1ch1st0ry
Pythonでパス文字列からファイル名・フォルダ名・拡張子を取得、結合 | note.nkmk.me
自前の保存したモデルを用いて画像を分類してみる。 - Qiita
macOS で「this TensorFlow binary was not compiled to use: AVX2 FMA」エラー - Qiita
Tensowflow "Could not load dynamic libary 'cudart64_110.dll'; dlerror: cudart64_110.dll not found - Qiita
KERASで学習済みのモデルをロードして画像1枚を判別 - Qiita
pipコマンド - Qiita
Kerasに「PILが無い」と怒られた場合の対策 - Qiita
Kerasで「ImportError: Could not import PIL.Image. The use of `array_to_img` requires PIL.」とPILのエラーが出る - 機械音痴な情報系
How to install python on Windows without an MSI installer? - Stack Overflow
Tensorflowインストール時に" Could not find a version..."というエラーが出た時の対処法 - WICの中から
Tensorflowインストール時に" Could not find a version..."というエラーが出た時の対処法 - WICの中から
Python3.9 を 3.8 にダウングレードする | Delft スタック
Python | 数値を文字列に変換して文字列と連結する
Python 3.6.8(旧バージョン)のインストール(Windows 上)
Python 3.7 のインストール(Windows 上)
【Python】WindowsでPythonインストールしてもバージョンが出ない… Output48
Python Release Python 3.7.12 | Python.org
【Python if文の応用編】or・and・not演算子の使い方を理解しよう | 侍エンジニアブログ
【python入門】os.path.join()を活用してパス結合をしてみよう! | 侍エンジニアブログ
【2021年最新版】【Windows】Python3.10+TensorFlow2.6-GPU+CUDA11.4+cuDNN8.2を動かす【3】
pip での TensorFlow のインストール
TensorFlow
Image classification | TensorFlow Core