ติดตั้งการเพิ่มประสิทธิภาพโมเดล TensorFlow
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
ขอแนะนำให้สร้างสภาพแวดล้อมเสมือน Python ก่อนดำเนินการติดตั้ง โปรดดู คู่มือ การติดตั้ง TensorFlow สำหรับข้อมูลเพิ่มเติม
โครงสร้างที่มั่นคง
หากต้องการติดตั้งเวอร์ชันล่าสุด ให้รันสิ่งต่อไปนี้:
# Installing with the `--upgrade` flag ensures you'll get the latest version.
pip install --user --upgrade tensorflow-model-optimization
สำหรับรายละเอียดการเผยแพร่ โปรดดู บันทึกประจำรุ่น ของเรา
สำหรับเวอร์ชันที่จำเป็นของ TensorFlow และข้อมูลความเข้ากันได้อื่นๆ โปรดดูส่วนเมทริกซ์ความเข้ากันได้ของ API ของหน้าภาพรวมสำหรับเทคนิคที่คุณต้องการใช้ ตัวอย่างเช่น สำหรับการตัดแต่งกิ่ง หน้าภาพรวมอยู่ ที่นี่
เนื่องจาก TensorFlow ไม่ รวมอยู่ในการขึ้นต่อกันของแพ็คเกจ TensorFlow Model Optimization (ใน setup.py
) คุณต้องติดตั้งแพ็คเกจ TensorFlow อย่างชัดเจน ( tf-nightly
หรือ tf-nightly-gpu
) สิ่งนี้ช่วยให้เราสามารถรักษาแพ็คเกจเดียวแทนที่จะแยกแพ็คเกจสำหรับ TensorFlow ที่เปิดใช้งาน CPU และ GPU
การติดตั้งจากแหล่งที่มา
คุณยังสามารถติดตั้งจากแหล่งที่มาได้ สิ่งนี้ต้องการระบบการสร้าง Bazel
# To install dependencies on Ubuntu:
# sudo apt-get install bazel git python-pip
# For other platforms, see Bazel docs above.
git clone https://github.com/tensorflow/model-optimization.git
cd model-optimization
bazel build --copt=-O3 --copt=-march=native :pip_pkg
PKGDIR=$(mktemp -d)
./bazel-bin/pip_pkg $PKGDIR
pip install --user --upgrade $PKGDIR/*.whl
เนื้อหาของหน้าเว็บนี้ได้รับอนุญาตภายใต้ใบอนุญาตที่ต้องระบุที่มาของครีเอทีฟคอมมอนส์ 4.0 และตัวอย่างโค้ดได้รับอนุญาตภายใต้ใบอนุญาต Apache 2.0 เว้นแต่จะระบุไว้เป็นอย่างอื่น โปรดดูรายละเอียดที่นโยบายเว็บไซต์ Google Developers Java เป็นเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2025-07-25 UTC
[null,null,["อัปเดตล่าสุด 2025-07-25 UTC"],[],[],null,["# Install TensorFlow Model Optimization\n\nIt is recommended to create a Python virtual environment before proceeding to\nthe installation. Please see the TensorFlow installation\n[guide](https://www.tensorflow.org/install/pip#2.-create-a-virtual-environment-recommended)\nfor more information.\n\n### Stable Builds\n\nTo install the latest version, run the following: \n\n # Installing with the `--upgrade` flag ensures you'll get the latest version.\n pip install --user --upgrade tensorflow-model-optimization\n\nFor release details, see our\n[release notes](https://github.com/tensorflow/model-optimization/releases).\n\nFor the required version of TensorFlow and other compatibility information, see\nthe API Compatibility Matrix section of the Overview page for the technique you\nintend to use. For instance, for pruning, the Overview page is\n[here](https://www.tensorflow.org/model_optimization/guide/pruning).\n\nSince TensorFlow is *not* included as a dependency of the TensorFlow Model\nOptimization package (in `setup.py`), you must explicitly install the TensorFlow\npackage (`tf-nightly` or `tf-nightly-gpu`). This allows us to maintain one\npackage instead of separate packages for CPU and GPU-enabled TensorFlow.\n\n### Installing from Source\n\nYou can also install from source. This requires the\n[Bazel](https://bazel.build/) build system. \n\n # To install dependencies on Ubuntu:\n # sudo apt-get install bazel git python-pip\n # For other platforms, see Bazel docs above.\n git clone https://github.com/tensorflow/model-optimization.git\n cd model-optimization\n bazel build --copt=-O3 --copt=-march=native :pip_pkg\n PKGDIR=$(mktemp -d)\n ./bazel-bin/pip_pkg $PKGDIR\n pip install --user --upgrade $PKGDIR/*.whl"]]