خوشهبندی یا اشتراک وزن، تعداد مقادیر وزن منحصربهفرد را در یک مدل کاهش میدهد که منجر به مزایایی برای استقرار میشود. ابتدا وزنهای هر لایه را به N خوشه گروهبندی میکند، سپس مقدار مرکز خوشه را برای همه وزنهای متعلق به خوشه به اشتراک میگذارد.
این تکنیک از طریق فشرده سازی مدل، بهبودهایی را به همراه دارد. پشتیبانی از چارچوب آینده میتواند پیشرفتهای ردپای حافظه را باز کند که میتواند تفاوتی اساسی برای استقرار مدلهای یادگیری عمیق در سیستمهای تعبیهشده با منابع محدود ایجاد کند.
ما با خوشه بندی در بین وظایف بینایی و گفتاری آزمایش کرده ایم. همانطور که در نتایج ارائه شده در زیر نشان داده شده است، تا 5 برابر پیشرفت در فشرده سازی مدل با حداقل کاهش دقت مشاهده کرده ایم.
لطفاً توجه داشته باشید که خوشهبندی مزایای کمتری را برای لایههای کانولوشن و متراکم که قبل از یک لایه نرمالسازی دستهای قرار دارند و همچنین در ترکیب با کوانتیزاسیون پس از آموزش هر محور ارائه میکند.
ماتریس سازگاری API
کاربران می توانند خوشه بندی را با API های زیر اعمال کنند:
ساختمان مدل: keras تنها با مدل های ترتیبی و کاربردی
نسخه های TensorFlow: TF 1.x برای نسخه های 1.14+ و 2.x.
tf.compat.v1 با بسته TF 2.X و tf.compat.v2 با بسته TF 1.X پشتیبانی نمی شوند.
حالت اجرای TensorFlow: هم گراف و هم مشتاق
نتایج
طبقه بندی تصویر
مدل
اصل
خوشه ای
دقت برتر 1 (%)
اندازه tflite. فشرده (MB)
پیکربندی
# خوشه ها
دقت برتر 1 (%)
اندازه tflite. فشرده (MB)
MobileNetV1
70.976
14.97
انتخابی (3 لایه Conv2D آخر)
16، 16، 16
70.294
7.69
انتخابی (3 لایه Conv2D آخر)
32، 32، 32
70.69
8.22
کامل (همه لایههای Conv2D)
32
69.4
4.43
MobileNetV2
71.778
12.38
انتخابی (3 لایه Conv2D آخر)
16، 16، 16
70.742
6.68
انتخابی (3 لایه Conv2D آخر)
32، 32، 32
70.926
7.03
کامل (همه لایههای Conv2D)
32
69.744
4.05
مدل ها در ImageNet آموزش و آزمایش شدند.
لکه بینی کلمه کلیدی
مدل
اصل
خوشه ای
دقت برتر 1 (%)
اندازه tflite. فشرده (MB)
پیکربندی
# خوشه ها
دقت برتر 1 (%)
اندازه tflite. فشرده (MB)
DS-CNN-L
95.233
1.46
کامل (همه لایههای Conv2D)
32
95.09
0.39
کامل (همه لایههای Conv2D)
8
94.272
0.27
این مدل بر روی SpeechCommands نسخه 0.02 آموزش و آزمایش شد.
مدل Keras را در فایل .h5 سریال کنید
با استفاده از TFLiteConverter.from_keras_model_file() ، فایل h5 را به tflite. تبدیل کنید.
دسته بندی وزن یک مدل CNN آموزش داده شده بر روی مجموعه داده دسته بندی رقمی دست نویس MNIST: کد
اجرای خوشهبندی وزن بر اساس فشردهسازی عمیق: فشردهسازی شبکههای عصبی عمیق با هرس، کوانتیزاسیون آموزشدیده وکاغذ کدگذاری هافمن است. به فصل 3، با عنوان کوانتیزاسیون و تقسیم وزن آموزش دیده مراجعه کنید.
تاریخ آخرین بهروزرسانی 2024-02-03 بهوقت ساعت هماهنگ جهانی.
[[["درک آسان","easyToUnderstand","thumb-up"],["مشکلم را برطرف کرد","solvedMyProblem","thumb-up"],["غیره","otherUp","thumb-up"]],[["اطلاعاتی که نیاز دارم وجود ندارد","missingTheInformationINeed","thumb-down"],["بیشازحد پیچیده/ مراحل بسیار زیاد","tooComplicatedTooManySteps","thumb-down"],["قدیمی","outOfDate","thumb-down"],["مشکل ترجمه","translationIssue","thumb-down"],["مشکل کد / نمونهها","samplesCodeIssue","thumb-down"],["غیره","otherDown","thumb-down"]],["تاریخ آخرین بهروزرسانی 2024-02-03 بهوقت ساعت هماهنگ جهانی."],[],[],null,["# Weight clustering\n\n\u003cbr /\u003e\n\n~Maintained by Arm ML Tooling~\n\nThis document provides an overview on weight clustering to help you determine how it fits with your use case.\n\n- To dive right into an end-to-end example, see the [weight clustering example](/model_optimization/guide/clustering/clustering_example).\n- To quickly find the APIs you need for your use case, see the [weight clustering comprehensive guide](/model_optimization/guide/clustering/clustering_comprehensive_guide).\n\nOverview\n--------\n\nClustering, or weight sharing, reduces the number of unique weight values in a model, leading to benefits for deployment. It first groups the weights of each layer into *N* clusters, then shares the cluster's centroid value for all the weights belonging to the cluster.\n\nThis technique brings improvements via model compression. Future framework support can unlock memory footprint improvements that can make a crucial difference for deploying deep learning models on embedded systems with limited resources.\n\nWe have experimented with clustering across vision and speech tasks. We've seen up to 5x improvements in model compression with minimal loss of accuracy, as demonstrated by the [results](#results) presented below.\n\nPlease note that clustering will provide reduced benefits for convolution and dense layers that precede a batch normalization layer, as well as in combination with per-axis post-training quantization.\n\n### API compatibility matrix\n\nUsers can apply clustering with the following APIs:\n\n- Model building: `keras` with only Sequential and Functional models\n- TensorFlow versions: TF 1.x for versions 1.14+ and 2.x.\n - [`tf.compat.v1`](https://www.tensorflow.org/api_docs/python/tf/compat/v1) with a TF 2.X package and `tf.compat.v2` with a TF 1.X package are not supported.\n- TensorFlow execution mode: both graph and eager\n\nResults\n-------\n\n### Image classification\n\n| Model | Original || Clustered ||||\n| Model | Top-1 accuracy (%) | Size of compressed .tflite (MB) | Configuration | # of clusters | Top-1 accuracy (%) | Size of compressed .tflite (MB) |\n|-------------|--------------------|---------------------------------|----------------------------------|---------------|--------------------|---------------------------------|\n| MobileNetV1 | 70.976 | 14.97 |\n| MobileNetV1 | 70.976 | 14.97 | Selective (last 3 Conv2D layers) | 16, 16, 16 | 70.294 | 7.69 |\n| MobileNetV1 | 70.976 | 14.97 | Selective (last 3 Conv2D layers) | 32, 32, 32 | 70.69 | 8.22 |\n| MobileNetV1 | 70.976 | 14.97 | Full (all Conv2D layers) | 32 | 69.4 | 4.43 |\n| MobileNetV2 | 71.778 | 12.38 |\n| MobileNetV2 | 71.778 | 12.38 | Selective (last 3 Conv2D layers) | 16, 16, 16 | 70.742 | 6.68 |\n| MobileNetV2 | 71.778 | 12.38 | Selective (last 3 Conv2D layers) | 32, 32, 32 | 70.926 | 7.03 |\n| MobileNetV2 | 71.778 | 12.38 | Full (all Conv2D layers) | 32 | 69.744 | 4.05 |\n\nThe models were trained and tested on ImageNet.\n\n### Keyword spotting\n\n| Model | Original || Clustered ||||\n| Model | Top-1 accuracy (%) | Size of compressed .tflite (MB) | Configuration | # of clusters | Top-1 accuracy (%) | Size of compressed .tflite (MB) |\n|----------|--------------------|---------------------------------|--------------------------|---------------|--------------------|---------------------------------|\n| DS-CNN-L | 95.233 | 1.46 |\n| DS-CNN-L | 95.233 | 1.46 | Full (all Conv2D layers) | 32 | 95.09 | 0.39 |\n| DS-CNN-L | 95.233 | 1.46 | Full (all Conv2D layers) | 8 | 94.272 | 0.27 |\n\nThe model was trained and tested on SpeechCommands v0.02.\n| **Note:** *Size of compressed .tflite* refers to the size of the zipped .tflite file obtained from the model from the following process:\n\n1. Serialize the Keras model into .h5 file\n2. Convert the .h5 file into .tflite using `TFLiteConverter.from_keras_model_file()`\n3. Compress the .tflite file into a zip\n\nExamples\n--------\n\nIn addition to the\n[Weight clustering in Keras example](/model_optimization/guide/clustering/clustering_example), see the\nfollowing examples:\n\n- Cluster the weights of a CNN model trained on the MNIST handwritten digit classification dataset: [code](https://github.com/tensorflow/model-optimization/blob/master/tensorflow_model_optimization/python/examples/clustering/keras/mnist/mnist_cnn.py)\n\nThe weight clustering implementation is based on the *Deep Compression:\nCompressing Deep Neural Networks With Pruning, Trained Quantization and Huffman\nCoding* [paper](https://arxiv.org/abs/1510.00149). See chapter 3, titled\n*Trained Quantization and Weight Sharing*."]]