diff --git a/llvm/projects/keras/frontend/weight_utils.py b/llvm/projects/keras/frontend/weight_utils.py index e2a956fa9a4fe68acf9e40fba16de9ab1247050d..4a9e3dbe0a1947fadda46704c984bbb087ce1545 100644 --- a/llvm/projects/keras/frontend/weight_utils.py +++ b/llvm/projects/keras/frontend/weight_utils.py @@ -13,10 +13,8 @@ def dumpLabels(file_name, Y_test): for label in Y_test: label_val = 0 if len(Y_test.shape) > 1: - #label_val = np.int8(label[0]) label_val = np.int32(label[0]) else: - #label_val = np.int8(label) label_val = np.int32(label) if label_val not in labels_map: @@ -28,7 +26,7 @@ def dumpLabels(file_name, Y_test): f.close() - +""" def dumpData(file_name, X_test): N = X_test.shape[0] @@ -37,8 +35,8 @@ def dumpData(file_name, X_test): W = X_test.shape[3] print ("*DumpData") - print("-min_val = ", np.amin(X_test)) - print("-max_val = ", np.amax(X_test)) + #print("-min_val = ", np.amin(X_test)) + #print("-max_val = ", np.amax(X_test)) f = open(file_name, "wb") for i in range(N): @@ -50,35 +48,36 @@ def dumpData(file_name, X_test): f.close() +""" + -""" def dumpData(file_name, X_test): - N = X_test.shape[0] - C = X_test.shape[1] - H = X_test.shape[2] - W = X_test.shape[3] - print ("*DumpData") - print("-min_val = ", np.amin(X_test)) - print("-max_val = ", np.amax(X_test)) + #print("-min_val = ", np.amin(X_test)) + #print("-max_val = ", np.amax(X_test)) f = open(file_name, "wb") + print ("X.shape = ", X_test.shape) + print ("X_test.size", len(X_test)) + X_test = X_test.flatten() + X_test = X_test.astype(np.float32) X_test.tofile(f) f.close() -""" + - +""" def dumpConvWeights(file_name, weights, N, C, H, W): print (weights.shape) print ("*DumpConvWeights") - print("-min_val = ", np.amin(weights)) - print("-max_val = ", np.amax(weights)) + + #print("-min_val = ", np.amin(weights)) + #print("-max_val = ", np.amax(weights)) f = open(file_name, "wb") @@ -90,7 +89,31 @@ def dumpConvWeights(file_name, weights, N, C, H, W): f.close() +""" + +def dumpConvWeights(file_name, X_test, N, C, H, W): + + print ("*DumpConvWeights") + #print("-min_val = ", np.amin(X_test)) + #print("-max_val = ", np.amax(X_test)) + + f = open(file_name, "wb") + + print ("X_test.shape", X_test.shape) + print ("X_test.size", len(X_test)) + + X_test = np.transpose(X_test, (3, 2, 0, 1)) + + print ("X_test.shape", X_test.shape) + X_test = X_test.flatten() + X_test = X_test.astype(np.float32) + X_test.tofile(f) + + f.close() + + + def dumpFcWeights(file_name, weights, H, W):