import torch import sys from fxpmath import Fxp import numpy as np x = Fxp(-5.25789021) print(x.info()) # network = sys.argv[1] network = "trained-models/cornell-randsplit-rgbd-grconvnet3-drop1-ch32/epoch_19_iou_0.98" net = torch.load(network) # net_q = torch.quantization.quantize_dynamic(net, qconfig_spec=None, dtype=torch.qint8, mapping=None, inplace=False) # net.eval() model_dict = net.state_dict() # model_dict_q = net_q.state_dict() # print ("model_dict = ",model_dict) keys = model_dict.keys() print("keys = ", keys) conv1_weight = model_dict['conv1.weight'] # conv1_weigdt_fixed = model_dict_q['conv1.weight'] # print("origin = ",conv1_weight[0][0][0]) # print("quantize = ",conv1_weigdt_fixed[0][0][0]) # print ("conv1_weight = ",conv1_weight.size()) # bn1_weight = model_dict["bn1.weight"] # print ("bn1_weight = ",bn1_weight) for key in model_dict:
import numpy as np x = np.array([[1 / 3, 1 / 3]]) y = np.array([[1 / 3], [1 / 3]]) print("X original = ", x) print("Y original = ", y) print("-----------") x_fxp = Fxp(x, signed=False, n_word=20, n_frac=15) y_fxp = Fxp(y, signed=False, n_word=20, n_frac=15) print("X fxp =", x_fxp.get_val()) print("Y fxp =", y_fxp.get_val()) print("-----------") print(x_fxp.info(verbose=3)) print("-----------") print("Dot product without scaling = ", x_fxp.get_val().dot(y_fxp.get_val())) print("Dot prod scaled = ", Fxp(x_fxp.get_val().dot(y_fxp.get_val()), n_word=20, n_frac=15)) print("Dot prod without specifications = ", Fxp(x_fxp.get_val().dot(y_fxp.get_val()))) dot_fpx = Fxp(None, signed=True, n_word=20, n_frac=15) dot_fpx.equal(x_fxp().dot(y_fxp())) print("Dot with new variable = ", dot_fpx())