Main Content

量化、投影和剪枝

通过执行量化、投影或剪枝来压缩深度神经网络

将 Deep Learning Toolbox™ 和 Deep Learning Toolbox Model Quantization Library 支持包结合使用,通过以下方式减少深度神经网络的内存占用和计算要求:

  • 使用一阶泰勒逼近从卷积层中对滤波器进行剪枝。然后,您可以从这个剪枝过的网络中生成 C/C++ 或 CUDA® 代码。

  • 对层进行投影,先使用代表训练数据的数据集对层激活执行主成分分析 (PCA),然后对层的可学习参数应用线性投影。当您使用无库的 C/C++ 代码生成将网络部署到嵌入式硬件时,投影的深度神经网络的前向传导通常会更快。

  • 将层的权重、偏置和激活量化为精度降低的缩放整数数据类型。然后,您可以从这个量化的网络中生成 C/C++、CUDA 或 HDL 代码。

    为了实现 C/C++ 和 CUDA 代码生成,软件通过将卷积层的权重、偏置和激活量化为 8 位定标整数数据类型,为卷积深度神经网络生成代码。量化是通过向 codegen (MATLAB Coder) 命令提供由 calibrate 函数生成的标定结果文件来执行的。

    代码生成不支持由 quantize 函数生成的量化深度神经网络。

函数

全部展开

taylorPrunableNetworkNetwork that can be pruned by using first-order Taylor approximation (自 R2022a 起)
forwardCompute deep learning network output for training (自 R2019b 起)
predictCompute deep learning network output for inference (自 R2019b 起)
updatePrunablesRemove filters from prunable layers based on importance scores (自 R2022a 起)
updateScoreCompute and accumulate Taylor-based importance scores for pruning (自 R2022a 起)
dlnetworkDeep learning neural network (自 R2019b 起)
compressNetworkUsingProjectionCompress neural network using projection (自 R2022b 起)
neuronPCAPrincipal component analysis of neuron activations (自 R2022b 起)
unpackProjectedLayersUnpack projected layers of neural network (自 R2023b 起)
ProjectedLayerCompressed neural network layer using projection (自 R2023b 起)
gruProjectedLayerGated recurrent unit (GRU) projected layer for recurrent neural network (RNN) (自 R2023b 起)
lstmProjectedLayerLong short-term memory (LSTM) projected layer for recurrent neural network (RNN) (自 R2022b 起)
dlquantizerQuantize a deep neural network to 8-bit scaled integer data types (自 R2020a 起)
dlquantizationOptionsOptions for quantizing a trained deep neural network (自 R2020a 起)
calibrateSimulate and collect ranges of a deep neural network (自 R2020a 起)
quantizeQuantize deep neural network (自 R2022a 起)
validateQuantize and validate a deep neural network (自 R2020a 起)
quantizationDetailsDisplay quantization details for a neural network (自 R2022a 起)
estimateNetworkMetricsEstimate network metrics for specific layers of a neural network (自 R2022a 起)
equalizeLayersEqualize layer parameters of deep neural network (自 R2022b 起)

App

深度网络量化器Quantize deep neural network to 8-bit scaled integer data types (自 R2020a 起)

主题

剪枝

投影和知识蒸馏

量化

GPU 目标的量化

FPGA 目标的量化

CPU 目标的量化