datagnosis.plugins package#
- class Plugin(model: torch.nn.modules.module.Module, criterion: torch.nn.modules.module.Module, optimizer: torch.optim.optimizer.Optimizer, lr: float, epochs: int, num_classes: int, device: Optional[torch.device] = device(type='cpu'), logging_interval: int = 100, reproducible: bool = True, requires_intermediate: bool = False)[source]#
Bases:
object- abstract compute_scores() Union[numpy.ndarray, Tuple[numpy.ndarray, numpy.ndarray]][source]#
Compute the scores for the plugin model
- extract_datapoints(method: Literal['threshold', 'top_n', 'index'] = 'threshold', hardness: Literal['hard', 'easy'] = 'hard', threshold: Optional[float] = None, threshold_range: Optional[Tuple[float, float]] = None, n: Optional[int] = None, indices: Optional[List[int]] = None, sort_by_index: bool = True) Tuple[Tuple[torch.Tensor, torch.Tensor, List], numpy.ndarray][source]#
Extracts datapoints from the plugin model by applying a threshold or range to the scores, selecting the top n scores, or selecting datapoints by index.
- Parameters
method (Literal[threshold, top_n, index], optional) – The method to use to extract datapoints. Defaults to “threshold”.
hardness (Literal[hard, easy], optional) – Flag to indicate whether to extract hard or easy data points. Defaults to “hard”.
threshold (Optional[float], optional) – The threshold to apply to the scores. Must be provided if the given method is “threshold” and threshold_range is None. Defaults to None.
threshold_range (Optional[Tuple[float, float]], optional) – The range of thresholds to apply to the scores. Must be provided if the given method is “threshold” and the value passed to threshold is None. Defaults to None.
n (Optional[int], optional) – The number of datapoints to extract. Must be provided if the given method is “top_n”. Defaults to None.
indices (Optional[List[int]], optional) – The indices of the datapoints to extract. Must be provided if the given method is “index”. Defaults to None.
sort_by_index (bool, optional) – Flag to indicate whether to sort_by_index the extracted datapoints. Defaults to True.
- Raises
ValueError – raised if the given method is not one of “threshold”, “top_n”, or “index”.
ValueError – raised if the given method is “threshold” but neither threshold nor threshold_range is provided.
ValueError – raised if the given method is “top_n” but n is not provided.
ValueError – raised if the given method is “index” but a list of indices is not provided.
- Returns
The extracted datapoints and the scores of the extracted datapoints. Datapoints returned in the format ((Features, Labels, Indices), scores)
- Return type
Tuple[np.ndarray, np.ndarray]
- fit(datahandler: datagnosis.plugins.core.datahandler.DataHandler, use_caches_if_exist: bool = True, workspace: Union[pathlib.Path, str] = PosixPath('workspace'), *args: Any, **kwargs: Any) typing_extensions.Self[source]#
Fit the plugin model.
- Parameters
datahandler (DataHandler) – The datagnosis.plugins.core.datahandler.DataHandler object that contains the data to be used for fitting.
use_caches_if_exist (bool, optional) – A flag to indicate whether or not to use cached data if it exists. Defaults to True.
workspace (Union[Path, str], optional) – A path to the workspace directory. Defaults to Path(“workspace/”).
- Raises
RuntimeError – Raises a RuntimeError if the plugin’s fit method has already been called.
- abstract static hard_direction() str[source]#
The direction of the scores for the plugin. Either ‘low’ if hard scores are low or ‘high’ if hard scores are high.
- plot_scores(*args: Any, axis: Optional[int] = None, show: bool = True, plot_type: Literal['scatter', 'dist'] = 'dist', **kwargs: Any) None[source]#
_summary_
- Parameters
axis (Optional[int], optional) – The axis to plot. If None, plot a higher dimentional plot. Defaults to None.
show (bool, optional) – Flag to indicate whether to show the plot. Defaults to True.
plot_type (Literal[scatter, dist], optional) – The type of plot to show. Can be either “scatter” or “dist”. Defaults to “dist”.
- Raises
ValueError – raised if the scores have not been computed.
ValueError – raised if scores have more than 2 dimensions. You must specify which axis to plot.
- property scores: Union[Tuple[numpy.ndarray, numpy.ndarray], numpy.ndarray]#
The scores for the plugin model
- Raises
ValueError – raised if the plugin has not been fit.
ValueError – raised if the scores have not been computed.
- Returns
The scores for the plugin model
- Return type
np.ndarray
- class Plugins(categories: list = ['generic', 'images'])[source]#
Bases:
datagnosis.plugins.core.plugin.PluginLoader- add(name: str, cls: Type) datagnosis.plugins.core.plugin.PluginLoader#
Add a new plugin
- get(name: str, *args: Any, **kwargs: Any) Any#
Create a new object from a plugin.
- Parameters
name (str) – The name of the plugin
- Raises
ValueError – raises if the plugin doesn’t exist
ValueError – raises if the plugin cannot be loaded
- Returns
The new object
- Return type
Any
- get_type(name: str) Type#
Get the class type of a plugin.
- Parameters
name (str) – The name of the plugin
- Raises
ValueError – raises if the plugin doesn’t exist
ValueError – raises if the plugin cannot be loaded
- Returns
The class of the plugin
- Return type
Type
- list() List[str]#
Get all the available plugins.
- types() List[Type]#
Get the loaded plugins types
Subpackages#
- datagnosis.plugins.core package
- datagnosis.plugins.generic package
- Submodules
- datagnosis.plugins.generic.plugin_aum module
- datagnosis.plugins.generic.plugin_conf_agree module
- datagnosis.plugins.generic.plugin_confident_learning module
- datagnosis.plugins.generic.plugin_data_iq module
- datagnosis.plugins.generic.plugin_data_maps module
- datagnosis.plugins.generic.plugin_el2n module
- datagnosis.plugins.generic.plugin_forgetting module
- datagnosis.plugins.generic.plugin_grand module
- datagnosis.plugins.generic.plugin_large_loss module
- datagnosis.plugins.generic.plugin_prototypicality module
- datagnosis.plugins.generic.plugin_vog module
- Submodules
- datagnosis.plugins.images package