התקנה עם Pip
התקן את TensorFlow Decision Forests על ידי הפעלת:
# 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__)"
בנה ממקור
לינוקס
להכין
דרישות
- בזל >= 3.7.2
- פייתון >= 3
- Git
- חבילות פייתון: פנדות מנופי tensorflow
במקום להתקין את התלות בידיים, אתה יכול להשתמש במעגן TensorFlow Build . אם תבחר באפשרויות אלה, התקן את Docker:
- דוקר .
הַהדָרָה
הורד את TensorFlow Decision Forests באופן הבא:
# Download the source code of TF-DF.
git clone https://github.com/tensorflow/decision-forests.git
cd decision-forests
אופציונלי: TensorFlow Decision Forests תלוי ב- Yggdrasil Decision Forests . אם אתה רוצה לערוך את קוד 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 שבה ברצונך להשתמש. שימו לב שאינכם חייבים להשתמש באותה גרסה של Python כמו בסקריפט test_bazel.sh
.
אם התצורה שלך תואמת ל- manylinux2014 , תיווצר חבילת pip תואמת manylinux2014
.
אם התצורה שלך אינה תואמת ל-manylinux2014, manylinux2014
חבילת pip שאינה תואמת ל-manylinux2014, והבדיקה הסופית תיכשל. זה לא משנה אם אתה רוצה להשתמש ב-TF-DF במחשב שלך. דרך קלה להפוך את ה-build manylinux2014 תואם היא להשתמש ב-docker שהוזכר לעיל.
# Build and test a Pip package.
./tools/build_pip_package.sh python3.8
פקודה זו תתקין את חבילת TF-DF pip ותפעיל את הדוגמה ב- examples/minimal.py
. חבילת Pip ממוקמת בספריית dist/
.
אם אתה רוצה ליצור חבילת Pip עבור הגרסה התואמת האחרת של Python, הרץ:
# 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
לחלופין , אתה יכול ליצור את חבילת pip עבור כל הגירסאות התואמות של python באמצעות pyenv על ידי הפעלת הפקודה הבאה. ראה את הכותרת של tools/build_pip_package.sh
לפרטים נוספים.
# Build and test all the Pip package using Pyenv.
./tools/build_pip_package.sh ALL_VERSIONS
MacOS
להכין
דרישות
- כלי שורת הפקודה XCode
- Bazel (מומלץ Bazelisk )
- Python >= 3.8
- Git
- Pyenv (לבניית חבילות Pip עם גרסאות פייתון מרובות)
בניין/אריזה (מעבד אפל)
אם יש לך מכונת MacOS עם Apple CPU, אתה יכול לבנות עם ההוראות הבאות.
שכפל את שלושת המאגרים והתאם נתיבים.
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
התאם את התלות של TensorFlow עבור מעבדי Apple
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
בנה את חבילות ה-Pip
# 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/
.
קומפילציה צולבת עבור מעבדי אינטל
אם יש לך מכונת MacOS עם מעבד Apple, בצע קומפילציה צולבת של TF-DF עבור מכונות MacOS עם מעבדי אינטל באופן הבא.
בצע את שלבים 1-3 ו-5 במדריך למעבדי Apple, דלג על שלב 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
בנה את חבילות ה-Pip
# 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 דקות.