bonlime/keras-deeplab-v3-plus のインストールと動作確認を行う.
【目次】
【サイト内の関連ページ】
Windows での Git のインストール: 別ページ »で説明
【関連する外部ページ】
Git の公式ページ: https://git-scm.com/
【サイト内の関連ページ】
【関連する外部ページ】
Python の公式ページ: https://www.python.org/
Windows での TensorFlow,Keras のインストール: 別ページ »で説明
(このページで,Build Tools for Visual Studio 2022,NVIDIA ドライバ, NVIDIA CUDA ツールキット, NVIDIA cuDNNのインストールも説明している.)
コマンドプロンプトを管理者として実行: 別ページ »で説明
python -m pip install -U opencv-python opencv-contrib-python
※ mtcnn については https://github.com/open-face/mtcnn
mkdir c:\pytools cd c:\pytools rmdir /s /q imutils rmdir /s /q mtcnn
この .zip ファイルは,D:\keras-deeplab-v3-plus-master\keras-deeplab-v3-plus-master に展開(解凍)したものとして,説明を続けるので,適切に読み替えてください.
cd D:\keras-deeplab-v3-plus-master\keras-deeplab-v3-plus-master
run -i extract_weights.py run -i load_weights.py
https://github.com/bonlime/keras-deeplab-v3-plus に記載のプログラムを使用
Python プログラムを実行する
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])