diff --git a/hpvm/test/dnn_benchmarks/hpvm-c/benchmarks/alexnet_cifar10/scripts/fp16_quantize.py b/hpvm/test/dnn_benchmarks/hpvm-c/benchmarks/alexnet_cifar10/scripts/fp16_quantize.py new file mode 100644 index 0000000000000000000000000000000000000000..ded4932c0428f082cc6603db6334be354c04ac0a --- /dev/null +++ b/hpvm/test/dnn_benchmarks/hpvm-c/benchmarks/alexnet_cifar10/scripts/fp16_quantize.py @@ -0,0 +1,30 @@ + +import numpy as np +import os + + +if __name__ == "__main__": + + list_dir = os.listdir("./") + print (list_dir) + + for file_name in list_dir: + if "fp16" not in file_name and ".bin" in file_name: + print ("name = ", file_name) + weights_arr = np.fromfile(file_name, dtype ='float32') + print (weights_arr[:5], weights_arr.shape) + fp16_weights = weights_arr.astype(np.float16) + print (fp16_weights[:5], fp16_weights.shape) + + fp16_file = open(file_name.split(".")[0] + "_fp16.bin", "w+") + fp16_weights.tofile(fp16_file) + fp16_file.close() + + + for file_name in list_dir: + if "fp16" in file_name: + print ("fp16_name = ", file_name) + weights_arr = np.fromfile(file_name, dtype ='float16') + print (weights_arr[:5], weights_arr.shape) + +