メニュー
はじめに
- 教師あり学習では、画像データにラベルを付与することで、初めて意味のある学習データになります。
- 本マニュアルでは、ラベリングツール
labelImg(Pythonのプログラム)によるラベリング手順を紹介します。
Pythonの環境構築
pyenvの導入 (shellがzshの場合)
- pyenvはPythonの複数のバージョンを簡単に切り替えることができます。
- GitHubのリポジトリをクローン (https://github.com/pyenv/pyenv)
$ git clone https://github.com/pyenv/pyenv -
~/.zprofile、~/.profile、~/.zshrcに下記のテキストを追記する~/.zprofileexport PYENV_ROOT="$HOME/.pyenv" export PATH="$PYENV_ROOT/bin:$PATH" eval "$(pyenv init --path)"~/.profileexport PYENV_ROOT="$HOME/.pyenv" export PATH="$PYENV_ROOT/bin:$PATH" eval "$(pyenv init --path)"~/.zshrceval "$(pyenv init -)"
仮想環境の作成
-
適当なディレクトリを作成
$ mkdir dataset $ cd dataset -
使いたいPythonのバージョンをインストールする
- インストールできるPythonのバージョンを確認
$ pyenv install --list - バージョン
3.8.5をインストールするとする- Pythonは
2系と3系があります。今回は3系を使います。
$ pyenv install 3.8.5 - Pythonは
- 先ほど作成したディレクトリに反映(
.python-versionというファイルが作成される)$ pyenv local 3.8.5
- インストールできるPythonのバージョンを確認
-
venvによる仮想環境の作成- パッケージをプロジェクトごとに独立させることができます。(Python3の標準機能なので別途インストールは不要)
- 新しい環境の作成
-
newenvnameは好きな名前でいいです。(venvか.venvが一般的) -
newenvname下にパッケージが置かれます。
-
$ python -m venv [newenvname]- 有効化
$ source [newenvname]/bin/activate- 無効化
$ deactivate
labelImgの導入
-
レポジトリのクローン (https://github.com/tzutalin/labelImg)
$ git clone https://github.com/tzutalin/labelImg $ cd labelImg -
pipでパッケージのインストール$ pip install -r requirements/requirements-linux-python3.txt $ make qt5py3 -
labelImgの起動
$ python labelImg.py [画像ファイルのパス] [分類クラスのテキストファイル]