From 87913b73dba9b0e7d88d94298d303c7c7db3bcb3 Mon Sep 17 00:00:00 2001 From: Franck Galpin <franck.galpin@interdigital.com> Date: Fri, 22 Nov 2024 08:16:34 +0000 Subject: [PATCH] fix python scripts, model names, sadl version --- Makefile | 2 +- cfg/nn-based/vlop3.cfg | 3 + fixsadl.patch | 15 - sadl | 2 +- source/App/DecoderApp/DecAppCfg.cpp | 2 +- source/App/EncoderApp/EncAppCfg.cpp | 2 +- source/Lib/CommonLib/NNFilterSet1.cpp | 4 - .../NN_Filtering/LOP4/model/model.py | 285 +++++++++++++++--- .../LOP4/quantize/quantize_lop4.py | 227 +++++++------- .../NN_Filtering/VLOP3/model/model.py | 285 +++++++++++++++--- .../NN_Filtering/VLOP3/quantize/quantize.py | 149 ++++----- 11 files changed, 691 insertions(+), 285 deletions(-) create mode 100644 cfg/nn-based/vlop3.cfg delete mode 100644 fixsadl.patch diff --git a/Makefile b/Makefile index 0ed4aa783..83fb371cf 100644 --- a/Makefile +++ b/Makefile @@ -18,7 +18,7 @@ BUILD_SCRIPT := $(CURDIR)/cmake/CMakeBuild/bin/cmake.py TARGETS := CommonLib DecoderAnalyserApp DecoderAnalyserLib DecoderApp DecoderLib TARGETS += EncoderApp EncoderLib Utilities SEIRemovalApp StreamMergeApp -SADL_HASH := "v10" # hard coded because of windows $(shell git submodule status | grep sadl | cut -d' ' -f2) +SADL_HASH := "2088b26" # hard coded because of windows $(shell git submodule status | grep sadl | cut -d' ' -f2) ifeq ($(OS),Windows_NT) ifneq ($(MSYSTEM),) diff --git a/cfg/nn-based/vlop3.cfg b/cfg/nn-based/vlop3.cfg new file mode 100644 index 000000000..61457e8cf --- /dev/null +++ b/cfg/nn-based/vlop3.cfg @@ -0,0 +1,3 @@ +NnlfOption : 3 +NnlfModelName : models/nnlf_vlop3_model_int16.sadl + diff --git a/fixsadl.patch b/fixsadl.patch deleted file mode 100644 index 285e68819..000000000 --- a/fixsadl.patch +++ /dev/null @@ -1,15 +0,0 @@ -diff --git a/sadl/tensor.h b/sadl/tensor.h -index 98d7157..db524f4 100644 ---- a/sadl/tensor.h -+++ b/sadl/tensor.h -@@ -651,8 +651,8 @@ template<typename T> void Tensor<T>::resize(Dimensions d) - template<typename T> void Tensor<T>::resizeSparse(Dimensions d, int32_t sizeSparse, int32_t packedSparsitySize) - { - m_dims = d; -- int64_t m = m_dims.nbElements(); -- assert(m < kMaxSize); -+ //int64_t m = m_dims.nbElements(); -+ //assert(m < kMaxSize); - assert(sizeSparse > 0); - assert(packedSparsitySize > 0); - m_data_sparse.clear(); diff --git a/sadl b/sadl index 0854e53ac..ff7e50a0f 160000 --- a/sadl +++ b/sadl @@ -1 +1 @@ -Subproject commit 0854e53ac91cedc26fe0469a2ed930d62ba1fc4c +Subproject commit ff7e50a0f0432843b989dfd87cb359c1b540467b diff --git a/source/App/DecoderApp/DecAppCfg.cpp b/source/App/DecoderApp/DecAppCfg.cpp index 757ccc9ae..c30d5dbd1 100644 --- a/source/App/DecoderApp/DecAppCfg.cpp +++ b/source/App/DecoderApp/DecAppCfg.cpp @@ -81,7 +81,7 @@ bool DecAppCfg::parseCfg( int argc, char* argv[] ) ("DumpBasename", m_dumpBasename, string(""), "basename for data dumping\n") #endif #if NN_LF_UNIFIED - ("NnlfModelName", m_nnModel[NnModel::LOP_UNIFIED_FILTER], string("models/nnlf_lop3_model_int16.sadl"), "loop filter model name\n") + ("NnlfModelName", m_nnModel[NnModel::LOP_UNIFIED_FILTER], string("models/nnlf_lop4_model_int16.sadl"), "loop filter model name\n") #if NN_LF_FORCE_USE ( "NnlfUnifiedDebugOption", m_nnlfDebugOption, 0, "Option used to debug stage 1 model. 0: default, 1: apply only on I slice, 2: apply on all slices using I type as input" ) #endif diff --git a/source/App/EncoderApp/EncAppCfg.cpp b/source/App/EncoderApp/EncAppCfg.cpp index 0c683c0e0..5fd696d07 100644 --- a/source/App/EncoderApp/EncAppCfg.cpp +++ b/source/App/EncoderApp/EncAppCfg.cpp @@ -1188,7 +1188,7 @@ bool EncAppCfg::parseCfg( int argc, char* argv[] ) #else ("NnlfOption", m_nnlfOption, 1, "NN-based in-loop filter option (0:disable nnlf, 1: enable unified nnlf, [legacy: 10: enable nnlf-0, 11: enable nnlf-1, 12: enable nnlf-LC])") #endif - ("NnlfModelName", m_nnModel[NnModel::LOP_UNIFIED_FILTER], string("models/nnlf_lop3_model_int16.sadl"), "unified nnlf model name." ) + ("NnlfModelName", m_nnModel[NnModel::LOP_UNIFIED_FILTER], string("models/nnlf_lop4_model_int16.sadl"), "unified nnlf model name." ) #endif #if NN_LF_UNIFIED ( "NnlfBlockSize", m_nnlfBlockSize, 128u, "Base inference size of NN-based in-loop filter") diff --git a/source/Lib/CommonLib/NNFilterSet1.cpp b/source/Lib/CommonLib/NNFilterSet1.cpp index fcb3d9d70..b6b23c866 100644 --- a/source/Lib/CommonLib/NNFilterSet1.cpp +++ b/source/Lib/CommonLib/NNFilterSet1.cpp @@ -424,8 +424,6 @@ void NNFilterSet1::cnnFilterLumaBlock(Picture* pic, UnitArea inferArea, int extL int log2InputScale = 10; int log2QpScale = 6; - const int border_to_skip = 0; - if (border_to_skip>0) sadl::Tensor<float>::skip_border = true; // get model #if JVET_AC0177_MULTI_FRAME @@ -570,8 +568,6 @@ void NNFilterSet1::cnnFilterChromaBlock(Picture* pic, UnitArea inferArea, int ex int log2InputScale = 10; int log2QpScale = 6; - const int border_to_skip = 0; - if (border_to_skip>0) sadl::Tensor<float>::skip_border = true; // get model ModelData<T> &m = getModel<T>(inferArea.lheight(), inferArea.lwidth(), false, inter, inter ? m_interChroma : m_intraChroma); diff --git a/training/training_scripts/NN_Filtering/LOP4/model/model.py b/training/training_scripts/NN_Filtering/LOP4/model/model.py index 853f307e0..e4dee907a 100644 --- a/training/training_scripts/NN_Filtering/LOP4/model/model.py +++ b/training/training_scripts/NN_Filtering/LOP4/model/model.py @@ -122,7 +122,7 @@ class Conv(nn.Sequential): super(Conv, self).__init__(*modules) - + class MultiBranchModule(nn.Module): """A module representing multple, parallel branches. If the input is a list, each element in the list is fed into the corresponding branch, otherwise the input is fed into every branch. The outputs of each branch are then merged.""" @@ -148,8 +148,24 @@ class NewResBlock_separate_prelu(nn.Sequential): super().__init__() self.prelu = nn.PReLU() self.conv1_11 = Conv(C1, C, kernel_size=1, post_activation=None) - self.conv2_13 = Conv(C, C, kernel_size=3, post_activation=None, is_separable=True, is_horizontal=True, hidden_separable_channels=C21) - self.conv3_31 = Conv(C, C, kernel_size=3, post_activation=None, is_separable=True, is_horizontal=False, hidden_separable_channels=C21) + self.conv2_13 = Conv( + C, + C, + kernel_size=3, + post_activation=None, + is_separable=True, + is_horizontal=True, + hidden_separable_channels=C21, + ) + self.conv3_31 = Conv( + C, + C, + kernel_size=3, + post_activation=None, + is_separable=True, + is_horizontal=False, + hidden_separable_channels=C21, + ) self.conv4_11 = Conv(C, C1, kernel_size=1, post_activation=None) def forward(self, x: torch.Tensor) -> torch.Tensor: @@ -167,8 +183,26 @@ class NewResBlock_separate_prelu_crop(nn.Sequential): super().__init__() self.prelu = nn.PReLU() self.conv1_11 = Conv(C1, C, kernel_size=1, post_activation=None) - self.conv2_13 = Conv(C, C, kernel_size=3, padding=(0,0), post_activation=None, is_separable=True, is_horizontal=True, hidden_separable_channels=C21) - self.conv3_31 = Conv(C, C, kernel_size=3, padding=(0,0), post_activation=None, is_separable=True, is_horizontal=False, hidden_separable_channels=C21) + self.conv2_13 = Conv( + C, + C, + kernel_size=3, + padding=(0, 0), + post_activation=None, + is_separable=True, + is_horizontal=True, + hidden_separable_channels=C21, + ) + self.conv3_31 = Conv( + C, + C, + kernel_size=3, + padding=(0, 0), + post_activation=None, + is_separable=True, + is_horizontal=False, + hidden_separable_channels=C21, + ) self.conv4_11 = Conv(C, C1, kernel_size=1, post_activation=None) def forward(self, x: torch.Tensor) -> torch.Tensor: @@ -180,6 +214,7 @@ class NewResBlock_separate_prelu_crop(nn.Sequential): x5 = self.conv4_11(x4) return x5 + temp + class Slice_only_y(nn.Sequential): def __init__(self): super().__init__() @@ -194,8 +229,8 @@ class Slice_only_x(nn.Sequential): def forward(self, x: torch.Tensor) -> torch.Tensor: return x[:, :, :, 1:-1] - - + + class SplitLumaChromaBlocks(nn.Sequential): def __init__( self, @@ -218,26 +253,91 @@ class SplitLumaChromaBlocks(nn.Sequential): self.Y_no_lower_extra_crop = N_Y[1] self.split_y_path = nn.Sequential( Conv(C_Y, C1_Y, kernel_size=1, post_activation=None), - *[NewResBlock_separate_prelu(C_Y, C1_Y, C21_Y) for _ in range(N_Y[0]) ], # Start with full margin 36x36 - *[NewResBlock_separate_prelu_crop(C_Y, C1_Y, C21_Y) for _ in range(N_Y[1]) ], # Go down once to 34x34 - *[NewResBlock_separate_prelu(C_Y, C1_Y, C21_Y) for _ in range(N_Y[2]) ], # continue once at 34x34 - *[NewResBlock_separate_prelu_crop(C_Y, C1_Y, C21_Y) for _ in range(N_Y[3]) ], # go down once again to 32x32 - *[NewResBlock_separate_prelu(C_Y, C1_Y, C21_Y) for _ in range(N_Y[4]) ], # continue with 32x32 for the rest + *[ + NewResBlock_separate_prelu(C_Y, C1_Y, C21_Y) for _ in range(N_Y[0]) + ], # Start with full margin 36x36 + *[ + NewResBlock_separate_prelu_crop(C_Y, C1_Y, C21_Y) for _ in range(N_Y[1]) + ], # Go down once to 34x34 + *[ + NewResBlock_separate_prelu(C_Y, C1_Y, C21_Y) for _ in range(N_Y[2]) + ], # continue once at 34x34 + *[ + NewResBlock_separate_prelu_crop(C_Y, C1_Y, C21_Y) for _ in range(N_Y[3]) + ], # go down once again to 32x32 + *[ + NewResBlock_separate_prelu(C_Y, C1_Y, C21_Y) for _ in range(N_Y[4]) + ], # continue with 32x32 for the rest Conv(C1_Y, C_Y, kernel_size=1, post_activation=None), - - # If we need extra cropping, we will do padding = (0,0) here. - *[Conv(C_Y, C_Y, kernel_size=3, padding=(0,0), is_separable=True, is_horizontal=True, hidden_separable_channels=C21_Y, post_activation=None) for _ in range(self.Y_upper_extra_crop)], - *[Conv(C_Y, C_Y, kernel_size=3, padding=(0,0), is_separable=True, is_horizontal=False, hidden_separable_channels=C21_Y, post_activation=None) for _ in range(self.Y_upper_extra_crop)], + # If we need extra cropping, we will do padding = (0,0) here. + *[ + Conv( + C_Y, + C_Y, + kernel_size=3, + padding=(0, 0), + is_separable=True, + is_horizontal=True, + hidden_separable_channels=C21_Y, + post_activation=None, + ) + for _ in range(self.Y_upper_extra_crop) + ], + *[ + Conv( + C_Y, + C_Y, + kernel_size=3, + padding=(0, 0), + is_separable=True, + is_horizontal=False, + hidden_separable_channels=C21_Y, + post_activation=None, + ) + for _ in range(self.Y_upper_extra_crop) + ], # Otherwise, we will do padding = (1,1) (which is implicit if not specified). - *[Conv(C_Y, C_Y, kernel_size=3, is_separable=True, is_horizontal=True, hidden_separable_channels=C21_Y, post_activation=None) for _ in range(self.Y_no_upper_extra_crop)], - *[Conv(C_Y, C_Y, kernel_size=3, is_separable=True, is_horizontal=False, hidden_separable_channels=C21_Y, post_activation=None) for _ in range(self.Y_no_upper_extra_crop)], - + *[ + Conv( + C_Y, + C_Y, + kernel_size=3, + is_separable=True, + is_horizontal=True, + hidden_separable_channels=C21_Y, + post_activation=None, + ) + for _ in range(self.Y_no_upper_extra_crop) + ], + *[ + Conv( + C_Y, + C_Y, + kernel_size=3, + is_separable=True, + is_horizontal=False, + hidden_separable_channels=C21_Y, + post_activation=None, + ) + for _ in range(self.Y_no_upper_extra_crop) + ], Conv(C_Y, C_Y, kernel_size=1), - # If we need extra cropping, we will do padding = (0,0) here. - *[Conv(C_Y, output_channels_y, kernel_size=3, padding=(0,0), post_activation=None) for _ in range(self.Y_lower_extra_crop)], + *[ + Conv( + C_Y, + output_channels_y, + kernel_size=3, + padding=(0, 0), + post_activation=None, + ) + for _ in range(self.Y_lower_extra_crop) + ], # Otherwise, we will do padding = (1,1) (which is implicit if not specified). - *[Conv(C_Y, output_channels_y, kernel_size=3, post_activation=None) for _ in range(self.Y_no_lower_extra_crop)], + *[ + Conv(C_Y, output_channels_y, kernel_size=3, post_activation=None) + for _ in range(self.Y_no_lower_extra_crop) + ], ) self.UV_upper_extra_crop = 1 - N_UV[3] @@ -246,26 +346,93 @@ class SplitLumaChromaBlocks(nn.Sequential): self.UV_no_lower_extra_crop = N_UV[1] self.split_uv_path = nn.Sequential( Conv(C_UV, C1_UV, kernel_size=1, post_activation=None), - *[NewResBlock_separate_prelu(C_UV, C1_UV, C21_UV) for _ in range(N_UV[0])], # Start with full margin 36x36 - *[NewResBlock_separate_prelu_crop(C_UV, C1_UV, C21_UV) for _ in range(N_UV[1])], # Go down once to 34x34 - *[NewResBlock_separate_prelu(C_UV, C1_UV, C21_UV) for _ in range(N_UV[2])], # continue once at 34x34 - *[NewResBlock_separate_prelu_crop(C_UV, C1_UV, C21_UV) for _ in range(N_UV[3])], # go down once again to 32x32 - *[NewResBlock_separate_prelu(C_UV, C1_UV, C21_UV) for _ in range(N_UV[4])], # continue with 32x32 for the rest + *[ + NewResBlock_separate_prelu(C_UV, C1_UV, C21_UV) for _ in range(N_UV[0]) + ], # Start with full margin 36x36 + *[ + NewResBlock_separate_prelu_crop(C_UV, C1_UV, C21_UV) + for _ in range(N_UV[1]) + ], # Go down once to 34x34 + *[ + NewResBlock_separate_prelu(C_UV, C1_UV, C21_UV) for _ in range(N_UV[2]) + ], # continue once at 34x34 + *[ + NewResBlock_separate_prelu_crop(C_UV, C1_UV, C21_UV) + for _ in range(N_UV[3]) + ], # go down once again to 32x32 + *[ + NewResBlock_separate_prelu(C_UV, C1_UV, C21_UV) for _ in range(N_UV[4]) + ], # continue with 32x32 for the rest Conv(C1_UV, C_UV, kernel_size=1, post_activation=None), - # If we need extra cropping, we will do padding = (0,0) here. - *[Conv(C_UV, C_UV, kernel_size=3, padding=(0,0), is_separable=True, is_horizontal=True, hidden_separable_channels=C21_UV, post_activation=None) for _ in range(self.UV_upper_extra_crop)], - *[Conv(C_UV, C_UV, kernel_size=3, padding=(0,0), is_separable=True, is_horizontal=False, hidden_separable_channels=C21_UV, post_activation=None) for _ in range(self.UV_upper_extra_crop)], + *[ + Conv( + C_UV, + C_UV, + kernel_size=3, + padding=(0, 0), + is_separable=True, + is_horizontal=True, + hidden_separable_channels=C21_UV, + post_activation=None, + ) + for _ in range(self.UV_upper_extra_crop) + ], + *[ + Conv( + C_UV, + C_UV, + kernel_size=3, + padding=(0, 0), + is_separable=True, + is_horizontal=False, + hidden_separable_channels=C21_UV, + post_activation=None, + ) + for _ in range(self.UV_upper_extra_crop) + ], # Otherwise, we will do padding = (1,1) (which is implicit if not specified). - *[Conv(C_UV, C_UV, kernel_size=3, is_separable=True, is_horizontal=True, hidden_separable_channels=C21_UV, post_activation=None) for _ in range(self.UV_no_upper_extra_crop)], - *[Conv(C_UV, C_UV, kernel_size=3, is_separable=True, is_horizontal=False, hidden_separable_channels=C21_UV, post_activation=None) for _ in range(self.UV_no_upper_extra_crop)], - + *[ + Conv( + C_UV, + C_UV, + kernel_size=3, + is_separable=True, + is_horizontal=True, + hidden_separable_channels=C21_UV, + post_activation=None, + ) + for _ in range(self.UV_no_upper_extra_crop) + ], + *[ + Conv( + C_UV, + C_UV, + kernel_size=3, + is_separable=True, + is_horizontal=False, + hidden_separable_channels=C21_UV, + post_activation=None, + ) + for _ in range(self.UV_no_upper_extra_crop) + ], Conv(C_UV, C_UV, kernel_size=1), - # If we need extra cropping, we will do padding = (0,0) here. - *[Conv(C_UV, output_channels_uv, padding=(0,0), kernel_size=3, post_activation=None) for _ in range(self.UV_lower_extra_crop)], + *[ + Conv( + C_UV, + output_channels_uv, + padding=(0, 0), + kernel_size=3, + post_activation=None, + ) + for _ in range(self.UV_lower_extra_crop) + ], # Otherwise, we will do padding = (1,1) (which is implicit if not specified). - *[Conv(C_UV, output_channels_uv, kernel_size=3, post_activation=None) for _ in range(self.UV_no_lower_extra_crop)], + *[ + Conv(C_UV, output_channels_uv, kernel_size=3, post_activation=None) + for _ in range(self.UV_no_lower_extra_crop) + ], ) self.Cy = C_Y @@ -324,10 +491,39 @@ class SADLNet(nn.Sequential): ] ), Conv(sum(self.input_features), D6, kernel_size=1), - Conv(D6, D6, kernel_size=3, stride=2, post_activation=None, is_separable=True, is_horizontal=True, hidden_separable_channels=D6), - Conv(D6, D6, kernel_size=3, stride=2, post_activation=None, is_separable=True, is_horizontal=False, hidden_separable_channels=D6), + Conv( + D6, + D6, + kernel_size=3, + stride=2, + post_activation=None, + is_separable=True, + is_horizontal=True, + hidden_separable_channels=D6, + ), + Conv( + D6, + D6, + kernel_size=3, + stride=2, + post_activation=None, + is_separable=True, + is_horizontal=False, + hidden_separable_channels=D6, + ), Conv(D6, C_Y + C_UV, kernel_size=1), - SplitLumaChromaBlocks(N_Y, N_UV, C_Y, C_UV, C1_Y, C1_UV, C21_Y, C21_UV, output_channels_y, output_channels_uv), + SplitLumaChromaBlocks( + N_Y, + N_UV, + C_Y, + C_UV, + C1_Y, + C1_UV, + C21_Y, + C21_UV, + output_channels_y, + output_channels_uv, + ), ) def get_example_inputs( @@ -399,7 +595,14 @@ class Net(nn.Module): input_kernels ), "[ERROR] input size and kernels size not equal" self.input_channels = input_channels - sizes = [dct_ch + dct_ch // 2, dct_ch + dct_ch // 2, dct_ch + dct_ch // 2, 1, 1, dct_ch] + sizes = [ + dct_ch + dct_ch // 2, + dct_ch + dct_ch // 2, + dct_ch + dct_ch // 2, + 1, + 1, + dct_ch, + ] self.SADL_model = SADLNet( sizes, input_kernels, @@ -418,7 +621,7 @@ class Net(nn.Module): C21_Y, C21_UV, 4 * dct_ch, - 2 * dct_ch + 2 * dct_ch, ) self.chroma_upsampler = nn.Upsample(scale_factor=2, mode="nearest") self.dct_ch = dct_ch diff --git a/training/training_scripts/NN_Filtering/LOP4/quantize/quantize_lop4.py b/training/training_scripts/NN_Filtering/LOP4/quantize/quantize_lop4.py index a937bbe21..106e7718b 100644 --- a/training/training_scripts/NN_Filtering/LOP4/quantize/quantize_lop4.py +++ b/training/training_scripts/NN_Filtering/LOP4/quantize/quantize_lop4.py @@ -45,9 +45,7 @@ import json def parse_arguments(): parser = argparse.ArgumentParser() - parser.add_argument( - "--config", "-c", type=str, help="config file" - ) + parser.add_argument("--config", "-c", type=str, help="config file") parser.add_argument( "--stage", type=int, @@ -59,37 +57,37 @@ def parse_arguments(): def qfactor_gen(content): - output_q_str = '' + output_q_str = "" linenumber = 0 - q0 = '13' + q0 = "13" q_prev = q0 q_save_prev = q_prev for line in content: linenumber += 1 - if line[:11] == '[INFO] id: ': - layer_str = line.split(' ') + if line[:11] == "[INFO] id: ": + layer_str = line.split(" ") layer_id = layer_str[2] layer_name = layer_str[-1][:-1] - if layer_name == 'Placeholder': + if layer_name == "Placeholder": qq = q0 - print('Setting qq = q0 for', layer_name) - elif layer_name == 'Const': + print("Setting qq = q0 for", layer_name) + elif layer_name == "Const": next_layer = content[linenumber + 5] - layer_str2 = next_layer.split(' ') + layer_str2 = next_layer.split(" ") next_layer_name = layer_str2[-1][:-1] - if next_layer_name == 'Concat': - qq = '0' + if next_layer_name == "Concat": + qq = "0" else: node_name_str0 = content[linenumber] - if 'split_y_path.' in node_name_str0: - node_name_str = node_name_str0.split('split_y_path') - node_module_str = node_name_str[1].split('.')[1] + if "split_y_path." in node_name_str0: + node_name_str = node_name_str0.split("split_y_path") + node_module_str = node_name_str[1].split(".")[1] node_module_int = int(node_module_str) - if node_module_int ==0 : + if node_module_int == 0: # 35 SADL_model.5.split_y_path.0.0 len 45056 [1024] 0.00 [512] 0.00 [256] 0.00 [128] 0.00 [64] 0.14 [32] 0.95 [16] 5.76 [8]20.39 exceed 64 bit 10 - qq = '11' - elif node_module_int ==1 : + qq = "11" + elif node_module_int == 1: # 36 SADL_model.5.split_y_path.1.size # 37 SADL_model.5.split_y_path.1.sub # 38 SADL_model.5.split_y_path.1.size_1 @@ -101,8 +99,8 @@ def qfactor_gen(content): # 44 SADL_model.5.split_y_path.1.conv3_31.0 len 6272 [1024] 0.00 [512] 0.00 [256] 0.00 [128] 0.00 [64] 0.00 [32] 0.00 [16] 4.18 [8]19.89 exceed 16 bit 12 # 45 SADL_model.5.split_y_path.1.conv4_11.0 len 34496 [1024] 0.00 [512] 0.00 [256] 0.00 [128] 0.00 [64] 0.00 [32] 0.00 [16] 0.59 [8]11.18 exceed 16 bit 12 # 46 SADL_model.5.split_y_path.1.add len 34496 [1024] 0.00 [512] 0.00 [256] 0.00 [128] 0.00 [64] 0.12 [32] 1.57 [16] 9.91 [8]34.72 exceed 64 bit 10 - qq = '11' #or maybe 12. Also try prelu=11 or 10 and rest 12 or 11. - elif node_module_int ==2 : + qq = "11" # or maybe 12. Also try prelu=11 or 10 and rest 12 or 11. + elif node_module_int == 2: # 47 SADL_model.5.split_y_path.2.size # 48 SADL_model.5.split_y_path.2.sub # 49 SADL_model.5.split_y_path.2.size_1 @@ -114,177 +112,183 @@ def qfactor_gen(content): # 55 SADL_model.5.split_y_path.2.conv3_31.0 len 4608 [1024] 0.00 [512] 0.00 [256] 0.00 [128] 0.00 [64] 0.00 [32] 0.00 [16] 2.93 [8]32.10 exceed 16 bit 12 # 56 SADL_model.5.split_y_path.2.conv4_11.0 len 25344 [1024] 0.00 [512] 0.00 [256] 0.00 [128] 0.00 [64] 0.00 [32] 0.00 [16] 0.88 [8]14.56 exceed 32 bit 11 # 57 SADL_model.5.split_y_path.2.add len 25344 [1024] 0.00 [512] 0.00 [256] 0.00 [128] 0.00 [64] 0.15 [32] 1.82 [16]12.17 [8]36.14 exceed 64 bit 10 - qq = '11' #or maybe 12. Also try prelu=11 or 10 and rest 12 or 11 - elif node_module_int ==3 : + qq = "11" # or maybe 12. Also try prelu=11 or 10 and rest 12 or 11 + elif node_module_int == 3: # 58 SADL_model.5.split_y_path.3.prelu len 25344 [1024] 0.00 [512] 0.00 [256] 0.00 [128] 0.00 [64] 0.13 [32] 1.71 [16]11.62 [8]34.97 exceed 64 bit 10 # 59 SADL_model.5.split_y_path.3.conv1_11.0 len 4608 [1024] 0.00 [512] 0.00 [256] 0.00 [128] 0.00 [64] 0.07 [32] 3.41 [16] 8.99 [8]29.35 exceed 64 bit 10 # 60 SADL_model.5.split_y_path.3.conv2_13.0 len 4608 [1024] 0.00 [512] 0.00 [256] 0.00 [128] 0.00 [64] 0.00 [32] 1.65 [16] 7.92 [8]26.85 exceed 32 bit 11 # 61 SADL_model.5.split_y_path.3.conv3_31.0 len 4608 [1024] 0.00 [512] 0.00 [256] 0.00 [128] 0.00 [64] 0.00 [32] 0.07 [16] 5.47 [8]22.64 exceed 32 bit 11 # 62 SADL_model.5.split_y_path.3.conv4_11.0 len 25344 [1024] 0.00 [512] 0.00 [256] 0.00 [128] 0.00 [64] 0.00 [32] 0.01 [16] 0.90 [8] 8.56 exceed 32 bit 11 # 63 SADL_model.5.split_y_path.3.add len 25344 [1024] 0.00 [512] 0.00 [256] 0.00 [128] 0.00 [64] 0.13 [32] 3.11 [16]15.77 [8]39.54 exceed 64 bit 10 - qq = '11' - elif node_module_int ==4 : + qq = "11" + elif node_module_int == 4: # 64 SADL_model.5.split_y_path.4.prelu len 25344 [1024] 0.00 [512] 0.00 [256] 0.00 [128] 0.00 [64] 0.16 [32] 3.20 [16]16.14 [8]40.24 exceed 64 bit 10 # 65 SADL_model.5.split_y_path.4.conv1_11.0 len 4608 [1024] 0.00 [512] 0.00 [256] 0.00 [128] 0.00 [64] 2.54 [32] 4.82 [16]19.49 [8]46.19 exceed 64 bit 10 # 66 SADL_model.5.split_y_path.4.conv2_13.0 len 4608 [1024] 0.00 [512] 0.00 [256] 0.00 [128] 0.00 [64] 0.59 [32] 4.51 [16]18.25 [8]45.58 exceed 64 bit 10 # 67 SADL_model.5.split_y_path.4.conv3_31.0 len 4608 [1024] 0.00 [512] 0.00 [256] 0.00 [128] 0.00 [64] 0.00 [32] 5.14 [16]15.89 [8]44.87 exceed 32 bit 11 # 68 SADL_model.5.split_y_path.4.conv4_11.0 len 25344 [1024] 0.00 [512] 0.00 [256] 0.00 [128] 0.00 [64] 0.00 [32] 0.19 [16] 5.64 [8]31.95 exceed 32 bit 11 # 69 SADL_model.5.split_y_path.4.add len 25344 [1024] 0.00 [512] 0.00 [256] 0.00 [128] 0.00 [64] 0.11 [32] 3.71 [16]22.80 [8]52.47 exceed 64 bit 10 - qq = '10' #minskad - elif node_module_int ==5 : + qq = "10" # minskad + elif node_module_int == 5: # 70 SADL_model.5.split_y_path.5.prelu len 25344 [1024] 0.00 [512] 0.00 [256] 0.00 [128] 0.00 [64] 0.01 [32] 2.28 [16]13.31 [8]26.94 exceed 64 bit 10 # 71 SADL_model.5.split_y_path.5.conv1_11.0 len 4608 [1024] 0.00 [512] 0.00 [256] 0.00 [128] 0.00 [64] 0.07 [32] 5.71 [16]24.90 [8]44.69 exceed 64 bit 10 # 72 SADL_model.5.split_y_path.5.conv2_13.0 len 4608 [1024] 0.00 [512] 0.00 [256] 0.00 [128] 0.00 [64] 0.00 [32] 8.38 [16]26.46 [8]47.67 exceed 32 bit 11 # 73 SADL_model.5.split_y_path.5.conv3_31.0 len 4608 [1024] 0.00 [512] 0.00 [256] 0.00 [128] 0.00 [64] 0.00 [32]11.37 [16]26.76 [8]43.85 exceed 32 bit 11 # 74 SADL_model.5.split_y_path.5.conv4_11.0 len 25344 [1024] 0.00 [512] 0.00 [256] 0.00 [128] 0.00 [64] 0.00 [32] 0.73 [16]13.54 [8]39.33 exceed 32 bit 11 # 75 SADL_model.5.split_y_path.5.add len 25344 [1024] 0.00 [512] 0.00 [256] 0.00 [128] 0.00 [64] 0.23 [32] 6.98 [16]30.09 [8]56.88 exceed 64 bit 10 - qq = '11' - elif node_module_int ==6 : + qq = "11" + elif node_module_int == 6: # 76 SADL_model.5.split_y_path.6.prelu len 25344 [1024] 0.00 [512] 0.00 [256] 0.00 [128] 0.00 [64] 0.06 [32] 4.49 [16]18.49 [8]31.93 exceed 64 bit 10 # 77 SADL_model.5.split_y_path.6.conv1_11.0 len 4608 [1024] 0.00 [512] 0.00 [256] 0.00 [128] 0.00 [64] 0.00 [32] 5.10 [16]26.57 [8]49.19 exceed 32 bit 11 # 78 SADL_model.5.split_y_path.6.conv2_13.0 len 4608 [1024] 0.00 [512] 0.00 [256] 0.00 [128] 0.00 [64] 0.04 [32] 5.77 [16]30.24 [8]51.14 exceed 64 bit 10 # 79 SADL_model.5.split_y_path.6.conv3_31.0 len 4608 [1024] 0.00 [512] 0.00 [256] 0.00 [128] 0.00 [64] 0.04 [32] 7.58 [16]31.52 [8]49.34 exceed 64 bit 10 # 80 SADL_model.5.split_y_path.6.conv4_11.0 len 25344 [1024] 0.00 [512] 0.00 [256] 0.00 [128] 0.00 [64] 0.00 [32] 1.51 [16]13.79 [8]42.65 exceed 32 bit 11 # 81 SADL_model.5.split_y_path.6.add len 25344 [1024] 0.00 [512] 0.00 [256] 0.00 [128] 0.00 [64] 0.75 [32]12.88 [16]40.20 [8]65.95 exceed 64 bit 10 - qq = '11' - elif node_module_int ==7 : + qq = "11" + elif node_module_int == 7: # 82 SADL_model.5.split_y_path.7.prelu len 25344 [1024] 0.00 [512] 0.00 [256] 0.00 [128] 0.00 [64] 0.29 [32] 7.79 [16]22.67 [8]35.08 exceed 64 bit 10 # 83 SADL_model.5.split_y_path.7.conv1_11.0 len 4608 [1024] 0.00 [512] 0.00 [256] 0.00 [128] 0.00 [64] 3.56 [32]10.33 [16]29.52 [8]54.61 exceed 64 bit 10 # 84 SADL_model.5.split_y_path.7.conv2_13.0 len 4608 [1024] 0.00 [512] 0.00 [256] 0.00 [128] 0.00 [64] 4.19 [32]10.92 [16]33.15 [8]57.76 exceed 64 bit 10 # 85 SADL_model.5.split_y_path.7.conv3_31.0 len 4608 [1024] 0.00 [512] 0.00 [256] 0.00 [128] 0.00 [64] 3.34 [32]12.31 [16]35.84 [8]59.67 exceed 64 bit 10 # 86 SADL_model.5.split_y_path.7.conv4_11.0 len 25344 [1024] 0.00 [512] 0.00 [256] 0.00 [128] 0.00 [64] 0.34 [32] 9.21 [16]35.11 [8]62.59 exceed 64 bit 10 # 87 SADL_model.5.split_y_path.7.add len 25344 [1024] 0.00 [512] 0.00 [256] 0.00 [128] 0.02 [64] 3.73 [32]23.88 [16]51.23 [8]72.27 exceed 128 bit 9 - qq = '10' - elif node_module_int ==8 : + qq = "10" + elif node_module_int == 8: # 88 SADL_model.5.split_y_path.8.prelu len 25344 [1024] 0.00 [512] 0.00 [256] 0.00 [128] 0.02 [64] 3.68 [32]23.66 [16]51.01 [8]72.15 exceed 128 bit 9 # 89 SADL_model.5.split_y_path.8.conv1_11.0 len 4608 [1024] 0.00 [512] 0.00 [256] 0.00 [128] 3.08 [64] 5.30 [32]21.01 [16]45.37 [8]69.26 exceed 128 bit 9 # 90 SADL_model.5.split_y_path.8.conv2_13.0 len 4608 [1024] 0.00 [512] 0.00 [256] 0.00 [128] 1.93 [64] 4.97 [32]20.16 [16]42.54 [8]63.71 exceed 128 bit 9 # 91 SADL_model.5.split_y_path.8.conv3_31.0 len 4608 [1024] 0.00 [512] 0.00 [256] 0.00 [128] 0.11 [64] 4.95 [32]19.90 [16]39.64 [8]60.30 exceed 128 bit 9 # 92 SADL_model.5.split_y_path.8.conv4_11.0 len 25344 [1024] 0.00 [512] 0.00 [256] 0.00 [128] 0.00 [64] 1.68 [32]15.37 [16]40.81 [8]64.95 exceed 64 bit 10 # 93 SADL_model.5.split_y_path.8.add len 25344 [1024] 0.00 [512] 0.00 [256] 0.00 [128] 0.51 [64] 9.45 [32]34.87 [16]60.19 [8]78.80 exceed 128 bit 9 - qq = '9' - elif node_module_int ==9 : + qq = "9" + elif node_module_int == 9: # 94 SADL_model.5.split_y_path.9.prelu len 25344 [1024] 0.00 [512] 0.00 [256] 0.00 [128] 2.65 [64]24.04 [32]52.62 [16]73.08 [8]85.48 exceed 128 bit 9 # 95 SADL_model.5.split_y_path.9.conv1_11.0 len 4608 [1024] 0.00 [512] 0.00 [256] 1.28 [128] 3.32 [64]12.03 [32]31.60 [16]54.83 [8]73.15 exceed 256 bit 8 # 96 SADL_model.5.split_y_path.9.conv2_13.0 len 4608 [1024] 0.00 [512] 0.00 [256] 0.00 [128] 2.91 [64] 8.40 [32]25.70 [16]50.38 [8]69.76 exceed 128 bit 9 # 97 SADL_model.5.split_y_path.9.conv3_31.0 len 4608 [1024] 0.00 [512] 0.00 [256] 0.00 [128] 0.22 [64] 5.06 [32]19.82 [16]42.74 [8]63.84 exceed 128 bit 9 # 98 SADL_model.5.split_y_path.9.conv4_11.0 len 25344 [1024] 0.00 [512] 0.00 [256] 0.00 [128] 0.00 [64] 0.70 [32]11.60 [16]39.87 [8]66.43 exceed 64 bit 10 # 99 SADL_model.5.split_y_path.9.add len 25344 [1024] 0.00 [512] 0.00 [256] 0.00 [128] 0.61 [64]12.96 [32]42.79 [16]69.78 [8]85.22 exceed 128 bit 9 - qq = '9' # minskad - elif node_module_int ==10 : + qq = "9" # minskad + elif node_module_int == 10: # 100 SADL_model.5.split_y_path.10.prelu len 25344 [1024] 0.00 [512] 0.00 [256] 0.00 [128] 0.60 [64] 9.31 [32]24.48 [16]35.04 [8]51.07 exceed 128 bit 9 # 101 SADL_model.5.split_y_path.10.conv1_11.0 len 4608 [1024] 0.00 [512] 0.00 [256] 0.00 [128] 3.00 [64] 5.80 [32]21.34 [16]45.39 [8]67.61 exceed 128 bit 9 # 102 SADL_model.5.split_y_path.10.conv2_13.0 len 4608 [1024] 0.00 [512] 0.00 [256] 0.00 [128] 2.93 [64] 7.38 [32]25.31 [16]49.49 [8]70.44 exceed 128 bit 9 # 103 SADL_model.5.split_y_path.10.conv3_31.0 len 4608 [1024] 0.00 [512] 0.00 [256] 0.00 [128] 2.76 [64] 9.68 [32]28.80 [16]53.83 [8]73.61 exceed 128 bit 9 # 104 SADL_model.5.split_y_path.10.conv4_11.0 len 25344 [1024] 0.00 [512] 0.00 [256] 0.00 [128] 0.02 [64] 3.86 [32]23.43 [16]52.58 [8]73.89 exceed 128 bit 9 # 105 SADL_model.5.split_y_path.10.add len 25344 [1024] 0.00 [512] 0.00 [256] 0.00 [128] 1.59 [64]22.03 [32]51.45 [16]73.37 [8]86.02 exceed 128 bit 9 - qq = '9' # minskad - elif node_module_int ==11 : + qq = "9" # minskad + elif node_module_int == 11: # 106 SADL_model.5.split_y_path.11.prelu len 25344 [1024] 0.00 [512] 0.00 [256] 0.07 [128] 7.94 [64]36.46 [32]63.57 [16]80.01 [8]89.45 exceed 256 bit 8 # 107 SADL_model.5.split_y_path.11.conv1_11.0 len 4608 [1024] 0.00 [512] 0.00 [256] 0.07 [128] 9.59 [64]24.01 [32]41.96 [16]60.69 [8]73.41 exceed 256 bit 8 # 108 SADL_model.5.split_y_path.11.conv2_13.0 len 4608 [1024] 0.00 [512] 0.00 [256] 0.00 [128] 4.73 [64]21.79 [32]38.64 [16]58.02 [8]72.17 exceed 128 bit 9 # 109 SADL_model.5.split_y_path.11.conv3_31.0 len 4608 [1024] 0.00 [512] 0.00 [256] 0.00 [128] 1.80 [64]18.84 [32]35.45 [16]55.35 [8]69.70 exceed 128 bit 9 # 110 SADL_model.5.split_y_path.11.conv4_11.0 len 25344 [1024] 0.00 [512] 0.00 [256] 0.00 [128] 0.69 [64] 7.70 [32]29.72 [16]60.00 [8]80.87 exceed 128 bit 9 # 111 SADL_model.5.split_y_path.11.add len 25344 [1024] 0.00 [512] 0.00 [256] 0.25 [128] 6.65 [64]27.63 [32]52.13 [16]73.17 [8]86.38 exceed 256 bit 8 - qq = '9' - elif node_module_int ==12 : + qq = "9" + elif node_module_int == 12: # 112 SADL_model.5.split_y_path.12.prelu len 25344 [1024] 0.00 [512] 0.00 [256] 0.25 [128] 5.20 [64]23.71 [32]46.21 [16]68.53 [8]83.83 exceed 256 bit 8 # 113 SADL_model.5.split_y_path.12.conv1_11.0 len 4608 [1024] 0.00 [512] 0.00 [256] 2.87 [128] 5.93 [64]24.40 [32]49.92 [16]69.83 [8]81.64 exceed 256 bit 8 # 114 SADL_model.5.split_y_path.12.conv2_13.0 len 4608 [1024] 0.00 [512] 0.00 [256] 1.76 [128] 6.71 [64]26.52 [32]52.07 [16]70.68 [8]81.61 exceed 256 bit 8 # 115 SADL_model.5.split_y_path.12.conv3_31.0 len 4608 [1024] 0.00 [512] 0.00 [256] 0.41 [128] 8.20 [64]28.85 [32]53.29 [16]71.48 [8]81.75 exceed 256 bit 8 # 116 SADL_model.5.split_y_path.12.conv4_11.0 len 25344 [1024] 0.00 [512] 0.00 [256] 0.00 [128] 2.49 [64]20.81 [32]48.03 [16]71.36 [8]85.46 exceed 128 bit 9 # 117 SADL_model.5.split_y_path.12.add len 25344 [1024] 0.00 [512] 0.00 [256] 0.16 [128]10.86 [64]39.23 [32]65.59 [16]82.41 [8]90.97 exceed 256 bit 8 - qq = '8' # minskad - elif node_module_int ==13 : + qq = "8" # minskad + elif node_module_int == 13: # 118 SADL_model.5.split_y_path.13.prelu len 25344 [1024] 0.00 [512] 0.00 [256] 0.14 [128] 6.01 [64]19.81 [32]33.71 [16]54.24 [8]73.76 exceed 256 bit 8 # 119 SADL_model.5.split_y_path.13.conv1_11.0 len 4608 [1024] 0.00 [512] 0.00 [256] 0.37 [128] 8.07 [64]17.04 [32]41.70 [16]66.25 [8]80.68 exceed 256 bit 8 # 120 SADL_model.5.split_y_path.13.conv2_13.0 len 4608 [1024] 0.00 [512] 0.00 [256] 0.24 [128] 9.29 [64]21.10 [32]46.73 [16]68.81 [8]81.16 exceed 256 bit 8 # 121 SADL_model.5.split_y_path.13.conv3_31.0 len 4608 [1024] 0.00 [512] 0.00 [256] 1.22 [128]10.40 [64]27.22 [32]52.25 [16]71.52 [8]82.79 exceed 256 bit 8 # 122 SADL_model.5.split_y_path.13.conv4_11.0 len 25344 [1024] 0.00 [512] 0.00 [256] 0.06 [128] 4.83 [64]24.14 [32]55.16 [16]77.26 [8]88.55 exceed 256 bit 8 # 123 SADL_model.5.split_y_path.13.add len 25344 [1024] 0.00 [512] 0.00 [256] 0.83 [128]18.66 [64]52.06 [32]75.17 [16]87.59 [8]93.60 exceed 256 bit 8 - qq = '9' - elif node_module_int ==14 : + qq = "9" + elif node_module_int == 14: # 124 SADL_model.5.split_y_path.14.prelu len 25344 [1024] 0.00 [512] 0.00 [256] 0.59 [128]16.81 [64]49.17 [32]73.73 [16]86.81 [8]93.29 exceed 256 bit 8 # 125 SADL_model.5.split_y_path.14.conv1_11.0 len 4608 [1024] 0.00 [512] 0.04 [256] 6.01 [128] 9.59 [64]20.79 [32]47.30 [16]70.57 [8]84.00 exceed 512 bit 7 # 126 SADL_model.5.split_y_path.14.conv2_13.0 len 4608 [1024] 0.00 [512] 0.00 [256] 6.19 [128]10.31 [64]24.66 [32]51.23 [16]73.37 [8]85.04 exceed 256 bit 8 # 127 SADL_model.5.split_y_path.14.conv3_31.0 len 4608 [1024] 0.00 [512] 0.00 [256] 6.03 [128]11.33 [64]29.02 [32]55.81 [16]75.52 [8]86.15 exceed 256 bit 8 # 128 SADL_model.5.split_y_path.14.conv4_11.0 len 25344 [1024] 0.00 [512] 0.00 [256] 0.49 [128] 5.56 [64]35.73 [32]70.33 [16]86.02 [8]93.41 exceed 256 bit 8 # 129 SADL_model.5.split_y_path.14.add len 25344 [1024] 0.00 [512] 0.00 [256] 1.30 [128]20.90 [64]54.87 [32]76.70 [16]88.52 [8]94.26 exceed 256 bit 8 - qq = '8' - elif node_module_int ==15 : + qq = "8" + elif node_module_int == 15: # 130 SADL_model.5.split_y_path.15.prelu len 25344 [1024] 0.00 [512] 0.62 [256]12.04 [128]41.69 [64]69.22 [32]83.67 [16]91.73 [8]95.89 exceed 512 bit 7 # 131 SADL_model.5.split_y_path.15.conv1_11.0 len 4608 [1024] 1.56 [512] 3.13 [256] 3.45 [128]10.61 [64]29.43 [32]55.20 [16]74.56 [8]86.46 exceed 1024 bit 6 # 132 SADL_model.5.split_y_path.15.conv2_13.0 len 4608 [1024] 0.15 [512] 3.13 [256] 3.13 [128] 6.51 [64]15.35 [32]36.31 [16]58.69 [8]76.97 exceed 1024 bit 6 # 133 SADL_model.5.split_y_path.15.conv3_31.0 len 4608 [1024] 0.00 [512] 2.37 [256] 3.13 [128] 5.19 [64]10.27 [32]20.12 [16]40.76 [8]61.41 exceed 512 bit 7 # 134 SADL_model.5.split_y_path.15.conv4_11.0 len 25344 [1024] 0.00 [512] 0.00 [256] 0.01 [128]14.34 [64]48.19 [32]76.03 [16]89.79 [8]95.26 exceed 256 bit 8 # 135 SADL_model.5.split_y_path.15.add len 25344 [1024] 0.00 [512] 0.00 [256] 0.19 [128] 2.15 [64]18.03 [32]49.42 [16]73.32 [8]86.87 exceed 256 bit 8 - qq = '7' - elif node_module_int ==16 : + qq = "7" + elif node_module_int == 16: # 136 SADL_model.5.split_y_path.16.0 len 4608 [1024] 0.00 [512] 0.00 [256] 0.00 [128] 0.00 [64] 1.76 [32]16.04 [16]37.42 [8]61.82 exceed 64 bit 10 - qq = '10' - elif node_module_int ==17 : + qq = "10" + elif node_module_int == 17: # 137 SADL_model.5.split_y_path.17.0 len 4608 [1024] 0.00 [512] 0.00 [256] 0.00 [128] 0.00 [64] 0.00 [32] 0.00 [16] 0.43 [8] 9.94 exceed 16 bit 12 - qq = '13' - elif node_module_int ==18 : + qq = "13" + elif node_module_int == 18: # 138 SADL_model.5.split_y_path.18.0 len 4608 [1024] 0.00 [512] 0.00 [256] 0.00 [128] 0.00 [64] 0.00 [32] 0.00 [16] 0.00 [8] 0.00 - qq = '13' - elif node_module_int ==19 : + qq = "13" + elif node_module_int == 19: # 139 SADL_model.5.split_y_path.19.0 len 4608 [1024] 0.00 [512] 0.00 [256] 0.00 [128] 0.00 [64] 0.00 [32] 0.00 [16] 0.00 [8] 0.00 - qq = '13' - elif node_module_int ==20 : + qq = "13" + elif node_module_int == 20: # 141 SADL_model.5.split_y_path.20.0 len 2304 [1024] 0.00 [512] 0.00 [256] 0.00 [128] 0.00 [64] 0.00 [32] 0.00 [16] 0.00 [8] 0.00 - qq = '13' - else : + qq = "13" + else: qq = q0 print(layer_id, node_name_str0[:-1], node_module_str, qq) - elif 'branches' in node_name_str0 or \ - 'split_uv_path.5' in node_name_str0 or \ - 'split_uv_path.6' in node_name_str0 or \ - 'split_uv_path.7' in node_name_str0 or \ - 'split_uv_path.8' in node_name_str0 or \ - 'split_uv_path.9' in node_name_str0 : + elif ( + "branches" in node_name_str0 + or "split_uv_path.5" in node_name_str0 + or "split_uv_path.6" in node_name_str0 + or "split_uv_path.7" in node_name_str0 + or "split_uv_path.8" in node_name_str0 + or "split_uv_path.9" in node_name_str0 + ): qq = q0 - print(layer_id, node_name_str0[:-1], qq) - elif 'split_uv_path.0' in node_name_str0 or \ - 'split_uv_path.1' in node_name_str0 : - qq = '12' - print(layer_id, node_name_str0[:-1], qq) - elif 'split_uv' in node_name_str0 : - qq = '11' - print(layer_id, node_name_str0[:-1], qq) - elif next_layer_name == 'PReLU': + print(layer_id, node_name_str0[:-1], qq) + elif ( + "split_uv_path.0" in node_name_str0 + or "split_uv_path.1" in node_name_str0 + ): + qq = "12" + print(layer_id, node_name_str0[:-1], qq) + elif "split_uv" in node_name_str0: + qq = "11" + print(layer_id, node_name_str0[:-1], qq) + elif next_layer_name == "PReLU": qq = q_prev - if qq == '0': + if qq == "0": qq = q_save_prev - print('Overriding q_prev with', qq) - print(layer_id,'PReLU', qq) + print("Overriding q_prev with", qq) + print(layer_id, "PReLU", qq) else: - print('Other: node name =', node_name_str0) + print("Other: node name =", node_name_str0) # fuse layers - qq = '12' + qq = "12" print(layer_id, node_name_str0[:-1], qq) - elif layer_name == 'Conv2D': + elif layer_name == "Conv2D": q_save_prev = q_prev - qq = '0' - elif layer_name == 'Mul': - qq = '0' - elif layer_name == 'BiasAdd' or \ - layer_name == 'LeakyRelu' or \ - layer_name == 'Concat' or \ - layer_name == 'Shape' or \ - layer_name == 'Expand' or \ - layer_name == 'Add' or \ - layer_name == 'Transpose' or \ - layer_name == 'Reshape' or \ - layer_name == 'PReLU' or \ - layer_name == 'Slice' : + qq = "0" + elif layer_name == "Mul": + qq = "0" + elif ( + layer_name == "BiasAdd" + or layer_name == "LeakyRelu" + or layer_name == "Concat" + or layer_name == "Shape" + or layer_name == "Expand" + or layer_name == "Add" + or layer_name == "Transpose" + or layer_name == "Reshape" + or layer_name == "PReLU" + or layer_name == "Slice" + ): continue else: - print('Undecided layer name', layer_name) + print("Undecided layer name", layer_name) continue q_prev = qq - output_q_str = output_q_str + layer_id + ' ' + qq + ' ' + output_q_str = output_q_str + layer_id + " " + qq + " " return output_q_str @@ -299,20 +303,20 @@ if __name__ == "__main__": except Exception: quit("[ERROR] unable to open json config") - main_dir = config['binaries']['sadl_path'] - sadl_build_dir = os.path.join(main_dir, 'sample_test') - debug_cpp_dir = os.path.join(sadl_build_dir, 'debug_model') - float_sadl_dir = config[f"stage{stage}"]['conversion']['full_path_filename'] - int_sadl_dir = config[f"stage{stage}"]['quantize']['full_path_filename'] - - debug_log_dir = float_sadl_dir[:-5] + '_debug.txt' + main_dir = config["binaries"]["sadl_path"] + sadl_build_dir = os.path.join(main_dir, "sample_test") + debug_cpp_dir = os.path.join(sadl_build_dir, "debug_model") + float_sadl_dir = config[f"stage{stage}"]["conversion"]["full_path_filename"] + int_sadl_dir = config[f"stage{stage}"]["quantize"]["full_path_filename"] + + debug_log_dir = float_sadl_dir[:-5] + "_debug.txt" print(f"[INFO] SADL build dir {sadl_build_dir}") print(f"[INFO] input model {float_sadl_dir}") print(f"[INFO] debug_log_dir {debug_log_dir}") # debug float SADL model and get the log - cmd_debug = [debug_cpp_dir, float_sadl_dir, '>', debug_log_dir] + cmd_debug = [debug_cpp_dir, float_sadl_dir, ">", debug_log_dir] cmd_debug = " ".join(cmd_debug) print("Fore") os.system(cmd_debug) @@ -325,12 +329,17 @@ if __name__ == "__main__": file.close() # apply quantization - naive_quantizer_cpp_dir = os.path.join(sadl_build_dir, 'naive_quantization') - cmd_quantize = ["echo '", output_q_str , " ' | ", - naive_quantizer_cpp_dir, - float_sadl_dir, - int_sadl_dir, ";"] + naive_quantizer_cpp_dir = os.path.join(sadl_build_dir, "naive_quantization") + cmd_quantize = [ + "echo '", + output_q_str, + " ' | ", + naive_quantizer_cpp_dir, + float_sadl_dir, + int_sadl_dir, + ";", + ] cmd_quantize = " ".join(cmd_quantize) - print('Executing the following command:') + print("Executing the following command:") print(cmd_quantize) os.system(cmd_quantize) diff --git a/training/training_scripts/NN_Filtering/VLOP3/model/model.py b/training/training_scripts/NN_Filtering/VLOP3/model/model.py index 853f307e0..e4dee907a 100644 --- a/training/training_scripts/NN_Filtering/VLOP3/model/model.py +++ b/training/training_scripts/NN_Filtering/VLOP3/model/model.py @@ -122,7 +122,7 @@ class Conv(nn.Sequential): super(Conv, self).__init__(*modules) - + class MultiBranchModule(nn.Module): """A module representing multple, parallel branches. If the input is a list, each element in the list is fed into the corresponding branch, otherwise the input is fed into every branch. The outputs of each branch are then merged.""" @@ -148,8 +148,24 @@ class NewResBlock_separate_prelu(nn.Sequential): super().__init__() self.prelu = nn.PReLU() self.conv1_11 = Conv(C1, C, kernel_size=1, post_activation=None) - self.conv2_13 = Conv(C, C, kernel_size=3, post_activation=None, is_separable=True, is_horizontal=True, hidden_separable_channels=C21) - self.conv3_31 = Conv(C, C, kernel_size=3, post_activation=None, is_separable=True, is_horizontal=False, hidden_separable_channels=C21) + self.conv2_13 = Conv( + C, + C, + kernel_size=3, + post_activation=None, + is_separable=True, + is_horizontal=True, + hidden_separable_channels=C21, + ) + self.conv3_31 = Conv( + C, + C, + kernel_size=3, + post_activation=None, + is_separable=True, + is_horizontal=False, + hidden_separable_channels=C21, + ) self.conv4_11 = Conv(C, C1, kernel_size=1, post_activation=None) def forward(self, x: torch.Tensor) -> torch.Tensor: @@ -167,8 +183,26 @@ class NewResBlock_separate_prelu_crop(nn.Sequential): super().__init__() self.prelu = nn.PReLU() self.conv1_11 = Conv(C1, C, kernel_size=1, post_activation=None) - self.conv2_13 = Conv(C, C, kernel_size=3, padding=(0,0), post_activation=None, is_separable=True, is_horizontal=True, hidden_separable_channels=C21) - self.conv3_31 = Conv(C, C, kernel_size=3, padding=(0,0), post_activation=None, is_separable=True, is_horizontal=False, hidden_separable_channels=C21) + self.conv2_13 = Conv( + C, + C, + kernel_size=3, + padding=(0, 0), + post_activation=None, + is_separable=True, + is_horizontal=True, + hidden_separable_channels=C21, + ) + self.conv3_31 = Conv( + C, + C, + kernel_size=3, + padding=(0, 0), + post_activation=None, + is_separable=True, + is_horizontal=False, + hidden_separable_channels=C21, + ) self.conv4_11 = Conv(C, C1, kernel_size=1, post_activation=None) def forward(self, x: torch.Tensor) -> torch.Tensor: @@ -180,6 +214,7 @@ class NewResBlock_separate_prelu_crop(nn.Sequential): x5 = self.conv4_11(x4) return x5 + temp + class Slice_only_y(nn.Sequential): def __init__(self): super().__init__() @@ -194,8 +229,8 @@ class Slice_only_x(nn.Sequential): def forward(self, x: torch.Tensor) -> torch.Tensor: return x[:, :, :, 1:-1] - - + + class SplitLumaChromaBlocks(nn.Sequential): def __init__( self, @@ -218,26 +253,91 @@ class SplitLumaChromaBlocks(nn.Sequential): self.Y_no_lower_extra_crop = N_Y[1] self.split_y_path = nn.Sequential( Conv(C_Y, C1_Y, kernel_size=1, post_activation=None), - *[NewResBlock_separate_prelu(C_Y, C1_Y, C21_Y) for _ in range(N_Y[0]) ], # Start with full margin 36x36 - *[NewResBlock_separate_prelu_crop(C_Y, C1_Y, C21_Y) for _ in range(N_Y[1]) ], # Go down once to 34x34 - *[NewResBlock_separate_prelu(C_Y, C1_Y, C21_Y) for _ in range(N_Y[2]) ], # continue once at 34x34 - *[NewResBlock_separate_prelu_crop(C_Y, C1_Y, C21_Y) for _ in range(N_Y[3]) ], # go down once again to 32x32 - *[NewResBlock_separate_prelu(C_Y, C1_Y, C21_Y) for _ in range(N_Y[4]) ], # continue with 32x32 for the rest + *[ + NewResBlock_separate_prelu(C_Y, C1_Y, C21_Y) for _ in range(N_Y[0]) + ], # Start with full margin 36x36 + *[ + NewResBlock_separate_prelu_crop(C_Y, C1_Y, C21_Y) for _ in range(N_Y[1]) + ], # Go down once to 34x34 + *[ + NewResBlock_separate_prelu(C_Y, C1_Y, C21_Y) for _ in range(N_Y[2]) + ], # continue once at 34x34 + *[ + NewResBlock_separate_prelu_crop(C_Y, C1_Y, C21_Y) for _ in range(N_Y[3]) + ], # go down once again to 32x32 + *[ + NewResBlock_separate_prelu(C_Y, C1_Y, C21_Y) for _ in range(N_Y[4]) + ], # continue with 32x32 for the rest Conv(C1_Y, C_Y, kernel_size=1, post_activation=None), - - # If we need extra cropping, we will do padding = (0,0) here. - *[Conv(C_Y, C_Y, kernel_size=3, padding=(0,0), is_separable=True, is_horizontal=True, hidden_separable_channels=C21_Y, post_activation=None) for _ in range(self.Y_upper_extra_crop)], - *[Conv(C_Y, C_Y, kernel_size=3, padding=(0,0), is_separable=True, is_horizontal=False, hidden_separable_channels=C21_Y, post_activation=None) for _ in range(self.Y_upper_extra_crop)], + # If we need extra cropping, we will do padding = (0,0) here. + *[ + Conv( + C_Y, + C_Y, + kernel_size=3, + padding=(0, 0), + is_separable=True, + is_horizontal=True, + hidden_separable_channels=C21_Y, + post_activation=None, + ) + for _ in range(self.Y_upper_extra_crop) + ], + *[ + Conv( + C_Y, + C_Y, + kernel_size=3, + padding=(0, 0), + is_separable=True, + is_horizontal=False, + hidden_separable_channels=C21_Y, + post_activation=None, + ) + for _ in range(self.Y_upper_extra_crop) + ], # Otherwise, we will do padding = (1,1) (which is implicit if not specified). - *[Conv(C_Y, C_Y, kernel_size=3, is_separable=True, is_horizontal=True, hidden_separable_channels=C21_Y, post_activation=None) for _ in range(self.Y_no_upper_extra_crop)], - *[Conv(C_Y, C_Y, kernel_size=3, is_separable=True, is_horizontal=False, hidden_separable_channels=C21_Y, post_activation=None) for _ in range(self.Y_no_upper_extra_crop)], - + *[ + Conv( + C_Y, + C_Y, + kernel_size=3, + is_separable=True, + is_horizontal=True, + hidden_separable_channels=C21_Y, + post_activation=None, + ) + for _ in range(self.Y_no_upper_extra_crop) + ], + *[ + Conv( + C_Y, + C_Y, + kernel_size=3, + is_separable=True, + is_horizontal=False, + hidden_separable_channels=C21_Y, + post_activation=None, + ) + for _ in range(self.Y_no_upper_extra_crop) + ], Conv(C_Y, C_Y, kernel_size=1), - # If we need extra cropping, we will do padding = (0,0) here. - *[Conv(C_Y, output_channels_y, kernel_size=3, padding=(0,0), post_activation=None) for _ in range(self.Y_lower_extra_crop)], + *[ + Conv( + C_Y, + output_channels_y, + kernel_size=3, + padding=(0, 0), + post_activation=None, + ) + for _ in range(self.Y_lower_extra_crop) + ], # Otherwise, we will do padding = (1,1) (which is implicit if not specified). - *[Conv(C_Y, output_channels_y, kernel_size=3, post_activation=None) for _ in range(self.Y_no_lower_extra_crop)], + *[ + Conv(C_Y, output_channels_y, kernel_size=3, post_activation=None) + for _ in range(self.Y_no_lower_extra_crop) + ], ) self.UV_upper_extra_crop = 1 - N_UV[3] @@ -246,26 +346,93 @@ class SplitLumaChromaBlocks(nn.Sequential): self.UV_no_lower_extra_crop = N_UV[1] self.split_uv_path = nn.Sequential( Conv(C_UV, C1_UV, kernel_size=1, post_activation=None), - *[NewResBlock_separate_prelu(C_UV, C1_UV, C21_UV) for _ in range(N_UV[0])], # Start with full margin 36x36 - *[NewResBlock_separate_prelu_crop(C_UV, C1_UV, C21_UV) for _ in range(N_UV[1])], # Go down once to 34x34 - *[NewResBlock_separate_prelu(C_UV, C1_UV, C21_UV) for _ in range(N_UV[2])], # continue once at 34x34 - *[NewResBlock_separate_prelu_crop(C_UV, C1_UV, C21_UV) for _ in range(N_UV[3])], # go down once again to 32x32 - *[NewResBlock_separate_prelu(C_UV, C1_UV, C21_UV) for _ in range(N_UV[4])], # continue with 32x32 for the rest + *[ + NewResBlock_separate_prelu(C_UV, C1_UV, C21_UV) for _ in range(N_UV[0]) + ], # Start with full margin 36x36 + *[ + NewResBlock_separate_prelu_crop(C_UV, C1_UV, C21_UV) + for _ in range(N_UV[1]) + ], # Go down once to 34x34 + *[ + NewResBlock_separate_prelu(C_UV, C1_UV, C21_UV) for _ in range(N_UV[2]) + ], # continue once at 34x34 + *[ + NewResBlock_separate_prelu_crop(C_UV, C1_UV, C21_UV) + for _ in range(N_UV[3]) + ], # go down once again to 32x32 + *[ + NewResBlock_separate_prelu(C_UV, C1_UV, C21_UV) for _ in range(N_UV[4]) + ], # continue with 32x32 for the rest Conv(C1_UV, C_UV, kernel_size=1, post_activation=None), - # If we need extra cropping, we will do padding = (0,0) here. - *[Conv(C_UV, C_UV, kernel_size=3, padding=(0,0), is_separable=True, is_horizontal=True, hidden_separable_channels=C21_UV, post_activation=None) for _ in range(self.UV_upper_extra_crop)], - *[Conv(C_UV, C_UV, kernel_size=3, padding=(0,0), is_separable=True, is_horizontal=False, hidden_separable_channels=C21_UV, post_activation=None) for _ in range(self.UV_upper_extra_crop)], + *[ + Conv( + C_UV, + C_UV, + kernel_size=3, + padding=(0, 0), + is_separable=True, + is_horizontal=True, + hidden_separable_channels=C21_UV, + post_activation=None, + ) + for _ in range(self.UV_upper_extra_crop) + ], + *[ + Conv( + C_UV, + C_UV, + kernel_size=3, + padding=(0, 0), + is_separable=True, + is_horizontal=False, + hidden_separable_channels=C21_UV, + post_activation=None, + ) + for _ in range(self.UV_upper_extra_crop) + ], # Otherwise, we will do padding = (1,1) (which is implicit if not specified). - *[Conv(C_UV, C_UV, kernel_size=3, is_separable=True, is_horizontal=True, hidden_separable_channels=C21_UV, post_activation=None) for _ in range(self.UV_no_upper_extra_crop)], - *[Conv(C_UV, C_UV, kernel_size=3, is_separable=True, is_horizontal=False, hidden_separable_channels=C21_UV, post_activation=None) for _ in range(self.UV_no_upper_extra_crop)], - + *[ + Conv( + C_UV, + C_UV, + kernel_size=3, + is_separable=True, + is_horizontal=True, + hidden_separable_channels=C21_UV, + post_activation=None, + ) + for _ in range(self.UV_no_upper_extra_crop) + ], + *[ + Conv( + C_UV, + C_UV, + kernel_size=3, + is_separable=True, + is_horizontal=False, + hidden_separable_channels=C21_UV, + post_activation=None, + ) + for _ in range(self.UV_no_upper_extra_crop) + ], Conv(C_UV, C_UV, kernel_size=1), - # If we need extra cropping, we will do padding = (0,0) here. - *[Conv(C_UV, output_channels_uv, padding=(0,0), kernel_size=3, post_activation=None) for _ in range(self.UV_lower_extra_crop)], + *[ + Conv( + C_UV, + output_channels_uv, + padding=(0, 0), + kernel_size=3, + post_activation=None, + ) + for _ in range(self.UV_lower_extra_crop) + ], # Otherwise, we will do padding = (1,1) (which is implicit if not specified). - *[Conv(C_UV, output_channels_uv, kernel_size=3, post_activation=None) for _ in range(self.UV_no_lower_extra_crop)], + *[ + Conv(C_UV, output_channels_uv, kernel_size=3, post_activation=None) + for _ in range(self.UV_no_lower_extra_crop) + ], ) self.Cy = C_Y @@ -324,10 +491,39 @@ class SADLNet(nn.Sequential): ] ), Conv(sum(self.input_features), D6, kernel_size=1), - Conv(D6, D6, kernel_size=3, stride=2, post_activation=None, is_separable=True, is_horizontal=True, hidden_separable_channels=D6), - Conv(D6, D6, kernel_size=3, stride=2, post_activation=None, is_separable=True, is_horizontal=False, hidden_separable_channels=D6), + Conv( + D6, + D6, + kernel_size=3, + stride=2, + post_activation=None, + is_separable=True, + is_horizontal=True, + hidden_separable_channels=D6, + ), + Conv( + D6, + D6, + kernel_size=3, + stride=2, + post_activation=None, + is_separable=True, + is_horizontal=False, + hidden_separable_channels=D6, + ), Conv(D6, C_Y + C_UV, kernel_size=1), - SplitLumaChromaBlocks(N_Y, N_UV, C_Y, C_UV, C1_Y, C1_UV, C21_Y, C21_UV, output_channels_y, output_channels_uv), + SplitLumaChromaBlocks( + N_Y, + N_UV, + C_Y, + C_UV, + C1_Y, + C1_UV, + C21_Y, + C21_UV, + output_channels_y, + output_channels_uv, + ), ) def get_example_inputs( @@ -399,7 +595,14 @@ class Net(nn.Module): input_kernels ), "[ERROR] input size and kernels size not equal" self.input_channels = input_channels - sizes = [dct_ch + dct_ch // 2, dct_ch + dct_ch // 2, dct_ch + dct_ch // 2, 1, 1, dct_ch] + sizes = [ + dct_ch + dct_ch // 2, + dct_ch + dct_ch // 2, + dct_ch + dct_ch // 2, + 1, + 1, + dct_ch, + ] self.SADL_model = SADLNet( sizes, input_kernels, @@ -418,7 +621,7 @@ class Net(nn.Module): C21_Y, C21_UV, 4 * dct_ch, - 2 * dct_ch + 2 * dct_ch, ) self.chroma_upsampler = nn.Upsample(scale_factor=2, mode="nearest") self.dct_ch = dct_ch diff --git a/training/training_scripts/NN_Filtering/VLOP3/quantize/quantize.py b/training/training_scripts/NN_Filtering/VLOP3/quantize/quantize.py index d2782acae..835214607 100755 --- a/training/training_scripts/NN_Filtering/VLOP3/quantize/quantize.py +++ b/training/training_scripts/NN_Filtering/VLOP3/quantize/quantize.py @@ -46,9 +46,7 @@ import json def parse_arguments(): parser = argparse.ArgumentParser() - parser.add_argument( - "--config", "-c", type=str, help="config file" - ) + parser.add_argument("--config", "-c", type=str, help="config file") parser.add_argument( "--stage", type=int, @@ -68,47 +66,47 @@ def parse_arguments(): def qfactor_gen(content): - output_q_str = '' + output_q_str = "" linenumber = 0 - q0 = '13' + q0 = "13" q_prev = q0 for line in content: linenumber += 1 - if line[:11] == '[INFO] id: ': - layer_str = line.split(' ') + if line[:11] == "[INFO] id: ": + layer_str = line.split(" ") layer_id = layer_str[2] layer_name = layer_str[-1][:-1] - if layer_name == 'Placeholder': + if layer_name == "Placeholder": qq = q0 - elif layer_name == 'Const': + elif layer_name == "Const": next_layer = content[linenumber + 5] - layer_str2 = next_layer.split(' ') + layer_str2 = next_layer.split(" ") next_layer_name = layer_str2[-1][:-1] - if next_layer_name == 'Concat': - qq = '0' + if next_layer_name == "Concat": + qq = "0" else: node_name_str0 = content[linenumber] - if 'split_y_path.' in node_name_str0: - node_name_str = node_name_str0.split('split_y_path') - node_module_str = node_name_str[1].split('.')[1] + if "split_y_path." in node_name_str0: + node_name_str = node_name_str0.split("split_y_path") + node_module_str = node_name_str[1].split(".")[1] node_module_int = int(node_module_str) - if node_module_int <= 2 : - qq = '11' + if node_module_int <= 2: + qq = "11" elif node_module_int > 2 and node_module_int <= 4: - qq = '10' - #elif node_module_int > 4 and node_module_int <= 6: + qq = "10" + # elif node_module_int > 4 and node_module_int <= 6: # qq = '9' - #elif node_module_int == 7: + # elif node_module_int == 7: # qq = '11' elif node_module_int > 4 and node_module_int <= 7: - qq = '9' + qq = "9" elif node_module_int == 8: - qq = '11' - else : + qq = "11" + else: qq = q0 print(layer_id, node_name_str0[:-1], node_module_str, qq) - #elif 'branches' in node_name_str0 or \ + # elif 'branches' in node_name_str0 or \ # 'split_uv_path.2' in node_name_str0 or \ # 'split_uv_path.3' in node_name_str0 or \ # 'split_uv_path.4' in node_name_str0 or \ @@ -116,56 +114,60 @@ def qfactor_gen(content): # 'split_uv_path.6' in node_name_str0 : # qq = q0 # print(layer_id, node_name_str0[:-1], qq) - #elif 'split_uv_path.0' in node_name_str0: + # elif 'split_uv_path.0' in node_name_str0: # qq = '12' # print(layer_id, node_name_str0[:-1], qq) - #elif 'split_uv' in node_name_str0 : + # elif 'split_uv' in node_name_str0 : # qq = '11' # print(layer_id, node_name_str0[:-1], qq) - elif 'branches' in node_name_str0 or \ - 'split_uv_path.0' in node_name_str0 or \ - 'split_uv_path.1' in node_name_str0 or \ - 'split_uv_path.2' in node_name_str0 or \ - 'split_uv_path.3' in node_name_str0 or \ - 'split_uv_path.4' in node_name_str0 or \ - 'split_uv_path.5' in node_name_str0 or \ - 'split_uv_path.6' in node_name_str0 or \ - 'split_uv_path.7' in node_name_str0 or \ - 'split_uv_path.8' in node_name_str0 or \ - 'split_uv_path.9' in node_name_str0 or \ - 'split_uv_path.10' in node_name_str0 : + elif ( + "branches" in node_name_str0 + or "split_uv_path.0" in node_name_str0 + or "split_uv_path.1" in node_name_str0 + or "split_uv_path.2" in node_name_str0 + or "split_uv_path.3" in node_name_str0 + or "split_uv_path.4" in node_name_str0 + or "split_uv_path.5" in node_name_str0 + or "split_uv_path.6" in node_name_str0 + or "split_uv_path.7" in node_name_str0 + or "split_uv_path.8" in node_name_str0 + or "split_uv_path.9" in node_name_str0 + or "split_uv_path.10" in node_name_str0 + ): qq = q0 print(layer_id, node_name_str0[:-1], qq) - elif next_layer_name == 'PReLU': + elif next_layer_name == "PReLU": qq = q_prev - if qq == '0': - print('PReLU quantization is wrong. ', qq) - print(layer_id, 'PReLU', qq) + if qq == "0": + print("PReLU quantization is wrong. ", qq) + print(layer_id, "PReLU", qq) else: # fuse layers - qq = '12' + qq = "12" print(layer_id, node_name_str0[:-1], qq) - elif layer_name == 'Conv2D': - qq = '0' - elif layer_name == 'Mul': - qq = '0' - elif layer_name == 'BiasAdd' or \ - layer_name == 'LeakyRelu' or \ - layer_name == 'Concat' or \ - layer_name == 'Shape' or \ - layer_name == 'Expand' or \ - layer_name == 'Add' or \ - layer_name == 'Transpose' or \ - layer_name == 'Reshape' or \ - layer_name == 'PReLU' or \ - layer_name == 'Slice' : + elif layer_name == "Conv2D": + qq = "0" + elif layer_name == "Mul": + qq = "0" + elif ( + layer_name == "BiasAdd" + or layer_name == "LeakyRelu" + or layer_name == "Concat" + or layer_name == "Shape" + or layer_name == "Expand" + or layer_name == "Add" + or layer_name == "Transpose" + or layer_name == "Reshape" + or layer_name == "PReLU" + or layer_name == "Slice" + ): continue else: - print('Undecided layer name', layer_name) + print("Undecided layer name", layer_name) continue q_prev = qq - output_q_str = output_q_str + layer_id + ' ' + qq + ' ' + output_q_str = output_q_str + layer_id + " " + qq + " " return output_q_str @@ -181,24 +183,24 @@ if __name__ == "__main__": except Exception: quit("[ERROR] unable to open json config") - main_dir = config['binaries']['sadl_path'] - sadl_build_dir = os.path.join(main_dir, 'sample_test') - debug_cpp_dir = os.path.join(sadl_build_dir, 'debug_model') + main_dir = config["binaries"]["sadl_path"] + sadl_build_dir = os.path.join(main_dir, "sample_test") + debug_cpp_dir = os.path.join(sadl_build_dir, "debug_model") if args["float_model"]: float_sadl_dir = args["float_model"] else: - float_sadl_dir = config[f"stage{stage}"]['conversion']['full_path_filename'] + float_sadl_dir = config[f"stage{stage}"]["conversion"]["full_path_filename"] if args["int_model"]: int_sadl_dir = args["int_model"] else: - int_sadl_dir = config[f"stage{stage}"]['quantize']['full_path_filename'] - debug_log_dir = float_sadl_dir[:-5] + '_debug.txt' + int_sadl_dir = config[f"stage{stage}"]["quantize"]["full_path_filename"] + debug_log_dir = float_sadl_dir[:-5] + "_debug.txt" print(f"[INFO] SADL build dir {sadl_build_dir}") print(f"[INFO] input model {float_sadl_dir}") # debug float SADL model and get the log - cmd_debug = [debug_cpp_dir, float_sadl_dir, '>', debug_log_dir] + cmd_debug = [debug_cpp_dir, float_sadl_dir, ">", debug_log_dir] cmd_debug = " ".join(cmd_debug) os.system(cmd_debug) @@ -209,10 +211,15 @@ if __name__ == "__main__": file.close() # apply quantization - naive_quantizer_cpp_dir = os.path.join(sadl_build_dir, 'naive_quantization') - cmd_quantize = ["echo '", output_q_str , " ' | ", - naive_quantizer_cpp_dir, - float_sadl_dir, - int_sadl_dir, ";"] + naive_quantizer_cpp_dir = os.path.join(sadl_build_dir, "naive_quantization") + cmd_quantize = [ + "echo '", + output_q_str, + " ' | ", + naive_quantizer_cpp_dir, + float_sadl_dir, + int_sadl_dir, + ";", + ] cmd_quantize = " ".join(cmd_quantize) os.system(cmd_quantize) -- GitLab