ONE - On-device Neural Engine
Loading...
Searching...
No Matches
QErrorComputer.SRMSEComputer Class Reference
Collaboration diagram for QErrorComputer.SRMSEComputer:

Public Member Functions

 __init__ (self, fp32_dir, fq_dir)
 
 advance_on (self, fp32_dir, fq_dir)
 
 get_final_result (self)
 
 run (self)
 
- Public Member Functions inherited from QErrorComputer.QErrorComputer
 collect_data_path (self, fp32_dir, fq_dir)
 

Data Fields

 scale_file
 
- Data Fields inherited from QErrorComputer.QErrorComputer
 qerror_map
 

Protected Attributes

 _fq_dir
 
 _fp32_dir
 
- Protected Attributes inherited from QErrorComputer.QErrorComputer
 _fp32_dir
 
 _fq_dir
 
 _num_processed_data
 
 _num_data
 
 _tid_to_tname
 

Detailed Description

Definition at line 210 of file QErrorComputer.py.

Constructor & Destructor Documentation

◆ __init__()

QErrorComputer.SRMSEComputer.__init__ (   self,
  fp32_dir,
  fq_dir 
)

Reimplemented from QErrorComputer.QErrorComputer.

Definition at line 211 of file QErrorComputer.py.

211 def __init__(self, fp32_dir, fq_dir):
212 super().__init__(fp32_dir, fq_dir)
213 if fq_dir != None:
214 self.scale_file = Path(fq_dir) / 'scales.txt'
215

References QErrorComputer.SRMSEComputer.__init__().

Referenced by QErrorComputer.SRMSEComputer.__init__().

Member Function Documentation

◆ advance_on()

QErrorComputer.SRMSEComputer.advance_on (   self,
  fp32_dir,
  fq_dir 
)

Definition at line 217 of file QErrorComputer.py.

217 def advance_on(self, fp32_dir, fq_dir):
218 if fq_dir != None:
219 self.scale_file = Path(fq_dir) / 'scales.txt'
220 self._fq_dir = fq_dir
221
222 data_paths = self.collect_data_path(fp32_dir, fq_dir)
223
224 for tensor_name, data_path in data_paths.items():
225 for (fp32_data_path, fq_data_path) in data_path:
226 fp32_data = np.load(fp32_data_path)
227 fq_data = np.load(fq_data_path)
228
229 MSE = np.square(fp32_data - fq_data).mean()
230
231 self.qerror_map[tensor_name] += MSE
232

References QErrorComputer.SRMSEComputer.scale_file.

◆ get_final_result()

QErrorComputer.SRMSEComputer.get_final_result (   self)

Definition at line 237 of file QErrorComputer.py.

237 def get_final_result(self):
238 with open(self.scale_file) as f:
239 # scale_map: {tensor_name(str) -> scale(float)}
240 scale_map = json.load(f)
241
242 qerror_max = 0.0
243 qerror_map = dict()
244 for tensor_name, acc in self.qerror_map.items():
245 MSE = acc / self._num_processed_data
246 SRMSE = np.sqrt(MSE) / scale_map[tensor_name]
247 qerror_map[tensor_name] = SRMSE
248 qerror_max = max(SRMSE, qerror_max)
249
250 return qerror_map, 0.0, qerror_max
251

References QErrorComputer.QErrorComputer._num_processed_data, QErrorComputer.QErrorComputer.qerror_map, and QErrorComputer.SRMSEComputer.scale_file.

◆ run()

QErrorComputer.SRMSEComputer.run (   self)
Return qerror map (dict: tensor_name(string) -> qerror(float)).

Reimplemented from QErrorComputer.QErrorComputer.

Definition at line 252 of file QErrorComputer.py.

252 def run(self):
253 self.advance_on(self._fp32_dir, self._fq_dir)
254 return self.get_final_result()
void run(std::ofstream &os, const circle::Model *model)

Field Documentation

◆ _fp32_dir

QErrorComputer.SRMSEComputer._fp32_dir
protected

Definition at line 253 of file QErrorComputer.py.

◆ _fq_dir

QErrorComputer.SRMSEComputer._fq_dir
protected

Definition at line 220 of file QErrorComputer.py.

◆ scale_file

QErrorComputer.SRMSEComputer.scale_file

The documentation for this class was generated from the following file: