ConceptSegmentationModel2D
- class hybrid_learning.concepts.models.concept_models.concept_segmentation.ConceptSegmentationModel2D(concept, model, layer_id, in_channels=None)[source]
Bases:
ConceptDetectionModel2DA concept model that segments the concept in an image. This is solved by a localization model with window respectively kernel size \(1\times 1\).
For a usage example compare
ConceptDetection2DTrainTestHandle.Public Data Attributes:
Inherited from : py: class:ConceptDetectionModel2D
conceptThe concept for which this model was configured.
concept_nameThe name of the associated concept if known.
main_model_stumpStump of the main model for which this instance was configured.
main_modelShortcut to access the main model.
layer_idLayer to extract concept from.
kernel_sizeSize of the convolution kernel.
in_channelsNumber of input channels.
apply_sigmoidWhether a sigmoid is applied to the output of the forward function before returning it.
apply_paddingWhether a zero-padding is applied to the input of the forward function.
settingsThe current model settings as dictionary.
Public Methods:
Inherited from : py: class:ConceptDetectionModel2D
reset_parameters()Randomly (re)initialize weight and bias.
to_embedding()Return the plain representation of the ensemble as list of
ConceptEmbedding.forward(inp)Torch model forward evaluation method.
Inherited from : py: class:Module
forward(inp)Torch model forward evaluation method.
register_buffer(name, tensor[, persistent])Adds a buffer to the module.
register_parameter(name, param)Adds a parameter to the module.
add_module(name, module)Adds a child module to the current module.
get_submodule(target)Returns the submodule given by
targetif it exists, otherwise throws an error.get_parameter(target)Returns the parameter given by
targetif it exists, otherwise throws an error.get_buffer(target)Returns the buffer given by
targetif it exists, otherwise throws an error.apply(fn)Applies
fnrecursively to every submodule (as returned by.children()) as well as self.cuda([device])Moves all model parameters and buffers to the GPU.
xpu([device])Moves all model parameters and buffers to the XPU.
cpu()Moves all model parameters and buffers to the CPU.
type(dst_type)Casts all parameters and buffers to
dst_type.float()Casts all floating point parameters and buffers to
floatdatatype.double()Casts all floating point parameters and buffers to
doubledatatype.half()Casts all floating point parameters and buffers to
halfdatatype.bfloat16()Casts all floating point parameters and buffers to
bfloat16datatype.to_empty(*, device)Moves the parameters and buffers to the specified device without copying storage.
to(*args, **kwargs)Moves and/or casts the parameters and buffers.
register_backward_hook(hook)Registers a backward hook on the module.
register_full_backward_hook(hook)Registers a backward hook on the module.
register_forward_pre_hook(hook)Registers a forward pre-hook on the module.
register_forward_hook(hook)Registers a forward hook on the module.
state_dict([destination, prefix, keep_vars])Returns a dictionary containing a whole state of the module.
load_state_dict(state_dict[, strict])Copies parameters and buffers from
state_dictinto this module and its descendants.parameters([recurse])Returns an iterator over module parameters.
named_parameters([prefix, recurse])Returns an iterator over module parameters, yielding both the name of the parameter as well as the parameter itself.
buffers([recurse])Returns an iterator over module buffers.
named_buffers([prefix, recurse])Returns an iterator over module buffers, yielding both the name of the buffer as well as the buffer itself.
children()Returns an iterator over immediate children modules.
named_children()Returns an iterator over immediate children modules, yielding both the name of the module as well as the module itself.
modules()Returns an iterator over all modules in the network.
named_modules([memo, prefix, remove_duplicate])Returns an iterator over all modules in the network, yielding both the name of the module as well as the module itself.
train([mode])Sets the module in training mode.
eval()Sets the module in evaluation mode.
requires_grad_([requires_grad])Change if autograd should record operations on parameters in this module.
zero_grad([set_to_none])Sets gradients of all model parameters to zero.
share_memory()extra_repr()Set the extra representation of the module
Special Methods:
__init__(concept, model, layer_id[, in_channels])Init.
Inherited from : py: class:ConceptDetectionModel2D
__init__(concept, model, layer_id[, in_channels])Init.
Inherited from : py: class:Module
__init__(concept, model, layer_id[, in_channels])Init.
__call__(*input, **kwargs)Call self as a function.
__setstate__(state)__getattr__(name)__setattr__(name, value)Implement setattr(self, name, value).
__delattr__(name)Implement delattr(self, name).
__repr__()Return repr(self).
__dir__()Default dir() implementation.
- Parameters
concept (SegmentationConcept2D) –
model (Module) –
layer_id (str) –
in_channels (int) –
- __init__(concept, model, layer_id, in_channels=None)[source]
Init.
Wrapper around init of a
ConceptDetectionModel2Dwith fixedkernel_sizeof \(1\times1\). For details on the arguments see the init function of the super classConceptDetectionModel2D.- Parameters
concept (SegmentationConcept2D) –
model (Module) –
layer_id (str) –
- activation: Optional[Sigmoid]
The activation layer to obtain heatmaps in
[0,1]. Defaults to a sigmoid ifapply_sigmoidis set toTrueduring init. If set toNone, no activation is applied.
- ensemble_count: int
Number of deep ensemble models. This is also the first dimension of the forward output. Each ensemble member simply is a separate convolutional layer, and all members are run in parallel.
- padding: Optional[ZeroPad2d]
The padding to apply before the convolution. Defaults to a padding such that the output size equals the input size if
apply_paddingis set toTrueduring init. If set toNone, no padding is applied.