金子邦彦研究室人工知能Windows でのインストールと動作確認(人工知能関係)bonlime/keras-deeplab-v3-plus のインストールと動作確認(セマンティック・セグメンテーション)(Deeplab v3+,Python を使用)(Windows 上)

bonlime/keras-deeplab-v3-plus のインストールと動作確認(セマンティック・セグメンテーション)(Deeplab v3+,Python を使用)(Windows 上)

bonlime/keras-deeplab-v3-plus のインストールと動作確認を行う.

目次

  1. 前準備
  2. Windows で bonlime/keras-deeplab-v3-plus を使ってみる

前準備

Git のインストール(Windows 上)

サイト内の関連ページ

Windows での Git のインストール: 別ページ »で説明

関連する外部ページ

Git の公式ページ: https://git-scm.com/

Python のインストール(Windows 上)

サイト内の関連ページ

関連する外部ページ

Python の公式ページ: https://www.python.org/

TensorFlow のインストール

Windows での TensorFlowKeras のインストール: 別ページ »で説明

(このページで,Build Tools for Visual Studio 2022,NVIDIA ドライバ, NVIDIA CUDA ツールキットNVIDIA cuDNNのインストールも説明している.)

OpenCV, 各種パッケージのインストール

  1. Windows で,コマンドプロンプト管理者として実行

    コマンドプロンプトを管理者として実行: 別ページ »で説明

  2. python の OpenCV のインストール

    python -m pip install -U opencv-python opencv-contrib-python
    
  3. imutils, mtcnn のインストール

    ※ mtcnn については https://github.com/open-face/mtcnn

    mkdir c:\pytools
    cd c:\pytools
    rmdir /s /q imutils
    rmdir /s /q mtcnn
    

    cd c:\pytools
    git clone https://github.com/jrosebr1/imutils
    cd imutils
    python setup.py build
    python setup.py install 
    
    cd c:\pytools
    git clone https://github.com/ipazc/mtcnn
    cd mtcnn
    python setup.py build
    python setup.py install 
    

tqdm のインストール

  1. Windows で,コマンドプロンプト管理者として実行

    コマンドプロンプトを管理者として実行: 別ページ »で説明

  2. tqdm のインストール
    pip install -U tqdm
    

Windows で bonlime/keras-deeplab-v3-plus を使ってみる

  1. GitHub の bonlime/keras-deeplab-v3-plus の Web ページを開く

    https://github.com/bonlime/keras-deeplab-v3-plus

  2. Clone or download」を展開し, 「Download ZIP」をクリック

    [image]
  3. .zip ファイルのダウンロードが始まるので確認する.

    [image]
  4. ダウンロードした .zip ファイルを展開(解凍)する.分かりやすいディレクトリに置く.

    Windows での展開(解凍)に便利な 7-Zip: 別ページ »で説明

    この .zip ファイルは,D:\keras-deeplab-v3-plus-master\keras-deeplab-v3-plus-master に展開(解凍)したものとして,説明を続けるので,適切に読み替えてください.

    [image]
  5. Python プログラムの実行

    Python プログラムの実行: 別ページ »で説明

    Python のまとめ: 別ページ »にまとめ

  6. カレントディレクトリの移動

    cd D:\keras-deeplab-v3-plus-master\keras-deeplab-v3-plus-master
    

    [image]
  7. モデルのダウンロードとロード

    run -i extract_weights.py 
    run -i load_weights.py 
    

    [image]

    https://github.com/bonlime/keras-deeplab-v3-plus に記載のプログラムを使用

    Python プログラムを実行する

    Python プログラムの実行: 別ページ »で説明

    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])