画像内の各画素について,ラベル (car, people, building など) を判別
画像をインスタンスに分け,インスタンスのラベル (car, people, building など)を判別.画像をインスタンスに分けるとき,重なりがありえる.
【目次】
【サイト内の関連ページ】
【関連する外部ページ】
Gitは,バージョン管理システム.ソースコードの管理や複数人での共同に役立つ.
【サイト内の関連ページ】
Windows での Git のインストール: 別ページ »で説明している.
【関連する外部ページ】
Git の公式ページ: https://git-scm.com/
CMake はビルドツールである.
【サイト内の関連ページ】
Windows での cmake のインストール: 別ページ »で説明している.
【関連する外部ページ】
CMake の公式ダウンロードページ: https://cmake.org/download/
【Python のインストールでの注意点】
Windows で,ユーザ名が日本語のとき,あとでトラブルが発生するかもしれない. トラブルの回避のため, Python をシステム管理者の領域にインストール(パソコンの全ユーザの共有領域)する.
【Python 3.7 のインストール手順の詳細(別ページ) 】
Windows での Python 3.7 のインストール: 別ページ »で説明している.
【Python の公式ページ】
【インストール手順の概要】
ページの上の方にある「Downloads」をクリック,「Downloads」の下にメニューが出るので,その中の「Windows」をクリック.
そして,Python 3.7.x (x は数字)を探す.
そして,Windows の 64ビット版のインストーラをダウンロードしたいので,「Windows x86-64 executable installer」を選ぶ
※ すでに Python ランチャーをインストール済みのときは, 「Install launcher for all users (recommended)」がチェックできないようになっている場合がある.そのときは,チェックせずに進む.
Python のインストールディレクトリは,「C:\Program Files\Python37」のように自動設定されることを確認.
「Install」をクリック
py とpip にパスが通っていることの確認である.
where py where pip
where py では「C:\Windows\py.exe」 が表示され, where pip では「C:\Program Files\Python37\Scripts\pip.exe」 が表示されることを確認.
Python の使用は「py -3.7」で行う.
py -3.7 -m pip install -U pip setuptools
コマンドプロンプトを管理者として実行: 別ページ »で説明
次のコマンドを実行する
次のコマンドを実行する
Python の使用は「C:\venv\py37\Scripts\activate.bat」の後,「python」で行う.
C:\venv\py37\Scripts\activate.bat python -m pip install -U pip setuptools jupyterlab jupyter jupyter-console jupytext nteract_on_jupyter
Windows での Visual Studio Community 2017,NVIDIA ドライバ,NVIDIA CUDA ツールキット 10.0,NVIDIA cuDNN 7.6.5 のインストール: 別ページ »で説明している.
コマンドプロンプトを管理者として実行: 別ページ »で説明
python -m pip install -U cython python -m pip install "git+https://github.com/philferriere/cocoapi.git#egg=pycocotools&subdirectory=PythonAPI"
C:\venv\py37\scripts\activate.bat python -m pip uninstall -y tensorflow tensorflow-gpu tensorflow-intel keras tensorboard tensorflow-estimator python -m pip install tensorflow==2.0.4 keras numpy
C:\venv\py37\Scripts\activate.bat python -m pip install pixellib
cd %HOMEPATH% del deeplabv3_xception65_ade20k.h5 curl -LO https://github.com/ayoolaolafenwa/PixelLib/releases/download/1.3/deeplabv3_xception65_ade20k.h5
画像ファイルは,%HOMEPATH%に置くことにする.
ここでは, https://pixellib.readthedocs.io/en/latest/image_ade20k.html で公開されている ade_test1.jpg を使用
cd %HOMEPATH% curl -O https://pixellib.readthedocs.io/en/latest/_images/ade_test1.jpg
Python プログラムを実行する.Matplotlib を使うので,Jupyter QtConsole や Jupyter ノートブック (Jupyter Notebook) の利用が便利である.
import pixellib from pixellib.semantic import semantic_segmentation fimg="ade_test1.jpg" segment_image = semantic_segmentation() segment_image.load_ade20k_model("deeplabv3_xception65_ade20k.h5") segment_image.segmentAsAde20k(fimg, output_image_name= "ade_test1_sseg.jpg") segment_image.segmentAsAde20k(fimg, output_image_name= "ade_test1_sseg_overlay.jpg", overlay = True)
Python プログラムを実行する.Matplotlib を使うので,Jupyter QtConsole や Jupyter ノートブック (Jupyter Notebook) の利用が便利である.
import matplotlib.pyplot as plt a = plt.imread("ade_test1.jpg") plt.imshow(a) plt.show() b = plt.imread("ade_test1_sseg.jpg") plt.imshow(b) plt.show() c = plt.imread("ade_test1_sseg_overlay.jpg") plt.imshow(c) plt.show()
Windows での実行手順を示す
mkdir %HOMEPATH% cd %HOMEPATH% curl -LO https://github.com/ayoolaolafenwa/PixelLib/releases/download/1.2/mask_rcnn_coco.h5
画像ファイルは,%HOMEPATH%に置くことにする.
ここでは, https://pixellib.readthedocs.io/en/latest/Image_instance.html で公開されている Sample2.jpg を使用
Python プログラムを実行する.Matplotlib を使うので,Jupyter QtConsole や Jupyter ノートブック (Jupyter Notebook) の利用が便利である.
import pixellib from pixellib.instance import instance_segmentation segment_image = instance_segmentation() segment_image.load_model("mask_rcnn_coco.h5") segment_image.segmentImage("Sample2.jpg", output_image_name= "c:/data/Sample2_iseg.jpg")
import matplotlib.pyplot as plt a = plt.imread("Sample2.jpg") plt.imshow(a) plt.show() b = plt.imread("Sample2_iseg.jpg") plt.imshow(b) plt.show()
次の URL で公開されているプログラムを,実行結果例を付けて紹介する.
mkdir %HOMEPATH% cd %HOMEPATH% curl -LO https://github.com/ayoolaolafenwa/PixelLib/releases/download/1.2/mask_rcnn_coco.h5
OpenCV による動画表示を行う.
import pixellib from pixellib.instance import instance_segmentation import cv2 capture = cv2.VideoCapture(0) segment_video = instance_segmentation() segment_video.load_model("mask_rcnn_coco.h5") segment_video.process_camera(capture, frames_per_second= 15, output_video_name="output_video.mp4", show_frames= True, frame_name= "frame")