Pip を使用したインストール
以下を実行して、TensorFlow デシジョン フォレストをインストールします。
# Install TensorFlow Decision Forests.
pip3 install tensorflow_decision_forests --upgrade
次に、次を実行してインストールを確認します。
# Check the version of TensorFlow Decision Forests.
python3 -c "import tensorflow_decision_forests as tfdf; print('Found TF-DF v' + tfdf.__version__)"
ソースからビルド
Linux
設定
要件
- バゼル >= 3.7.2
- パイソン >= 3
- ギット
- Python パッケージ: numpy tensorflow pandas
依存関係を手動でインストールする代わりに、 TensorFlow Build dockerを使用できます。このオプションを選択した場合は、Docker をインストールします。
- ドッカー。
コンパイル
TensorFlow デシジョン フォレストを次のようにダウンロードします。
# Download the source code of TF-DF.
git clone https://github.com/tensorflow/decision-forests.git
cd decision-forests
オプション: TensorFlow デシジョン フォレストはYggdrasil デシジョンフォレストに依存します。 Yggdrasil コードを編集する場合は、Yggdrasil github のクローンを作成し、それに応じてthird_party/yggdrasil_decision_forests/workspace.bzl
のパスを変更できます。
オプション: docker オプションを使用する場合は、 start_compile_docker.sh
スクリプトを実行して、次のステップに進みます。 docker オプションを使用しない場合は、直接次の手順に進みます。
# Optional: Install and start the build docker.
./tools/start_compile_docker.sh
次のコマンドを使用して、TF-DF の単体テストをコンパイルして実行します。 test_bazel.sh
は、マシンのpython3.8
およびデフォルトのコンパイラ用に構成されていることに注意してください。この構成を変更するには、ファイルを直接編集します。
# Build and test TF-DF.
./tools/test_bazel.sh
次のコマンドで pip パッケージを作成してテストします。 python3.8 を、使用する python のバージョンに置き換えます。 test_bazel.sh
スクリプトと同じバージョンの Python を使用する必要はないことに注意してください。
構成がmanylinux2014と互換性がある場合、 manylinux2014
互換の pip パッケージが生成されます。
構成が manylinux2014 と互換性がない場合、 manylinux2014
と互換性のない pip パッケージが生成され、最終チェックは失敗します。自分のマシンで TF-DF を使用するかどうかは問題ではありません。ビルド manylinux2014 に互換性を持たせる簡単な方法は、上記の docker を使用することです。
# Build and test a Pip package.
./tools/build_pip_package.sh python3.8
このコマンドは、TF-DF pip パッケージをインストールし、 examples/minimal.py
のサンプルを実行します。 Pip パッケージはdist/
ディレクトリにあります。
互換性のある他のバージョンの Python 用の Pip パッケージを作成する場合は、次を実行します。
# Install the other versions of python (assume only python3.8 is installed; this is the case in the build docker).
sudo apt-get update && sudo apt-get install python3.7 python3.9 python3-pip
# Create the Pip package for the other version of python
./tools/build_pip_package.sh python3.7
./tools/build_pip_package.sh python3.9
または、 pyenvを使用して次のコマンドを実行することにより、互換性のあるすべてのバージョンの python の pip パッケージを作成できます。詳細については、 tools/build_pip_package.sh
のヘッダーを参照してください。
# Build and test all the Pip package using Pyenv.
./tools/build_pip_package.sh ALL_VERSIONS
マックOS
設定
要件
- XCode コマンド ライン ツール
- バゼル(バゼリスク推奨)
- Python >= 3.8
- ギット
- Pyenv (複数の Python バージョンで Pip パッケージをビルドするため)
ビルド/パッケージング (Apple CPU)
Apple CPU を搭載した MacOS マシンをお持ちの場合は、次の手順でビルドできます。
3 つのリポジトリを複製し、パスを調整します。
git clone https://github.com/tensorflow/decision-forests.git git clone https://github.com/google/yggdrasil-decision-forests.git git clone --branch boost-1.75.0 https://github.com/boostorg/boost.git (cd boost && git submodule update --init --checkout --force) # Adjust path TF-DF --> YDF perl -0777 -i.original -pe 's/ http_archive\(\n name = "ydf",\n urls = \["https:\/\/github.com\/google\/yggdrasil-decision-forests\/archive\/refs\/heads\/main.zip"\],\n strip_prefix = "yggdrasil-decision-forests-main",\n \)/ native.local_repository\(\n name = "ydf",\n path = "..\/yggdrasil-decision-forests",\n \)/igs' decision-forests/third_party/yggdrasil_decision_forests/workspace.bzl # Adjust path YDF --> Boost perl -0777 -i.original -pe 's/ new_git_repository\(\n name = "org_boost",\n branch = branch,\n build_file_content = build_file_content,\n init_submodules = True,\n recursive_init_submodules = True,\n remote = "https:\/\/github.com\/boostorg\/boost",\n \)/ native.new_local_repository\(\n name = "org_boost",\n path = "..\/boost",\n build_file_content = build_file_content,\n \)/igs' yggdrasil-decision-forests/third_party/boost/workspace.bzl
(オプション) 新しい仮想環境を作成してアクティブ化する
python3 -m venv venv source venv/source/activate
Apple CPU の TensorFlow 依存関係を調整する
perl -0777 -i.original -pe 's/tensorflow~=/tensorflow-macos~=/igs' decision-forests/configure/setup.py
使用して実行する Python のバージョンを決定する
cd decision-forests # This will compile with the latest Tensorflow version in the tensorflow-macos repository. RUN_TESTS=1 PY_VERSION=3.9 TF_VERSION=mac-arm64 ./tools/test_bazel.sh
ピップ パッケージをビルドする
# First, we deactivate our virtualenv, since the Pip script uses a different one. deactivate # Build the packages. ./tools/build_pip_package.sh ALL_VERSIONS_MAC_ARM64
パッケージは
decision-forests/dist/
ます。
Intel CPU のクロスコンパイル
Apple CPU を搭載した MacOS マシンを使用している場合は、Intel CPU を搭載した MacOS マシン用の TF-DF を次のようにクロスコンパイルします。
Apple CPU のガイドの手順 1 ~ 3 および 5 に従います。手順 4 はスキップしてください。
使用して実行する Python のバージョンを決定する
cd decision-forests # This will compile with the latest Tensorflow version in the tensorflow-macos repository. RUN_TESTS=0 PY_VERSION=3.9 TF_VERSION=mac-intel-crosscompile ./tools/test_bazel.sh
ピップ パッケージをビルドする
# First, we deactivate our virtualenv, since the Pip script uses a different one. deactivate # Build the packages. ./tools/build_pip_package.sh ALL_VERSIONS_MAC_INTEL_CROSSCOMPILE
パッケージは
decision-forests/dist/
ます。
最後の注意事項
TF-DF のコンパイルは、TensorFlow Pip パッケージとTensorFlow Bazel 依存関係に依存しています。 TensorFlow のごく一部のみがコンパイルされます。単一の強力なワークステーションで TF-DF をコンパイルするには、約 10 分かかります。