文档反馈

问题文档片段

问题文档片段包含公式时,显示为空格。

提交类型
issue

有点复杂...

找人问问吧。

请选择提交类型

问题类型
规范和低错类

- 规范和低错类:

- 错别字或拼写错误,标点符号使用错误、公式错误或显示异常。

- 链接错误、空单元格、格式错误。

- 英文中包含中文字符。

- 界面和描述不一致,但不影响操作。

- 表述不通顺,但不影响理解。

- 版本号不匹配:如软件包名称、界面版本号。

易用性

- 易用性:

- 关键步骤错误或缺失,无法指导用户完成任务。

- 缺少主要功能描述、关键词解释、必要前提条件、注意事项等。

- 描述内容存在歧义指代不明、上下文矛盾。

- 逻辑不清晰,该分类、分项、分步骤的没有给出。

正确性

- 正确性:

- 技术原理、功能、支持平台、参数类型、异常报错等描述和软件实现不一致。

- 原理图、架构图等存在错误。

- 命令、命令参数等错误。

- 代码片段错误。

- 命令无法完成对应功能。

- 界面错误,无法指导操作。

- 代码样例运行报错、运行结果不符。

风险提示

- 风险提示:

- 对重要数据或系统存在风险的操作,缺少安全提示。

内容合规

- 内容合规:

- 违反法律法规,涉及政治、领土主权等敏感词。

- 内容侵权。

请选择问题类型

问题描述

点击输入详细问题描述,以帮助我们快速定位问题。

mindarmour.reliability

Reliability methods of MindArmour.

class mindarmour.reliability.ConceptDriftCheckTimeSeries(window_size=100, rolling_window=10, step=10, threshold_index=1.5, need_label=False)[source]

ConceptDriftCheckTimeSeries is used for example series distribution change detection.

Parameters
  • window_size (int) – Size of a concept window, no less than 10. If given the input data, window_size belongs to [10, 1/3*len(input data)]. If the data is periodic, usually window_size equals 2-5 periods, such as, for monthly/weekly data, the data volume of 30/7 days is a period. Default: 100.

  • rolling_window (int) – Smoothing window size, belongs to [1, window_size]. Default:10.

  • step (int) – The jump length of the sliding window, belongs to [1, window_size]. Default:10.

  • threshold_index (float) – The threshold index, (,+). Default: 1.5.

  • need_label (bool) – False or True. If need_label=True, concept drift labels are needed. Default: False.

Examples

>>> concept = ConceptDriftCheckTimeSeries(window_size=100, rolling_window=10,
>>>                   step=10, threshold_index=1.5, need_label=False)
>>> data_example = 5*np.random.rand(1000)
>>> data_example[200: 800] = 20*np.random.rand(600)
>>> score, threshold, concept_drift_location = concept.concept_check(data_example)
concept_check(data)[source]

Find concept drift locations in a data series.

Parameters

data (numpy.ndarray) – Input data. The shape of data could be (n,1) or (n,m). Note that each column (m columns) is one data series.

Returns

  • numpy.ndarray, the concept drift score of the example series.

  • float, the threshold to judge concept drift.

  • list, the location of the concept drift.

Examples:
>>> concept = ConceptDriftCheckTimeSeries(window_size=100, rolling_window=10,
>>>                   step=10, threshold_index=1.5, need_label=False)
>>> data_example = 5*np.random.rand(1000)
>>> data_example[200: 800] = 20*np.random.rand(600)
>>> score, drift_threshold, drift_location = concept.concept_check(data_example)
class mindarmour.reliability.FaultInjector(model, fi_type=None, fi_mode=None, fi_size=None)[source]

Fault injection for deep neural networks and evaluate performance.

Parameters
  • model (Model) – The model need to be evaluated.

  • fi_type (list) – The type of the fault injection which include bitflips_random(flip randomly), bitflips_designated(flip the key bit), random, zeros, nan, inf, anti_activation precision_loss etc.

  • fi_mode (list) – The mode of fault injection. Fault inject on just single layer or all layers.

  • fi_size (list) – The number of fault injection.It mean that how many values need to be injected.

Examples

>>> net = Net()
>>> model = Model(net)
>>> ds_data, ds_label = create_data()
>>> fi_type = ['bitflips_random', 'zeros']
>>> fi_mode = ['single_layer', 'all_layer']
>>> fi_size = [1, 2]
>>> fi = FaultInjector(model, fi_type=fi_type, fi_mode=fi_mode, fi_size=fi_size)
>>> fi.kick_off(ds_data, ds_label)
kick_off(ds_data, ds_label, iter_times=100)[source]

Startup and return final results.

Parameters
  • ds_data (np.ndarray) – Input data for testing. The evaluation is based on this data.

  • ds_label (np.ndarray) – The label of data, corresponding to the data.

  • iter_times (int) – The number of evaluations, which will determine the batch size.

Returns

  • list, the result of fault injection.

metrics()[source]

metrics of final result. :returns: list, the summary of result.

class mindarmour.reliability.OodDetector(model, ds_train)[source]

Train the OOD detector.

Parameters
  • model (Model) – The training model.

  • ds_train (numpy.ndarray) – The training dataset.

get_optimal_threshold(label, ds_eval)[source]

Get the optimal threshold.

Parameters
  • label (numpy.ndarray) – The label whether an image is in-distribution and out-of-distribution.

  • ds_eval (numpy.ndarray) – The testing dataset to help find the threshold.

Returns

  • float, the optimal threshold.

ood_predict(threshold, ds_test)[source]

The out-of-distribution detection.

Parameters
  • threshold (float) – the threshold to judge ood data. One can set value by experience or use function get_optimal_threshold.

  • ds_test (numpy.ndarray) – The testing dataset.

Returns

  • numpy.ndarray, the detection result. 0 means the data is not ood, 1 means the data is ood.

class mindarmour.reliability.OodDetectorFeatureCluster(model, ds_train, n_cluster, layer)[source]

Train the OOD detector. Extract the training data features, and obtain the clustering centers. The distance between the testing data features and the clustering centers determines whether an image is an out-of-distribution(OOD) image or not.

Parameters
  • model (Model) – The training model.

  • ds_train (numpy.ndarray) – The training dataset.

  • n_cluster (int) – The cluster number. Belonging to [2,100]. Usually, n_cluster equals to the class number of the training dataset. If the OOD detector performs poor in the testing dataset, we can increase the value of n_cluster appropriately.

  • layer (str) – The name of the feature layer. layer (str) is represented by ‘name[:Tensor]’, where ‘name’ is given by users when training the model. Please see more details about how to name the model layer in ‘README.md’.

get_optimal_threshold(label, ds_eval)[source]

Get the optimal threshold.

Parameters
  • label (numpy.ndarray) – The label whether an image is in-distribution and out-of-distribution.

  • ds_eval (numpy.ndarray) – The testing dataset to help find the threshold.

Returns

  • float, the optimal threshold.

ood_predict(threshold, ds_test)[source]

The out-of-distribution detection.

Parameters
  • threshold (float) – the threshold to judge ood data. One can set value by experience or use function get_optimal_threshold.

  • ds_test (numpy.ndarray) – The testing dataset.

Returns

  • numpy.ndarray, the detection result. 0 means the data is not ood, 1 means the data is ood.