最佳化機器學習模型

import tensorflow as tf
import tensorflow_model_optimization as tfmot
import tf_keras as keras

model = keras.Sequential([...])

pruning_schedule = tfmot.sparsity.keras.PolynomialDecay(
                      initial_sparsity=0.0, final_sparsity=0.5,
                      begin_step=2000, end_step=4000)

model_for_pruning = tfmot.sparsity.keras.prune_low_magnitude(
    model, pruning_schedule=pruning_schedule)
...

model_for_pruning.fit(...)
TensorFlow 模型最佳化工具組是一套用於最佳化 ML 模型以進行部署和執行的工具。此工具組支援多種技術,用途包括:
  • 降低雲端和邊緣裝置(例如行動裝置、IoT)的延遲時間和推論成本。
  • 將模型部署到對處理、記憶體、功耗、網路使用量和模型儲存空間有限制的邊緣裝置。
  • 啟用在現有硬體或新的特殊用途加速器上執行,並針對其進行最佳化。

根據您的任務選擇模型和最佳化工具