|
|
|
@@ -19,7 +19,8 @@ from mindinsight.mindconverter.graph_based_converter.constant import NEW_LINE, S |
|
|
|
|
|
|
|
|
|
|
|
class ReportGenerator(metaclass=abc.ABCMeta): |
|
|
|
"""Generate report.""" |
|
|
|
"""Generate report of scripts transformation.""" |
|
|
|
|
|
|
|
def __init__(self): |
|
|
|
self._title = self._gen_title() |
|
|
|
self._extra = self._gen_extra() |
|
|
|
@@ -27,27 +28,40 @@ class ReportGenerator(metaclass=abc.ABCMeta): |
|
|
|
|
|
|
|
@staticmethod |
|
|
|
def _gen_title(): |
|
|
|
"""Generate title.""" |
|
|
|
""" |
|
|
|
Generate title of scripts transformation. |
|
|
|
|
|
|
|
Returns: |
|
|
|
str, title of scripts transformation report. |
|
|
|
""" |
|
|
|
title_info = '' |
|
|
|
return title_info |
|
|
|
|
|
|
|
@staticmethod |
|
|
|
def _gen_extra(): |
|
|
|
"""Generate extra information.""" |
|
|
|
""" |
|
|
|
Generate extra information. |
|
|
|
|
|
|
|
Returns: |
|
|
|
str, body of scripts transformation report. |
|
|
|
""" |
|
|
|
extra_info = {'start': '[Start Convert]', |
|
|
|
'end': '[Convert Over]'} |
|
|
|
return extra_info |
|
|
|
|
|
|
|
@property |
|
|
|
def title(self): |
|
|
|
"""Title property.""" |
|
|
|
return self._title |
|
|
|
|
|
|
|
@property |
|
|
|
def extra(self): |
|
|
|
"""Extra property.""" |
|
|
|
return self._extra |
|
|
|
|
|
|
|
@staticmethod |
|
|
|
def _gen_converted_operator_content(converted_location: list, converted_operator_name): |
|
|
|
def _gen_converted_operator_content(converted_location: list, |
|
|
|
converted_operator_name): |
|
|
|
""" |
|
|
|
Generate converted operator content. |
|
|
|
|
|
|
|
@@ -61,11 +75,13 @@ class ReportGenerator(metaclass=abc.ABCMeta): |
|
|
|
unconverted_operator_name = '' |
|
|
|
content = \ |
|
|
|
f"line {':'.join(converted_location)}: " \ |
|
|
|
f"[Convert]'{unconverted_operator_name}' is converted to {converted_operator_name}." |
|
|
|
f"[Convert]'{unconverted_operator_name}' is converted to " \ |
|
|
|
f"{converted_operator_name}." |
|
|
|
return content |
|
|
|
|
|
|
|
@staticmethod |
|
|
|
def _gen_unconverted_operator_content(unconverted_location: list, unconverted_operator_name): |
|
|
|
def _gen_unconverted_operator_content(unconverted_location: list, |
|
|
|
unconverted_operator_name): |
|
|
|
""" |
|
|
|
Generate unconverted operator content. |
|
|
|
|
|
|
|
@@ -76,9 +92,8 @@ class ReportGenerator(metaclass=abc.ABCMeta): |
|
|
|
Returns: |
|
|
|
String, report content of unconverted operator. |
|
|
|
""" |
|
|
|
content = \ |
|
|
|
f"line {':'.join(unconverted_location)}: " \ |
|
|
|
f"[UnConvert] '{unconverted_operator_name}' didn't convert." |
|
|
|
content = f"line {':'.join(unconverted_location)}: " \ |
|
|
|
f"[UnConvert] '{unconverted_operator_name}' didn't convert." |
|
|
|
return content |
|
|
|
|
|
|
|
def gen_report(self, code: str): |
|
|
|
@@ -100,18 +115,18 @@ class ReportGenerator(metaclass=abc.ABCMeta): |
|
|
|
code_line = code_lines[num_line] |
|
|
|
if 'onnx.' in code_line: |
|
|
|
num_unconverted_line += 1 |
|
|
|
unconverted_operator = \ |
|
|
|
SEPARATOR_IN_ONNX_OP.join(('onnx', re.findall(r".*onnx.(.*)[(]", code_line)[0])) |
|
|
|
info_unconverted_line = \ |
|
|
|
self._gen_unconverted_operator_content( |
|
|
|
[f"{num_line + 1}", f"{code_line.index('onnx.') + 1}"], |
|
|
|
unconverted_operator |
|
|
|
) |
|
|
|
self._content = f"{NEW_LINE}".join((self._content, info_unconverted_line)) |
|
|
|
unconverted_operator = SEPARATOR_IN_ONNX_OP.join( |
|
|
|
('onnx', re.findall(r".*onnx.(.*)[(]", code_line)[0])) |
|
|
|
info_unconverted_line = self._gen_unconverted_operator_content( |
|
|
|
[f"{num_line + 1}", f"{code_line.index('onnx.') + 1}"], |
|
|
|
unconverted_operator |
|
|
|
) |
|
|
|
self._content = f"{NEW_LINE}".join((self._content, |
|
|
|
info_unconverted_line)) |
|
|
|
self._content = f"{NEW_LINE}".join((self._content, self._extra['end'])) |
|
|
|
|
|
|
|
converted_rate = (num_all_lines - num_unconverted_line) / num_all_lines |
|
|
|
info_converted_rate = f"Converted Rate: {converted_rate * 100:.2f}%." |
|
|
|
info_converted_rate = f"Converted Rate: {converted_rate * 100:.2f}%.{NEW_LINE}" |
|
|
|
self._content = f"{NEW_LINE}".join((self._content, info_converted_rate)) |
|
|
|
|
|
|
|
return self._content |