Skip to content
Snippets Groups Projects
Commit bd9f17a7 authored by Hashim Sharif's avatar Hashim Sharif
Browse files

Adding FP16 weight quantization script - NVDLA needs FP16 weights

parent 1e9c7b89
No related branches found
No related tags found
No related merge requests found
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)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment