From 7dcec5145d272136c4b364ddb3307d70b351e2b2 Mon Sep 17 00:00:00 2001 From: Yongjoo Ahn Date: Mon, 29 Mar 2021 20:16:44 +0900 Subject: [PATCH] [test/tensor_transform] Add testcases for stand - Add SSAT testcases for stand: default and dc-average Signed-off-by: Yongjoo Ahn --- tests/transform_stand/checkResult.py | 4 ++-- tests/transform_stand/generateTest.py | 27 ++++++++++++++++++++++++--- tests/transform_stand/runTest.sh | 20 +++++++++++++++++++- 3 files changed, 45 insertions(+), 6 deletions(-) diff --git a/tests/transform_stand/checkResult.py b/tests/transform_stand/checkResult.py index e844d67..6ef3b84 100644 --- a/tests/transform_stand/checkResult.py +++ b/tests/transform_stand/checkResult.py @@ -17,7 +17,7 @@ import struct ## # @brief Check typecast from typea to typeb with file fna/fnb # -def testStandardization (fna, fnb, typeasize, typebsize,typeapack, typebpack): +def testStandardization (fna, fnb, typeasize, typebsize, typeapack, typebpack): lena = len(fna) lenb = len(fnb) @@ -32,7 +32,7 @@ def testStandardization (fna, fnb, typeasize, typebsize,typeapack, typebpack): vala = struct.unpack(typeapack, fna[x * typeasize: x * typeasize + typeasize])[0] valb = struct.unpack(typebpack, fnb[x * typebsize: x * typebsize + typebsize])[0] diff = vala - valb - if diff > 0.01 or diff < -0.01: + if diff > 0.00001 or diff < -0.00001: return 20 return 0 diff --git a/tests/transform_stand/generateTest.py b/tests/transform_stand/generateTest.py index 2b9e6a8..252ad7a 100755 --- a/tests/transform_stand/generateTest.py +++ b/tests/transform_stand/generateTest.py @@ -17,7 +17,7 @@ import random import numpy as np -def saveTestData(filename, width, height): +def saveTestData(filename, width, height, dc_average=False): data = [] for w in range(0,width): @@ -34,7 +34,10 @@ def saveTestData(filename, width, height): a=np.array(data) mean = np.mean(a) standard = np.std(a) - result=abs((a-np.mean(a)) / (np.std(a)+1e-10)) + if dc_average: + result=a-np.mean(a) + else: + result=abs((a-np.mean(a)) / (np.std(a)+1e-10)) data = [] for w in range(0,width): @@ -47,4 +50,22 @@ def saveTestData(filename, width, height): return result, mean, standard -buf = saveTestData("test_00.dat", 100, 50) +def saveTestPerChannelData(filename, num_channel, num_sample, dc_average=False): + arr = np.random.randn(num_sample, num_channel) + with open(filename, 'wb') as f: + f.write(arr.astype('f').tobytes()) + + means = np.mean(arr, axis=0) + result = arr - means + + if dc_average == False: + std = np.std(arr, axis=0) + result = abs(result / (std + 1e-10)) + + with open(filename+".golden", 'wb') as f: + f.write(result.astype('f').tobytes()) + +buf = saveTestData("test_00.dat", 100, 50, False) +buf = saveTestPerChannelData("test_01.dat", 50, 100, False) +buf = saveTestData("test_02.dat", 100, 50, True) +buf = saveTestPerChannelData("test_03.dat", 50, 100, True) diff --git a/tests/transform_stand/runTest.sh b/tests/transform_stand/runTest.sh index 9fbed88..e6f1ef8 100644 --- a/tests/transform_stand/runTest.sh +++ b/tests/transform_stand/runTest.sh @@ -37,6 +37,24 @@ gstTest "--gst-plugin-path=${PATH_TO_PLUGIN} multifilesrc location=\"test_%02d.d python3 checkResult.py standardization test_00.dat.golden result_00.log 4 4 f f default -testResult $? 1 "Golden test comparison" 0 1 +testResult $? 1 "Golden test comparison 1" 0 1 + +gstTest "--gst-plugin-path=${PATH_TO_PLUGIN} multifilesrc location=\"test_%02d.dat\" caps=\"application/octet-stream\" ! tensor_converter input-dim=50:100:1:1 input-type=float32 ! tensor_transform mode=stand option=default,per-channel:true ! multifilesink location=\"./result_%02d.log\" sync=true" 2 0 0 $PERFORMANCE + +python3 checkResult.py standardization test_01.dat.golden result_01.log 4 4 f f default + +testResult $? 1 "Golden test comparison 2" 0 1 + +gstTest "--gst-plugin-path=${PATH_TO_PLUGIN} multifilesrc location=\"test_%02d.dat\" caps=\"application/octet-stream\" ! tensor_converter input-dim=50:100:1:1 input-type=float32 ! tensor_transform mode=stand option=dc-average:float32 ! multifilesink location=\"./result_%02d.log\" sync=true" 3 0 0 $PERFORMANCE + +python3 checkResult.py standardization test_02.dat.golden result_02.log 4 4 f f default + +testResult $? 1 "Golden test comparison 3" 0 1 + +gstTest "--gst-plugin-path=${PATH_TO_PLUGIN} multifilesrc location=\"test_%02d.dat\" caps=\"application/octet-stream\" ! tensor_converter input-dim=50:100:1:1 input-type=float32 ! tensor_transform mode=stand option=dc-average:float32,per-channel:true ! multifilesink location=\"./result_%02d.log\" sync=true" 4 0 0 $PERFORMANCE + +python3 checkResult.py standardization test_03.dat.golden result_03.log 4 4 f f default + +testResult $? 1 "Golden test comparison 4" 0 1 report -- 2.7.4