การติดตั้ง

การติดตั้งด้วย 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
  • คอมไพล์
  • แพ็คเกจ Python: แพนด้าเทนเซอร์โฟลว์จำนวนมาก

แทนที่จะติดตั้งการขึ้นต่อกันด้วยมือ คุณสามารถใช้ TensorFlow Build docker ได้ หากคุณเลือกตัวเลือกนี้ ให้ติดตั้ง 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

ทางเลือก: หากคุณต้องการใช้อ็อพชันนักเทียบท่า ให้รันสคริปต์ start_compile_docker.sh และดำเนินการขั้นตอนถัดไป หากคุณไม่ต้องการใช้ตัวเลือกนักเทียบท่า ให้ทำตามขั้นตอนถัดไปโดยตรง

# 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 จะมีการสร้างแพ็คเกจ pip ที่เข้ากันได้กับ manylinux2014 และการตรวจสอบขั้นสุดท้ายจะล้มเหลว ไม่สำคัญว่าคุณต้องการใช้ TF-DF บนเครื่องของคุณเองหรือไม่ วิธีง่ายๆ ในการสร้างความเข้ากันได้ของ build manylinux2014 คือการใช้นักเทียบท่าที่กล่าวถึงข้างต้น

# Build and test a Pip package.
./tools/build_pip_package.sh python3.9

คำสั่งนี้จะติดตั้งแพ็คเกจ TF-DF pip และเรียกใช้ตัวอย่างใน examples/minimal.py แพ็คเกจ Pip อยู่ในไดเร็กทอรี dist/

หากคุณต้องการสร้างแพ็คเกจ Pip สำหรับ Python เวอร์ชันอื่นที่เข้ากันได้ ให้รัน:

# Install the other versions of python (assume only python3.9 is installed; this is the case in the build docker).
sudo apt-get update && sudo apt-get install python3.9 python3-pip

# Create the Pip package for the other version of python
./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

แมคโอเอส

ติดตั้ง

ความต้องการ

  • เครื่องมือบรรทัดคำสั่ง XCode
  • Bazel (แนะนำ Bazelisk )
  • หลาม >= 3.9
  • คอมไพล์
  • Pyenv (สำหรับการสร้างแพ็คเกจ Pip ด้วย Python หลายเวอร์ชัน)

อาคาร / บรรจุภัณฑ์ (Apple CPU)

หากคุณมีเครื่อง MacOS ที่มี CPU ของ Apple คุณสามารถสร้างตามคำแนะนำต่อไปนี้

  1. โคลนที่เก็บข้อมูลทั้งสามและปรับเส้นทาง

    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
    

    คุณอาจต้องปรับสคริปต์ test_bazel.sh ด้วยตนเองเพื่อแก้ไขแฮชคอมมิต Tensorflow เนื่องจากบางครั้งสคริปต์นั้นใช้งานไม่ได้สำหรับ MacOS บิวด์

  2. (ไม่บังคับ) สร้างสภาพแวดล้อมเสมือนจริงใหม่และเปิดใช้งาน

    python3 -m venv venv
    source venv/source/activate
    
  3. ปรับการพึ่งพา TensorFlow สำหรับ CPU ของ Apple

    perl -0777 -i.original -pe 's/tensorflow~=/tensorflow-macos~=/igs' decision-forests/configure/setup.py
    
  4. ตัดสินใจเลือกเวอร์ชัน 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
    
  5. สร้างแพ็คเกจ 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
    
  6. แพ็คเกจสามารถพบได้ใน decision-forests/dist/

การคอมไพล์ข้ามสำหรับ Intel CPU

หากคุณมีเครื่อง MacOS ที่มี Apple CPU ให้ข้ามคอมไพล์ TF-DF สำหรับเครื่อง MacOS ที่มี CPU Intel ดังต่อไปนี้

  1. ทำตามขั้นตอนที่ 1-3 และ 5 ของคำแนะนำสำหรับ CPU ของ Apple ข้ามขั้นตอนที่ 4 คุณอาจต้องเรียกใช้ bazel --bazelrc=tensorflow_bazelrc clean --expunge เพื่อล้างไดเร็กทอรีบิลด์ของคุณ

  2. ตัดสินใจเลือกเวอร์ชัน 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
    
  3. สร้างแพ็คเกจ 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
    
  4. แพ็คเกจสามารถพบได้ใน decision-forests/dist/

หมายเหตุสุดท้าย

การคอมไพล์ TF-DF อาศัยแพ็คเกจ TensorFlow Pip และ การขึ้นต่อกันของ TensorFlow Bazel TensorFlow จะรวบรวมเพียงส่วนเล็กๆ เท่านั้น การรวบรวม TF-DF บนเวิร์กสเตชันอันทรงพลังเพียงเครื่องเดียวใช้เวลาประมาณ 10 นาที