##
# @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)
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
import numpy as np
-def saveTestData(filename, width, height):
+def saveTestData(filename, width, height, dc_average=False):
data = []
for w in range(0,width):
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):
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)
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