From 698da2e16f86a5764c005f471ccbd35a3fb7075b Mon Sep 17 00:00:00 2001 From: Petros Toupas Date: Fri, 5 Jan 2024 14:03:53 +0200 Subject: [PATCH] update README --- README.md | 26 +++++++++++++------------- encoding/utils.py | 21 ++++++++++++++++++--- 2 files changed, 31 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 8099802..0086689 100644 --- a/README.md +++ b/README.md @@ -86,20 +86,20 @@ python threshold_relu_example.py * RLE-8, run-length encoding, use 8 bits for encoding (max length 2^8) * Compression Ratio, average over all weights and activations -| Dataset | Model | Experiment | Compression Ratio | +| Dataset | Model | Experiment | Avg Compression Ratio | |------------|----------------------|------------|-------------------| -| coco | yolov8n ([onnx](https://drive.google.com/file/d/10-lNBid4VRzWBrE6GuT3I3L3H2BtWT1P/view?usp=sharing)) | RLE-8 | 1.753 | -| camvid | unet-bilinear ([onnx](https://drive.google.com/file/d/1C_Q58_NKMVfpbqg3ZbQ1IzyMSgoopex7/view?usp=sharing)) | RLE-8 | 1.175 | -| cityscapes | unet (onnx) | RLE-8 | GPU TIMEOUT | -| ucf101 | x3d_s ([onnx](https://drive.google.com/file/d/1gY5HGMWacbTQ5cK8MWdQgQ1lQM5VWRFb/view?usp=sharing)) | RLE-8 | 1.737 | -| ucf101 | x3d_m ([onnx](https://drive.google.com/file/d/1WaLjJYE0l_AiIrZw559Ile3xQza_wnWJ/view?usp=sharing)) | RLE-8 | 1.721 | -| brats2020 | unet3d (onnx) | RLE-8 | - | -| coco | yolov8n ([onnx](https://drive.google.com/file/d/1ghj2Da4HdkHSC-ADSe-JwvQbtwhUT_vT/view?usp=sharing)) | Huffman | 0.821 | -| camvid | unet-bilinear ([onnx](https://drive.google.com/file/d/1X6Ps_qcbP7vJLgNCkHbsHtWY6aSnG8es/view?usp=sharing)) | Huffman | 0.684 | -| cityscapes | unet ([onnx](https://drive.google.com/file/d/1d2v6VJI8B9DZY020Nq_AWQR0e8F9LH6A/view?usp=sharing)) | Huffman | 0.692 | -| ucf101 | x3d_s ([onnx](https://drive.google.com/file/d/19c6jwuHZVcfZXPpXMaGmaK9AsRXPO5lJ/view?usp=sharing)) | Huffman | 0.835 | -| ucf101 | x3d_m ([onnx](https://drive.google.com/file/d/1RQr0lEuROwO14F0WtObBUmuz8Na3Vci2/view?usp=sharing)) | Huffman | 0.833 | -| brats2020 | unet3d (onnx) | Huffman | - | +| coco | yolov8n ([onnx](https://drive.google.com/file/d/10-lNBid4VRzWBrE6GuT3I3L3H2BtWT1P/view?usp=sharing)) | RLE-8 | 1.753 | +| camvid | unet-bilinear ([onnx](https://drive.google.com/file/d/1C_Q58_NKMVfpbqg3ZbQ1IzyMSgoopex7/view?usp=sharing)) | RLE-8 | 1.175 | +| cityscapes | unet (onnx) | RLE-8 | GPU TIMEOUT | +| ucf101 | x3d_s ([onnx](https://drive.google.com/file/d/1gY5HGMWacbTQ5cK8MWdQgQ1lQM5VWRFb/view?usp=sharing)) | RLE-8 | 1.737 | +| ucf101 | x3d_m ([onnx](https://drive.google.com/file/d/1WaLjJYE0l_AiIrZw559Ile3xQza_wnWJ/view?usp=sharing)) | RLE-8 | 1.721 | +| brats2020 | unet3d (onnx) | RLE-8 | TBA | +| coco | yolov8n ([onnx](https://drive.google.com/file/d/1ghj2Da4HdkHSC-ADSe-JwvQbtwhUT_vT/view?usp=sharing)) | Huffman | 0.821 | +| camvid | unet-bilinear ([onnx](https://drive.google.com/file/d/1X6Ps_qcbP7vJLgNCkHbsHtWY6aSnG8es/view?usp=sharing)) | Huffman | 0.684 | +| cityscapes | unet ([onnx](https://drive.google.com/file/d/1d2v6VJI8B9DZY020Nq_AWQR0e8F9LH6A/view?usp=sharing)) | Huffman | 0.692 | +| ucf101 | x3d_s ([onnx](https://drive.google.com/file/d/19c6jwuHZVcfZXPpXMaGmaK9AsRXPO5lJ/view?usp=sharing)) | Huffman | 0.835 | +| ucf101 | x3d_m ([onnx](https://drive.google.com/file/d/1RQr0lEuROwO14F0WtObBUmuz8Na3Vci2/view?usp=sharing)) | Huffman | 0.833 | +| brats2020 | unet3d (onnx) | Huffman | TBA | ## Links to other repos * Optimizer: https://github.com/AlexMontgomerie/fpgaconvnet-optimiser; https://github.com/AlexMontgomerie/samo diff --git a/encoding/utils.py b/encoding/utils.py index b316e41..6054d7b 100644 --- a/encoding/utils.py +++ b/encoding/utils.py @@ -1,8 +1,12 @@ -import torch +from collections import defaultdict + import numpy as np +import torch + from quantization.utils import linear_quantize -def convert_to_int(x, word_length, scaling_factor, zero_point, transpose): + +def convert_to_int(x, word_length, scaling_factor, zero_point, transpose): if torch.cuda.is_available(): x = x.cuda() scaling_factor = scaling_factor.cuda() @@ -24,4 +28,15 @@ def avg_compress_ratio(encode_info): for v in encode_info.values(): compression_ratio += list(v.values()) compression_ratio = np.mean(compression_ratio) - return compression_ratio \ No newline at end of file + return compression_ratio + +def avg_compress_ratio_detailed(encode_info): + sum_dict = defaultdict(float) + count_dict = defaultdict(int) + + for v in encode_info.values(): + for key, value in v.items(): + sum_dict[key] += value + count_dict[key] += 1 + + return {key: sum_dict[key] / count_dict[key] for key in sum_dict} \ No newline at end of file