dnn_cool package¶
Submodules¶
dnn_cool.activations module¶
-
class
dnn_cool.activations.ActivationVisitor(task, prefix)¶ Bases:
dnn_cool.visitors.LeafVisitor-
empty_result()¶
-
full_result(preds, targets)¶
-
preconditioned_result(preds, targets)¶
-
-
class
dnn_cool.activations.ActivationsFiltered(data: Dict = <factory>)¶ Bases:
dnn_cool.visitors.VisitorOut-
reduce()¶
-
-
class
dnn_cool.activations.CompositeActivation(task_flow)¶
dnn_cool.catalyst_utils module¶
-
class
dnn_cool.catalyst_utils.DeviceReducingDataParallel(module: torch.nn.modules.module.Module, task_flow, infer_dict_callback)¶ Bases:
torch.nn.parallel.data_parallel.DataParallel-
gather(outputs, output_device)¶
-
reset_device_reducing_tasks()¶
-
-
class
dnn_cool.catalyst_utils.GuidedGradCamPublisher(model, layer, forward_pass_preprocess)¶ Bases:
object
-
class
dnn_cool.catalyst_utils.ITensorboardPublisher¶ Bases:
object
-
class
dnn_cool.catalyst_utils.InterpretationCallback(per_sample_criterion, tensorboard_converters: Optional[dnn_cool.catalyst_utils.TensorboardConverters] = None, loaders_to_skip=())¶ Bases:
catalyst.core.callback.CallbackThis callback publishes best and worst images per task, according to the configuration supplied via the constructor.
-
on_batch_end(state: catalyst.core.runner.IRunner)¶ Event handler for batch end.
- Args:
- runner: IRunner instance.
-
on_loader_end(state: catalyst.core.runner.IRunner)¶ Event handler for loader end.
- Args:
- runner: IRunner instance.
-
on_loader_start(state: catalyst.core.runner.IRunner)¶ Event handler for loader start.
- Args:
- runner: IRunner instance.
-
on_stage_end(state: catalyst.core.runner.IRunner)¶ Event handler for stage end.
- Args:
- runner: IRunner instance.
-
prepare_interpretations(state)¶
-
-
class
dnn_cool.catalyst_utils.ReplaceGatherCallback(task_flow, infer_dict_callback=None)¶ Bases:
catalyst.core.callback.Callback-
on_loader_start(runner: catalyst.core.runner.IRunner)¶ Event handler for loader start.
- Args:
- runner: IRunner instance.
-
on_stage_start(runner: catalyst.core.runner.IRunner)¶ Event handler for stage start.
- Args:
- runner: IRunner instance.
-
-
class
dnn_cool.catalyst_utils.SingleLossInterpretationCallback(criterion, loaders_to_skip: Container[str] = (), prefix: str = '', input_key: str = 'targets', output_key: str = 'logits', idx_key=None, top_k=10, tensorboard_sequence: Sequence[T_co] = None, tensorboard_publishers: Sequence[dnn_cool.catalyst_utils.ITensorboardPublisher] = (), **loss_kwargs)¶ Bases:
catalyst.callbacks.metric.IMetricCallback-
metric_fn¶ Specifies used metric function.
-
on_batch_end(runner: catalyst.core.runner.IRunner)¶ Event handler for batch end.
- Args:
- runner: IRunner instance.
-
on_loader_end(runner: catalyst.core.runner.IRunner)¶ Event handler for loader end.
- Args:
- runner: IRunner instance.
-
on_loader_start(runner: catalyst.core.runner.IRunner)¶ Event handler for loader start.
- Args:
- runner: IRunner instance.
-
-
class
dnn_cool.catalyst_utils.TensorboardConverter(col_mapping: Dict[str, List[dnn_cool.catalyst_utils.ITensorboardPublisher]] = <factory>, type_mapping: Dict[str, List[dnn_cool.catalyst_utils.ITensorboardPublisher]] = <factory>, col_to_type_mapping: Dict[str, str] = <factory>)¶ Bases:
objectA dataclass which holds mappings from column names to Tensorboard publishers and from column types to Tensorboard publishers. Also, it stores which column is of what type, to be able to log any column name to the Tensorboard.
-
col_mapping= None¶ Stores a dict from column names to a list of publishers. A publisher is just a callable which will be called with this signature:
publisher(writer: SummaryWriter, idx: int, sample: Tuple, prefix: str, task_name: str, key: str). Example publisher functions arednn_cool.catalyst_utils.img()anddnn_cool.catalyst_utils.text().
-
col_to_type_mapping= None¶ Stores a dict from column names to type names.
-
type_mapping= None¶ Stores a dict from column types to a list of publishers. A publisher is just a callable which will be called with this signature:
publisher(writer: SummaryWriter, idx: int, sample: Tuple, prefix: str, task_name: str, key: str). Example publisher functions arednn_cool.catalyst_utils.img()anddnn_cool.catalyst_utils.text().
-
-
class
dnn_cool.catalyst_utils.TensorboardConverters(logdir: pathlib.Path, datasets: Dict[str, torch.utils.data.dataset.Dataset], tensorboard_loggers: Callable = <factory>, loggers: Dict[str, tensorboardX.writer.SummaryWriter] = <factory>, top_k: int = 10)¶ Bases:
objectThis class handles the logging to the Tensorboard of an interpretation for a task
-
close(state: catalyst.core.runner.IRunner)¶ Close opened tensorboard writers
-
initialize(state: catalyst.core.runner.IRunner)¶ Initializes the tensorboard loggers.
Parameters: state – The state with which the callback is called.
-
publish(state: catalyst.core.runner.IRunner, interpretations: Dict[str, torch.Tensor])¶ Publishes all interpretations
Parameters: - state – The state with which the callback is called.
- interpretations – A dict object from task name to loss values. Also additional keys are those prefixed with “indices|{task_name}”, which hold the corresponding indices in the original dataset for which the loss items are computed.
-
top_k= 10¶
-
-
dnn_cool.catalyst_utils.compute_device_metrics(reduced, any_tensor, metrics, outputs, targets)¶
-
dnn_cool.catalyst_utils.compute_leaf_losses(leaf_criterions, outputs, reduced, targets)¶
-
dnn_cool.catalyst_utils.compute_per_sample_losses(reduced, per_sample_criterion, outputs, targets, n)¶
-
dnn_cool.catalyst_utils.default_tensorboard_type_mapping()¶
-
dnn_cool.catalyst_utils.img_publisher(writer: tensorboardX.writer.SummaryWriter, tag: str, sample: Any, idx: int)¶
-
dnn_cool.catalyst_utils.publish_all(prefix: str, idx: int, sample: Tuple[Dict[KT, VT], Dict[KT, VT]], mapping_key: str, key: str, writer: tensorboardX.writer.SummaryWriter, mapping: Mapping[KT, VT_co], task_name: str)¶ Publishes a given key given all publishers supplied via the mapping :param prefix: The prefix, this is typically either “best” or “worst”.
Parameters: - idx – The index of the sample in the dataset.
- sample – A tuple X, y where X and y and dictionaries.
- mapping_key – The key which when applied to the mapping gives a list of publishers.
- key – The key in X that is being published.
- writer – A
SummaryWriterthat logs to the tensorboard. - mapping – A mapping [str, List[Callable]] where the key are either input columns, or input types and the values are a list of publisher functions.
- task_name – The name of the task, to be included in the name
-
dnn_cool.catalyst_utils.reduce_on_device(criterion, per_sample_criterion, leaf_criterions, metrics, outputs, targets, r_device_metrics, r_leaf_losses, r_per_sample_losses)¶
-
dnn_cool.catalyst_utils.should_skip_loader(state, loaders_to_skip)¶
-
dnn_cool.catalyst_utils.text_publisher(writer: tensorboardX.writer.SummaryWriter, tag: str, sample: Any, idx: int)¶
dnn_cool.converters module¶
-
class
dnn_cool.converters.Converters(project_dir: pathlib.Path, name: str = 'converters', type: dnn_cool.converters.TypeGuesser = <factory>, values: dnn_cool.converters.ValuesConverter = <factory>, task: dnn_cool.converters.TaskConverter = <factory>, tensorboard_converters: dnn_cool.catalyst_utils.TensorboardConverter = <factory>, stats_registry: dnn_cool.verbosity.StatsRegistry = <factory>)¶ Bases:
object-
connect_to_stats_registry(stats_registry)¶
-
create_inputs_and_leaf_tasks_from_df(df: pandas.core.frame.DataFrame, input_col: Union[str, Iterable[str]], output_col: Union[str, Iterable[str]], verbosity: dnn_cool.verbosity.Verbosity = <Verbosity.SILENT: 0>)¶
-
create_leaf_task(df, col)¶
-
create_leaf_tasks(df, col)¶
-
create_task_flow_for_development(df: pandas.core.frame.DataFrame, input_col: Union[str, Iterable[str]], output_col: Union[str, Iterable[str]], task_flow: dnn_cool.tasks.TaskFlow, verbosity: dnn_cool.verbosity.Verbosity = <Verbosity.SILENT: 0>) → dnn_cool.tasks.TaskFlowForDevelopment¶
-
create_values(df, output_col)¶
-
dump_state_to_directory(converters_directory: pathlib.Path)¶
-
load_state_from_directory(converters_directory: pathlib.Path)¶
-
name= 'converters'¶
-
read_inputs(df, input_col)¶
-
state_dict()¶
-
-
class
dnn_cool.converters.StatefulConverter(col_mapping: Dict = <factory>, type_mapping: Dict = <factory>, stats_registry: dnn_cool.verbosity.StatsRegistry = <factory>)¶ Bases:
object-
connect_to_stats_registry(stats_registry)¶
-
dump_state_to_directory(directory: pathlib.Path)¶
-
load_state_from_directory(directory: pathlib.Path)¶
-
state_dict()¶
-
-
class
dnn_cool.converters.TaskConverter(col_mapping: Dict = <factory>, type_mapping: Dict = <factory>, stats_registry: dnn_cool.verbosity.StatsRegistry = <factory>)¶ Bases:
dnn_cool.converters.StatefulConverter-
to_task(output_col, guessed_type, values)¶
-
-
class
dnn_cool.converters.TypeGuesser(type_mapping: Dict = <factory>)¶ Bases:
object-
dump_state_to_directory(directory)¶
-
guess(df, output_col)¶
-
load_state_from_directory(directory: pathlib.Path)¶
-
state_dict()¶
-
-
class
dnn_cool.converters.ValuesConverter(col_mapping: Dict = <factory>, type_mapping: Dict = <factory>, stats_registry: dnn_cool.verbosity.StatsRegistry = <factory>)¶ Bases:
dnn_cool.converters.StatefulConverter-
to_values(df, col, guessed_type, perform_conversion=True)¶
-
-
dnn_cool.converters.assert_col_in_df(df, col)¶
-
dnn_cool.converters.dump_state_to_directory_when_possible(mapping, directory, stats_registry)¶
-
dnn_cool.converters.extract_state_when_possible(mapping)¶
-
dnn_cool.converters.load_state_from_directory_when_possible(mapping: Dict[KT, VT], directory: pathlib.Path, stats_registry)¶
-
dnn_cool.converters.not_found_error_message(col, df)¶
dnn_cool.datasets module¶
-
class
dnn_cool.datasets.FlowDataset(task_flow, prefix='')¶ Bases:
torch.utils.data.dataset.Dataset,dnn_cool.dsl.IFlowTask,collections.abc.Sized,typing.Generic
-
class
dnn_cool.datasets.FlowDatasetDecorator(task, prefix, labels)¶ Bases:
object
-
class
dnn_cool.datasets.FlowDatasetDict(prefix, data=None, available=None)¶ Bases:
dnn_cool.dsl.IOut-
to_dict(X)¶
-
-
class
dnn_cool.datasets.FlowDatasetPrecondition(prefix: str, path: str, precondition: torch.Tensor)¶ Bases:
dnn_cool.dsl.ICondition
-
class
dnn_cool.datasets.IndexHolder(item)¶ Bases:
dnn_cool.dsl.IFeaturesDict
-
class
dnn_cool.datasets.TensorDict¶ Bases:
dict
-
dnn_cool.datasets.discover_index_holder(*args, **kwargs)¶
dnn_cool.decoders module¶
-
class
dnn_cool.decoders.BinaryDecoder(threshold=None, metric=<function accuracy_score>)¶ Bases:
dnn_cool.decoders.Decoder-
load_tuned(params)¶ Loads a dictionary of tuned parameters.
Parameters: params – a dictionary of tuned parameters.
-
tune(predictions, targets)¶ Performs a simple grid search that optimizes the metric in the field
metric.Parameters: - predictions – The activated model predictions
- targets – The ground truth
Returns: A dictionary of tuned parameters.
-
-
class
dnn_cool.decoders.BoundedRegressionDecoder(scale=224)¶ Bases:
dnn_cool.decoders.Decoder-
load_tuned(params)¶ Loads a dictionary of tuned parameters.
Parameters: params – a dictionary of tuned parameters.
-
tune(predictions, targets)¶ Tunes any thresholds or other parameters needed for decoding.
Parameters: - predictions – The activated model predictions
- targets – The ground truth
Returns: A dictionary of tuned parameters.
-
-
class
dnn_cool.decoders.ClassificationDecoder¶ Bases:
dnn_cool.decoders.Decoder-
load_tuned(params)¶ Loads a dictionary of tuned parameters.
Parameters: params – a dictionary of tuned parameters.
-
tune(predictions, targets)¶ Tunes any thresholds or other parameters needed for decoding.
Parameters: - predictions – The activated model predictions
- targets – The ground truth
Returns: A dictionary of tuned parameters.
-
-
class
dnn_cool.decoders.CompositeDecoder(task_flow, prefix)¶
-
class
dnn_cool.decoders.DecodedData(data: Dict = <factory>)¶ Bases:
dnn_cool.visitors.VisitorOut-
reduce()¶
-
-
class
dnn_cool.decoders.Decoder¶ Bases:
objectA decoder is a
Callablewhich when invoked, returns processed task predictions so that they can be used as a precondition to other tasks.-
load_tuned(params)¶ Loads a dictionary of tuned parameters.
Parameters: params – a dictionary of tuned parameters.
-
tune(predictions, targets)¶ Tunes any thresholds or other parameters needed for decoding.
Parameters: - predictions – The activated model predictions
- targets – The ground truth
Returns: A dictionary of tuned parameters.
-
-
class
dnn_cool.decoders.DecodingVisitor(task, prefix)¶ Bases:
dnn_cool.visitors.LeafVisitor-
empty_result()¶
-
full_result(preds, targets)¶
-
preconditioned_result(preds, targets)¶
-
-
class
dnn_cool.decoders.MultilabelClassificationDecoder(metric=<function accuracy_score>)¶ Bases:
dnn_cool.decoders.Decoder-
load_tuned(params)¶ Loads a dictionary of tuned parameters.
Parameters: params – a dictionary of tuned parameters.
-
tune(predictions, targets)¶ Tunes any thresholds or other parameters needed for decoding.
Parameters: - predictions – The activated model predictions
- targets – The ground truth
Returns: A dictionary of tuned parameters.
-
-
class
dnn_cool.decoders.NoOpDecoder¶ Bases:
dnn_cool.decoders.Decoder-
load_tuned(params)¶ Loads a dictionary of tuned parameters.
Parameters: params – a dictionary of tuned parameters.
-
tune(predictions, targets)¶ Tunes any thresholds or other parameters needed for decoding.
Parameters: - predictions – The activated model predictions
- targets – The ground truth
Returns: A dictionary of tuned parameters.
-
-
class
dnn_cool.decoders.TaskFlowDecoder(task_flow, prefix='')¶ Bases:
dnn_cool.decoders.Decoder-
load_tuned(tuned_params)¶ Loads a dictionary of tuned parameters.
Parameters: params – a dictionary of tuned parameters.
-
tune(predictions, targets)¶ Tunes any thresholds or other parameters needed for decoding.
Parameters: - predictions – The activated model predictions
- targets – The ground truth
Returns: A dictionary of tuned parameters.
-
-
dnn_cool.decoders.sort_declining(x)¶
-
dnn_cool.decoders.threshold_binary(x, threshold=0.5)¶
dnn_cool.dsl module¶
-
class
dnn_cool.dsl.ICondition¶ Bases:
objectThis class represents the inferface that a class has to implement to be able to act asa a precondition to a
IFlowTaskResult.
-
class
dnn_cool.dsl.IFeaturesDict¶ Bases:
objectThis class represents the interface that a class has to implement to be an intermediary for the results in
dnn_cool.task_flow.TaskFlow.
-
class
dnn_cool.dsl.IFlowTask¶ Bases:
object
-
class
dnn_cool.dsl.IFlowTaskResult¶ Bases:
objectThis interface represents the result of a task flow.
-
class
dnn_cool.dsl.IOut¶ Bases:
objectThs interface is used to accumulate the result in a TaskFlow.
dnn_cool.evaluation module¶
-
class
dnn_cool.evaluation.EvaluationCompositeVisitor(task_flow, prefix)¶ Bases:
dnn_cool.visitors.RootCompositeVisitor-
load_tuned(tuned_params)¶
-
-
class
dnn_cool.evaluation.EvaluationResults(data: List = <factory>)¶ Bases:
dnn_cool.visitors.VisitorOut-
reduce()¶
-
dnn_cool.filter module¶
-
class
dnn_cool.filter.FilterCompositeVisitor(task_flow, prefix)¶ Bases:
dnn_cool.visitors.RootCompositeVisitor-
load_tuned(tuned_params)¶
-
-
class
dnn_cool.filter.FilterParams(predictions: Dict = <factory>, targets: Dict = <factory>)¶ Bases:
dnn_cool.visitors.VisitorOut-
reduce()¶
-
-
class
dnn_cool.filter.FilterVisitor(task, prefix)¶ Bases:
dnn_cool.visitors.LeafVisitor-
empty_result()¶
-
full_result(preds, targets)¶
-
preconditioned_result(preds, targets)¶
-
dnn_cool.losses module¶
-
class
dnn_cool.losses.BaseMetricDecorator(task_name, prefix, metric, metric_name, ctx)¶ Bases:
torch.nn.modules.module.Module-
compute_with_precondition(loss_flow_data)¶
-
forward(*args, **kwargs)¶ Defines the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
-
handle_empty_precondition(outputs)¶
-
postprocess_results(metric_res)¶
-
-
class
dnn_cool.losses.CriterionFlowData(outputs, targets)¶ Bases:
dnn_cool.dsl.IFeaturesDict-
classmethod
from_args(*args, **kwargs)¶
-
classmethod
-
class
dnn_cool.losses.DeviceReducingCache(task_name, prefix, metric, metric_name, ctx)¶ Bases:
object-
aggregate_device_result(loss_flow_data_outputs, out_key)¶
-
aggregate_device_results(loss_flow_data_outputs, out_keys)¶
-
discover_metric_keys(device_metric_key)¶
-
-
class
dnn_cool.losses.LanguageModelCrossEntropyLoss(*args, **kwargs)¶ Bases:
torch.nn.modules.module.Module-
forward(outputs, targets)¶ Defines the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
-
-
class
dnn_cool.losses.LossItems(loss_items)¶ Bases:
dnn_cool.dsl.IOut,dnn_cool.dsl.IFlowTaskResult,dnn_cool.dsl.ICondition
-
class
dnn_cool.losses.ReducedPerSample(loss, reduction)¶ Bases:
torch.nn.modules.module.Module-
forward(*args, **kwargs)¶ Defines the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
-
-
class
dnn_cool.losses.TaskCriterionDecorator(task_name, prefix, loss, metric_name, ctx)¶ Bases:
dnn_cool.losses.BaseMetricDecorator-
postprocess_results(metric_res)¶
-
-
class
dnn_cool.losses.TaskFlowCriterion(task_flow, prefix='', ctx=None)¶ Bases:
torch.nn.modules.module.Module-
catalyst_callbacks()¶
-
forward(*args)¶ TaskFlowLoss can be invoked either by giving two arguments: (outputs, targets), or bby giving a single LossFlowData argument, which holds the outputs and the targets. :param args: :return:
-
get_device_reduced_ctx()¶
-
get_leaf_losses()¶
-
get_metrics()¶
-
-
class
dnn_cool.losses.TaskFlowLossPerSample(task_flow, prefix='', ctx=None)¶ Bases:
torch.nn.modules.module.Module-
forward(outputs, targets)¶ Defines the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
-
get_leaf_losses_per_sample()¶
-
-
dnn_cool.losses.args_are_dicts(args)¶
-
dnn_cool.losses.squeeze_if_needed(tensor)¶
dnn_cool.metrics module¶
-
class
dnn_cool.metrics.BinaryAccuracy¶ Bases:
dnn_cool.metrics.TorchMetric
-
class
dnn_cool.metrics.BinaryF1Score¶ Bases:
dnn_cool.metrics.NumpyMetric
-
class
dnn_cool.metrics.BinaryPrecision¶ Bases:
dnn_cool.metrics.NumpyMetric
-
class
dnn_cool.metrics.BinaryRecall¶ Bases:
dnn_cool.metrics.NumpyMetric
-
class
dnn_cool.metrics.ClassificationAccuracy(metric_args=None)¶ Bases:
dnn_cool.metrics.TorchMetric-
empty_precondition_result()¶
-
-
class
dnn_cool.metrics.ClassificationF1Score¶
-
class
dnn_cool.metrics.ClassificationNumpyMetric(metric_fn, decode=True)¶ Bases:
dnn_cool.metrics.NumpyMetric
-
class
dnn_cool.metrics.ClassificationPrecision¶
-
class
dnn_cool.metrics.ClassificationRecall¶
-
class
dnn_cool.metrics.MeanAbsoluteError(decode=False)¶ Bases:
dnn_cool.metrics.TorchMetric
-
class
dnn_cool.metrics.MultiLabelClassificationAccuracy(metric_args=None)¶ Bases:
dnn_cool.metrics.TorchMetric
-
class
dnn_cool.metrics.NumpyMetric(metric_fn, decode=True)¶ Bases:
dnn_cool.metrics.TorchMetric
-
class
dnn_cool.metrics.TorchMetric(metric_fn, decode=True, metric_args=None)¶ Bases:
object-
bind_to_task(task)¶
-
-
dnn_cool.metrics.get_default_binary_metrics()¶
-
dnn_cool.metrics.get_default_bounded_regression_metrics()¶
-
dnn_cool.metrics.get_default_classification_metrics()¶
-
dnn_cool.metrics.get_default_multilabel_classification_metrics()¶
dnn_cool.missing_values module¶
-
dnn_cool.missing_values.all_correct(tensor)¶
-
dnn_cool.missing_values.positive_values(tensor)¶
dnn_cool.modules module¶
-
class
dnn_cool.modules.AndCondition(condition_one: dnn_cool.modules.Condition, condition_two: dnn_cool.modules.Condition)¶ Bases:
dnn_cool.modules.Condition-
get_precondition(data)¶
-
to_mask(data)¶
-
-
class
dnn_cool.modules.CompositeModuleOutput(training: bool, gt: Dict[str, torch.Tensor], prefix: str, logits: Dict[str, torch.Tensor] = <factory>, activated: Dict[str, torch.Tensor] = <factory>, decoded: Dict[str, torch.Tensor] = <factory>, preconditions: Dict[str, dnn_cool.modules.Condition] = <factory>, dropout_samples: Dict[str, torch.Tensor] = <factory>)¶ Bases:
dnn_cool.modules.IModuleOutput-
add_to_composite(other)¶
-
reduce()¶
-
-
class
dnn_cool.modules.Condition¶ Bases:
dnn_cool.dsl.ICondition-
get_precondition(data)¶
-
to_mask(data)¶
-
-
class
dnn_cool.modules.FeaturesDict(data)¶ Bases:
dnn_cool.dsl.IFeaturesDict
-
class
dnn_cool.modules.IModuleOutput¶ Bases:
dnn_cool.dsl.IFlowTaskResult,abc.ABC
-
class
dnn_cool.modules.Identity¶ Bases:
torch.nn.modules.module.Module-
forward(x)¶ Defines the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
-
-
class
dnn_cool.modules.LeafCondition(path: str)¶ Bases:
dnn_cool.modules.Condition-
get_precondition(data)¶
-
to_mask(data)¶
-
-
class
dnn_cool.modules.LeafModuleOutput(path: str, logits: torch.Tensor, precondition: dnn_cool.modules.Condition, activated: Union[torch.Tensor, NoneType], decoded: Union[torch.Tensor, NoneType], dropout_samples: Union[torch.Tensor, NoneType])¶ Bases:
dnn_cool.modules.IModuleOutput-
add_to_composite(composite_module_output)¶
-
-
class
dnn_cool.modules.ModuleDecorator(task, prefix)¶ Bases:
torch.nn.modules.module.Module-
forward(*args, **kwargs)¶ Defines the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
-
-
class
dnn_cool.modules.NegatedCondition(precondition: dnn_cool.modules.Condition)¶ Bases:
dnn_cool.modules.Condition-
get_precondition(data)¶
-
to_mask(data)¶
-
-
class
dnn_cool.modules.NestedCondition(path: str, parent: dnn_cool.modules.Condition)¶ Bases:
dnn_cool.modules.Condition-
get_precondition(data)¶
-
to_mask(data)¶
-
-
class
dnn_cool.modules.OnesCondition(path: str)¶ Bases:
dnn_cool.modules.Condition-
get_precondition(data)¶
-
to_mask(data)¶
-
-
class
dnn_cool.modules.SigmoidAndMSELoss(reduction)¶ Bases:
torch.nn.modules.module.Module-
forward(output, target)¶ Defines the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
-
-
class
dnn_cool.modules.TaskFlowModule(task_flow, prefix='')¶ Bases:
torch.nn.modules.module.Module-
forward(x)¶ Defines the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
-
load_tuned(tuned_params)¶
-
-
dnn_cool.modules.find_arg_with_gt(args, is_kwargs)¶
-
dnn_cool.modules.find_gt_and_process_args_when_training(*args, **kwargs)¶
-
dnn_cool.modules.select_gt(a_gt, k_gt)¶
dnn_cool.project module¶
dnn_cool.runner module¶
dnn_cool.synthetic_dataset module¶
dnn_cool.task_converters module¶
-
class
dnn_cool.task_converters.EfficientNetHead¶ Bases:
object-
static
create(model: Union[str, int], out_features, bias=True)¶
-
static
create_supplier(model: Union[str, int], out_features, bias=True)¶
-
in_features_dict= {'efficientnet-b0': 1280, 'efficientnet-b1': 1280, 'efficientnet-b2': 1408, 'efficientnet-b3': 1536, 'efficientnet-b4': 1792, 'efficientnet-b5': 2048, 'efficientnet-b6': 2304, 'efficientnet-b7': 2560, 'efficientnet-b8': 2816}¶
-
static
-
class
dnn_cool.task_converters.To(task_cls, module_supplier: Callable[[], torch.nn.modules.module.Module] = None, loss_supplier: Callable[[], torch.nn.modules.module.Module] = None, per_sample_loss_supplier: Callable[[], torch.nn.modules.module.Module] = None, decoder_supplier: Callable[[], dnn_cool.decoders.Decoder] = None, available_func=None, inputs=None, activation: Optional[torch.nn.modules.module.Module] = None, metrics: Tuple[str, dnn_cool.metrics.TorchMetric] = None)¶ Bases:
objectSyntactic sugar for task converters. You can achieve the same through functools.partial, but here you can give a supplier for some fields, so that the creation of the respective field is delayed.
-
class
dnn_cool.task_converters.ToEfficient(task_cls, model: Union[str, int], n_classes: int, bias=True, loss_supplier: Callable[[], torch.nn.modules.module.Module] = None, per_sample_loss_supplier: Callable[[], torch.nn.modules.module.Module] = None, decoder_supplier: Callable[[], dnn_cool.decoders.Decoder] = None, available_func=None, inputs=None, activation: Optional[torch.nn.modules.module.Module] = None, metrics: Tuple[str, dnn_cool.metrics.TorchMetric] = None)¶ Bases:
dnn_cool.task_converters.To
dnn_cool.task_flow module¶
dnn_cool.treelib module¶
-
class
dnn_cool.treelib.LeafExplainer(task_name: str, prefix: str, tree_func=<function default_leaf_tree_explainer>)¶ Bases:
object
-
class
dnn_cool.treelib.Precondition(path: str)¶ Bases:
object
-
class
dnn_cool.treelib.Results(module_output, idx=None)¶ Bases:
object
-
class
dnn_cool.treelib.TreeExplainer(task_name: str, flow_func: Callable, flow_tasks, prefix='')¶ Bases:
object
-
class
dnn_cool.treelib.TreeExplanation(tree: treelib.tree.Tree, start_node, results, prefix: str)¶ Bases:
object
-
dnn_cool.treelib.default_leaf_tree_explainer(task_name: str, decoded: numpy.ndarray, activated: numpy.ndarray, logits: numpy.ndarray, node_identifier: str) → Tuple[treelib.tree.Tree, treelib.node.Node]¶
-
dnn_cool.treelib.find_results_for_treelib(*args, **kwargs)¶
dnn_cool.tuners module¶
-
class
dnn_cool.tuners.TunedParams(data: Dict = <factory>)¶ Bases:
dnn_cool.visitors.VisitorOut-
reduce()¶
-
-
class
dnn_cool.tuners.TunerVisitor(task_flow, prefix)¶ Bases:
dnn_cool.visitors.RootCompositeVisitor-
load_tuned(tuned_params)¶
-
-
class
dnn_cool.tuners.TuningVisitor(task, prefix)¶ Bases:
dnn_cool.visitors.LeafVisitor-
empty_result()¶
-
full_result(preds, targets)¶
-
preconditioned_result(preds, targets)¶
-
dnn_cool.utils module¶
-
class
dnn_cool.utils.ImageNetNormalizer(should_divide_by_255=None, should_transpose=None)¶ Bases:
object
-
class
dnn_cool.utils.TransformedSubset(dataset, indices, sample_transforms=None)¶ Bases:
torch.utils.data.dataset.DatasetSubset of a dataset at specified indices, with additionally applied transforms.
- Arguments:
- dataset (Dataset): The whole Dataset indices (sequence): Indices in the whole set selected for subset
-
class
dnn_cool.utils.Values(keys, values, types)¶ Bases:
object
-
dnn_cool.utils.any_value(outputs)¶
-
dnn_cool.utils.check_if_should_divide(sample)¶
-
dnn_cool.utils.check_if_should_transpose(sample)¶
-
dnn_cool.utils.load_model_from_export(model, full_flow, out_directory: Union[str, pathlib.Path]) → torch.nn.modules.module.Module¶
-
dnn_cool.utils.split_dataset(n: int, test_size=0.2, random_state=None)¶
-
dnn_cool.utils.to_broadcastable_shape(tensor1, tensor2)¶
-
dnn_cool.utils.to_broadcastable_smaller(tensor1, tensor2)¶
-
dnn_cool.utils.torch_split_dataset(dataset, test_size=0.2, random_state=None)¶
-
dnn_cool.utils.train_test_val_split(n: int, random_state=None)¶
dnn_cool.value_converters module¶
-
class
dnn_cool.value_converters.ImageCoordinatesValuesConverter(dim: Union[float, numpy.ndarray])¶ Bases:
object
-
class
dnn_cool.value_converters.ImagesFromFileSystem(base_path, values)¶ Bases:
object
-
class
dnn_cool.value_converters.ImagesFromFileSystemConverter(base_path)¶ Bases:
object
-
class
dnn_cool.value_converters.MultiLabelValuesConverter¶ Bases:
object-
load_state_dict(state_dict)¶
-
state_dict()¶
-
-
dnn_cool.value_converters.binary_value_converter(values)¶
-
dnn_cool.value_converters.classification_converter(values)¶
dnn_cool.visitors module¶
-
class
dnn_cool.visitors.CompositeVisitor(task_flow, leaf_visitor_cls, visitor_out_cls, prefix='')¶ Bases:
dnn_cool.dsl.IFlowTask
-
class
dnn_cool.visitors.LeafVisitor(task, prefix)¶ Bases:
dnn_cool.dsl.IFlowTask-
empty_result()¶
-
full_result(preds, targets)¶
-
preconditioned_result(preds, targets)¶
-
-
class
dnn_cool.visitors.RootCompositeVisitor(task_flow, leaf_visitor_cls, visitor_out_cls, prefix='')¶ Bases:
dnn_cool.dsl.IFlowTask
-
class
dnn_cool.visitors.VisitorData(predictions: Dict, targets: Dict)¶ Bases:
dnn_cool.dsl.IFeaturesDict
-
class
dnn_cool.visitors.VisitorOut¶ Bases:
dnn_cool.dsl.IOut,dnn_cool.dsl.IFlowTaskResult,dnn_cool.dsl.ICondition-
reduce()¶
-
-
dnn_cool.visitors.get_visitor_data(*args, **kwargs)¶