afe.core.graph_analyzer.utils

Classes

BaseGraphAnalyzerMode

Base class for GraphAnalyzer mode. Overload _missing_ method

QuantizedGraphAnalyzerMode

Modes of the QuantizedGraphAnalyzer. Support:

Metric

Enum class for different metric

Functions

find_below_threshold(...)

A function that returns only the analyzed results below the targeted threshold.

find_above_threshold(...)

A function that returns only the analyzed results above the targeted threshold.

single_input_tuple_list_datatype_helper(func)

A helper decorator that helps the metric calculation functions to support

double_inputs_tuple_list_datatype_helper(func)

A helper decorator that helps the metric calculation functions to support

get_metric_func(β†’Β Callable)

Function to get the metric calculation function.

Module Contents

class afe.core.graph_analyzer.utils.BaseGraphAnalyzerMode[source]

Base class for GraphAnalyzer mode. Overload _missing_ method to print out more informative error message.

class afe.core.graph_analyzer.utils.QuantizedGraphAnalyzerMode[source]

Modes of the QuantizedGraphAnalyzer. Support:

  • global_feed:

    Execute the both fp32 AwesomeNet and quantized AwesomeNet using the same inputs. Compare intermediates between both AwesomeNets and calculate the targeted metrics

  • local_feed:

    Execute the fp32 AwesomeNet. Execute the given quantized AwesomeNet using the intermediates from fp32 AwesomeNet. When execute each node in the quantized AwesomeNet, instead using the output from its previous node(s), it uses the intermediates from the fp32 AwesomeNet. Each input to the node will be quantized to int8 before execution. Compare intermediates between both AwesomeNets and calculate the targeted metrics

global_feed = 'global_feed'[source]
local_feed = 'local_feed'[source]
class afe.core.graph_analyzer.utils.Metric[source]

Enum class for different metric

Parameters

param l1:

L1 error

param l2:

L2 error

param mae:

Mean absolute error

param mse:

Mean square error

param psnr:

Peak signal-to-noise ratio

param mean:

Mean

param std:

Standard deviation

l1 = 'l1'[source]
l2 = 'l2'[source]
mae = 'mae'[source]
mse = 'mse'[source]
psnr = 'psnr'[source]
mean = 'mean'[source]
std = 'std'[source]
afe.core.graph_analyzer.utils.find_below_threshold(analyzed_results: afe.core.graph_analyzer.analyzed_results.AnalyzedResultDict, threshold: float) afe.core.graph_analyzer.analyzed_results.AnalyzedResultDict[source]

A function that returns only the analyzed results below the targeted threshold.

Parameters

param analyzed_results:

AnalyzedResultDict. The AnalyzedResultDict that will be filtered.

param threshold:

float. The threshold value that will be used by the filter function.

Return

return:

AnalyzedResultDict. A filtered AnalyzedResultDict.

afe.core.graph_analyzer.utils.find_above_threshold(analyzed_results: afe.core.graph_analyzer.analyzed_results.AnalyzedResultDict, threshold: float) afe.core.graph_analyzer.analyzed_results.AnalyzedResultDict[source]

A function that returns only the analyzed results above the targeted threshold.

Parameters

param analyzed_results:

AnalyzedResultDict. The AnalyzedResultDict that will be filtered.

param threshold:

float. The threshold value that will be used by the filter function.

Return

return:

AnalyzedResultDict. A filtered AnalyzedResultDict.

afe.core.graph_analyzer.utils.single_input_tuple_list_datatype_helper(func)[source]

A helper decorator that helps the metric calculation functions to support single Tuple[np.ndarray, …] and List[np.ndarray] input.

Example

The example shows how the single_input_tuple_list_datatype_helper can help the mean and std calculation function to be able to support Tuple[np.ndarray, …] and List[np.ndarray] format input

@single_input_tuple_list_datatype_helper
def calculate_mean_std(in1: np.ndarray):
    return np.average(in1) np.std(in1)
afe.core.graph_analyzer.utils.double_inputs_tuple_list_datatype_helper(func)[source]

A helper decorator that helps the metric calculation functions to support double Tuple[np.ndarray, …] and List[np.ndarray] inputs

Example

The example shows how the double_inputs_tuple_list_datatype_helper can help the MAE calculation function to be able to support Tuple[np.ndarray, …] and List[np.ndarray] format in1 and in2

@double_inputs_tuple_list_datatype_helper
def calculate_mean_absolute_value(in1: np.ndarray, in2: np.ndarray):
    return np.average(np.abs(in1 - in2))
afe.core.graph_analyzer.utils.get_metric_func(metric: Metric) Callable[source]

Function to get the metric calculation function.

Parameters

param metric:

Metric

Return

return:

Callable. A metric calculation function