[test/tensor_transform] Add testcases for stand
authorYongjoo Ahn <yongjoo1.ahn@samsung.com>
Mon, 29 Mar 2021 11:16:44 +0000 (20:16 +0900)
committerMyungJoo Ham <myungjoo.ham@samsung.com>
Thu, 1 Apr 2021 10:13:25 +0000 (19:13 +0900)
- Add SSAT testcases for stand: default and dc-average

Signed-off-by: Yongjoo Ahn <yongjoo1.ahn@samsung.com>
tests/transform_stand/checkResult.py
tests/transform_stand/generateTest.py
tests/transform_stand/runTest.sh

index e844d67..6ef3b84 100644 (file)
@@ -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
 
index 2b9e6a8..252ad7a 100755 (executable)
@@ -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)
index 9fbed88..e6f1ef8 100644 (file)
@@ -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