rembg のインストールと動作確認(画像の背景除去)(Python を使用)(Windows 上)
【関連する外部ページ】
GitHub のページ: https://github.com/danielgatis/rembg
U2-Net
【文献】
Xuebin Qin, Zichen Zhang, Chenyang Huang, Masood Dehghan, Osmar R. Zaiane and Martin Jagersand, U2-Net: Going Deeper with Nested U-Structure for Salient Object Detection, arXiv:2108.10257, 2021.
前準備
Python 3.12 のインストール(Windows 上) [クリックして展開]
以下のいずれかの方法で Python 3.12 をインストールする。Python がインストール済みの場合、この手順は不要である。
方法1:winget によるインストール
管理者権限のコマンドプロンプトで以下を実行する。管理者権限のコマンドプロンプトを起動するには、Windows キーまたはスタートメニューから「cmd」と入力し、表示された「コマンドプロンプト」を右クリックして「管理者として実行」を選択する。
winget install --scope machine --id Python.Python.3.12 -e --silent --disable-interactivity --force --accept-source-agreements --accept-package-agreements --override "/quiet InstallAllUsers=1 PrependPath=1 Include_pip=1 Include_test=0 Include_launcher=1 InstallLauncherAllUsers=1"
--scope machine を指定することで、システム全体(全ユーザー向け)にインストールされる。このオプションの実行には管理者権限が必要である。インストール完了後、コマンドプロンプトを再起動すると PATH が自動的に設定される。
方法2:インストーラーによるインストール
- Python 公式サイト(https://www.python.org/downloads/)にアクセスし、「Download Python 3.x.x」ボタンから Windows 用インストーラーをダウンロードする。
- ダウンロードしたインストーラーを実行する。
- 初期画面の下部に表示される「Add python.exe to PATH」に必ずチェックを入れてから「Customize installation」を選択する。このチェックを入れ忘れると、コマンドプロンプトから
pythonコマンドを実行できない。 - 「Install Python 3.xx for all users」にチェックを入れ、「Install」をクリックする。
インストールの確認
コマンドプロンプトで以下を実行する。
python --version
バージョン番号(例:Python 3.12.x)が表示されればインストール成功である。「'python' は、内部コマンドまたは外部コマンドとして認識されていません。」と表示される場合は、インストールが正常に完了していない。
- 必要なPythonライブラリのインストール
【関連する外部ページ】
【サイト内の関連ページ】
動作確認
- Windows で,コマンドプロンプトを実行
- rembg のソースコード等のダウンロード
cd /d c:%HOMEPATH% rmdir /s /q rembg git clone https://github.com/danielgatis/rembg
- 動作確認
cd /d c:%HOMEPATH% cd rembg cd examples rembg i animal-1.jpg animal-1.result.jpg animal-1.result.jpg rembg i animal-2.jpg animal-2.result.jpg animal-2.result.jpg rembg i animal-3.jpg animal-3.result.jpg animal-3.result.jpg rembg i girl-1.jpg girl-1.result.jpg girl-1.result.jpg rembg i girl-2.jpg girl-2.result.jpg girl-2.result.jpg rembg i girl-3.jpg girl-3.result.jpg girl-3.result.jpg