liveBook · Manning

Model optimization

As explained in Deep Learning with R, Third Edition

Model optimization is the modification of a trained model to reduce computational, memory, or latency costs while preserving acceptable predictive performance.

Model optimization modifies a trained model to reduce inference memory, computation, or latency while preserving acceptable predictive performance. It matters especially on smartphones, embedded devices, and other constrained or low-latency targets. section 6.3.2

Use two main techniques to reduce inference cost:

  • Apply weight pruning to retain the most significant coefficients, reducing parameters and computation while exposing a tunable size-versus-accuracy tradeoff. section 6.3.2
  • Apply weight quantization to convert float32 weights to int8, producing an inference-only model that is four times smaller and near the original accuracy. section 6.3.2

Quantizing a Keras model

Call quantize_weights(model, "int8") before importing the model into TensorFlow.js or exporting it to TensorFlow Lite. Validate the resulting accuracy because optimization trades resource usage against predictive performance. section 6.3.2

How Deep Learning with R, Third Edition covers it

How deep it goes
Defines pruning and quantization with tradeoffs and an API call, but does not detail pruning algorithms or evaluation procedures.
Examples
Uses significant-weight pruning and Keras int8 quantization as concrete optimization examples.
What it assumes
Assumes a trained deep learning model and a target deployment environment with resource or latency constraints.
What you can do after
Apply it via Keras to compress weights before deploying an inference model.
How it connects
Connects inference optimization with TensorFlow.js, TensorFlow Lite, Keras, and ONNX deployment.

Also explained in

Compare how 2 books explain model optimization →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Deep Learning with R, Third Edition. The section links point to the parts of the book it draws on.