للعثور بسرعة على واجهات برمجة التطبيقات التي تحتاجها لحالة الاستخدام الخاصة بك، راجع الدليل الشامل لتجميع الوزن .
ملخص
يؤدي التجميع، أو مشاركة الوزن، إلى تقليل عدد قيم الوزن الفريدة في النموذج، مما يؤدي إلى فوائد النشر. يقوم أولاً بتجميع أوزان كل طبقة في مجموعات N ، ثم يشارك قيمة النقطه الوسطى للمجموعة لجميع الأوزان التي تنتمي إلى المجموعة.
توفر هذه التقنية تحسينات عبر ضغط النموذج. يمكن أن يؤدي دعم إطار العمل المستقبلي إلى إطلاق تحسينات في بصمة الذاكرة والتي يمكن أن تحدث فرقًا حاسمًا في نشر نماذج التعلم العميق على الأنظمة المدمجة ذات الموارد المحدودة.
لقد جربنا التجميع عبر مهام الرؤية والكلام. لقد شهدنا ما يصل إلى 5 أضعاف التحسينات في ضغط النموذج مع الحد الأدنى من فقدان الدقة، كما يتضح من النتائج المعروضة أدناه.
يرجى ملاحظة أن التجميع سيوفر فوائد مخفضة للطبقات الملتوية والطبقات الكثيفة التي تسبق طبقة تسوية الدفعة، وكذلك بالاشتراك مع التكميم بعد التدريب لكل محور.
مصفوفة توافق 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 (ميجابايت)
إعدادات
# من المجموعات
دقة أعلى 1 (%)
حجم الملف المضغوط .tflite (ميجابايت)
موبايل نتV1
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
موبايل نتV2
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 (ميجابايت)
إعدادات
# من المجموعات
دقة أعلى 1 (%)
حجم الملف المضغوط .tflite (ميجابايت)
دي إس-سي إن إن-إل
95.233
1.46
كامل (جميع طبقات Conv2D)
32
95.09
0.39
كامل (جميع طبقات Conv2D)
8
94.272
0.27
تم تدريب النموذج واختباره على SpeechCommands v0.02.
قم بإجراء تسلسل لنموذج Keras في ملف .h5
قم بتحويل ملف .h5 إلى .tflite باستخدام TFLiteConverter.from_keras_model_file()
قم بتجميع أوزان نموذج CNN الذي تم تدريبه على مجموعة بيانات تصنيف الأرقام المكتوبة بخط اليد MNIST: الكود
يعتمد تطبيق تجميع الوزن على الضغط العميق: ضغط الشبكات العصبية العميقة مع التقليم، والتكميم المدرب، وورقة هوفمان للتشفير. انظر الفصل الثالث بعنوان التكميم المدرّب وتقاسم الوزن .
تاريخ التعديل الأخير: 2024-02-03 (حسب التوقيت العالمي المتفَّق عليه)
[null,null,["تاريخ التعديل الأخير: 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*."]]