Esempio n. 1
0
 def forward(self, input):
     if self.config["quantization"] == "BNN":
         Wb = quant.bnn_sign(self.weight/self.H)*self.H
         return quant.bnn_sign(F.linear(input, Wb, self.bias))
     elif self.config["quantization"] == "INT":
         Wb = quant.int_nn(self.weight, self.config["weight_i_width"], self.config["weight_f_width"])
         return quant.int_nn(F.linear(input, Wb, self.bias), self.config["activation_i_width"], self.config["activation_f_width"])
     else:
         Wb = self.weight
         return F.linear(input, Wb, self.bias)
Esempio n. 2
0
 def forward(self, x):
     # self.cnt += 1
     # if self.cnt==1000:
     #import ipdb as pdb; pdb.set_trace()
     if self.config["quantization"].lower() == "bnn":
         Wb = quant.bnn_sign(self.weight/self.H)*self.H
         return quant.bnn_sign(F.conv2d(x, Wb, self.bias, self.stride, self.padding, self.dilation, self.groups))
     elif self.config["quantization"].lower() == "int":
         Wb = quant.int_nn(self.weight, self.config["weight_i_width"])
         return quant.int_nn(F.conv2d(x, Wb, self.bias, self.stride, self.padding, self.dilation, self.groups), self.config["activation_i_width"])
     elif self.config["quantization"].lower() == "fixed":
         Wb = quant.fixed_nn(self.weight, self.config["weight_i_width"], self.config["weight_f_width"], "weight")
         return quant.fixed_nn(F.conv2d(x, Wb, self.bias, self.stride, self.padding, self.dilation, self.groups), self.config["activation_i_width"], self.config["activation_f_width"], "activation")
     else:
         Wb = self.weight
         return F.conv2d(x, Wb, self.bias, self.stride, self.padding, self.dilation, self.groups)
Esempio n. 3
0
 def forward(self, x):
     # import ipdb as pdb; pdb.set_trace()
     if self.config["quantization"] == "BNN":
         Wb = q.bnn_sign(self.weight / self.H) * self.H
         return q.bnn_sign(
             F.conv2d(x, Wb, self.bias, self.stride, self.padding,
                      self.dilation, self.groups))
     elif self.config["quantization"] == "INT":
         Wb = q.int_nn(self.weight, self.config["weight_width"])
         return q.int_nn(
             F.conv2d(x, Wb, self.bias, self.stride, self.padding,
                      self.dilation, self.groups),
             self.config["activation_width"])
     else:
         Wb = self.weight
         return F.conv2d(x, Wb, self.bias, self.stride, self.padding,
                         self.dilation, self.groups)
Esempio n. 4
0
 def forward(self, x):
     #import ipdb as pdb; pdb.set_trace()
     if self.config["quantization"].lower() == "int":
         return quant.int_nn(x, self.config["activation_i_width"])
     elif self.config["quantization"].lower() == "fixed":
         return quant.fixed_nn(x, self.config["activation_i_width"],
                               self.config["activation_f_width"])
     elif self.config["quantization"].lower() == "bnn":
         # import ipdb as pdb; pdb.set_trace()
         return quant.bnn_sign(x)
     else:
         return x