bonlime/keras-deeplab-v3-plus のインストールと動作確認(セマンティック・セグメンテーション)(Deeplab v3+,Python を使用)(Windows 上)
bonlime/keras-deeplab-v3-plus のインストールと動作確認を行う.
【目次】
bonlime/keras-deeplab-v3-plus を使うために,Python バージョン3.9 を推奨する.
前準備
Python 3.9, Git のインストール(Windows 上)
Pythonは,プログラミング言語の1つ. Gitは,分散型のバージョン管理システム.
【手順】
- Windows で,コマンドプロンプトを管理者権限で起動する(例:Windowsキーを押し,「cmd」と入力し,「管理者として実行」を選択)
次のコマンドを実行
次のコマンドは,Python ランチャーとPython 3.9とGitをインストールし,Gitにパスを通すものである.
次のコマンドでインストールされるGitは 「git for Windows」と呼ばれるものであり, Git,MinGW などから構成されている.
winget install --scope machine Python.Launcher winget install --scope machine Python.Python.3.9 winget install --scope machine Git.Git powershell -command "$oldpath = [System.Environment]::GetEnvironmentVariable(\"Path\", \"Machine\"); $oldpath += \";c:\Program Files\Git\cmd\"; [System.Environment]::SetEnvironmentVariable(\"Path\", $oldpath, \"Machine\")"
【関連する外部ページ】
- Python の公式ページ: https://www.python.org/
- Git の公式ページ: https://git-scm.com/
【サイト内の関連ページ】
【関連項目】 Python, Git バージョン管理システム, Git の利用
bonlime/keras-deeplab-v3-plus の実行(Windows 上)
GitHub の bonlime/keras-deeplab-v3-plus の Web ページ: https://github.com/bonlime/keras-deeplab-v3-plus
- インストール
cd /d c:%HOMEPATH% rmdir /s /q keras-deeplab-v3-plus git clone --recursive https://github.com/bonlime/keras-deeplab-v3-plus cd keras-deeplab-v3-plus type requirements.txt python -m pip install -U keras==2.2.4 tensorflow==2.5.0 pillow numpy matplotlib tqdm opencv-python
- モデルのダウンロードとロード
python extract_weights.py python load_weights.py
- Python プログラムの実行
Python プログラムの実行
- Windows では python (Python ランチャーは py)
- Ubuntu では python3
Python 開発環境(Jupyter Qt Console, Jupyter ノートブック (Jupyter Notebook), Jupyter Lab, Nteract, Spyder, PyCharm, PyScripterなど)も便利である.
Python のまとめ: 別ページ »にまとめ
https://github.com/bonlime/keras-deeplab-v3-plus に記載のプログラムを使用
from matplotlib import pyplot as plt import cv2 # used for resize. if you dont have it, use anything else import numpy as np from model import DeepLabv3 deeplab_model = DeepLabv3() img = plt.imread("imgs/image1.jpg") w, h, _ = img.shape ratio = 512. / np.max([w,h]) resized = cv2.resize(img,(int(ratio*h),int(ratio*w))) resized = resized / 127.5 - 1. pad_x = int(512 - resized.shape[0]) resized2 = np.pad(resized,((0,pad_x),(0,0),(0,0)),mode='constant') res = deeplab_model.predict(np.expand_dims(resized2,0)) labels = np.argmax(res.squeeze(),-1) plt.imshow(labels[:-pad_x])