resnet¶
- class mfai.pytorch.models.resnet.ResNet50(num_channels=3, num_classes=1000, input_shape=None, settings=ResNet50Settings(encoder_depth=5, encoder_weights=False, encoder_stride=32))[source]¶
Bases:
Module- Parameters:
- forward(x)[source]¶
Define the computation performed at every call.
Should be overridden by all subclasses. :rtype:
TensorNote
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.
- settings_kls¶
alias of
ResNet50Settings
- class mfai.pytorch.models.resnet.ResNet50MLM(num_channels=3, num_classes=1000, input_shape=None, settings=ResNet50MLMSettings(encoder_depth=5, encoder_weights=False, encoder_stride=32, num_tokens=32, pos_embedding=False, mlp_output=False))[source]¶
Bases:
ModuleA ResNet50 model adapted for Multi-Modal Language Models (MLM). This model outputs a sequence of feature vectors instead of a single classification output.
- Parameters:
- forward(x)[source]¶
Forward function of the ResNetMLM vision encoder.
- Parameters:
x (Tensor) – tensor of shape (B, num_channels, height, width)
- Returns:
tensor of shape (B, num_tokens, num_classes)
- Return type:
Tensor
- settings_kls¶
alias of
ResNet50MLMSettings
- class mfai.pytorch.models.resnet.ResNet50MLMSettings(encoder_depth=5, encoder_weights=False, encoder_stride=32, num_tokens=32, pos_embedding=False, mlp_output=False)[source]¶
Bases:
object- Parameters:
- classmethod from_dict(kvs, *, infer_missing=False)¶
- classmethod from_json(s, *, parse_float=None, parse_int=None, parse_constant=None, infer_missing=False, **kw)¶
- classmethod schema(*, infer_missing=False, only=None, exclude=(), many=False, context=None, load_only=(), dump_only=(), partial=False, unknown=None)¶
- to_json(*, skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, indent=None, separators=None, default=None, sort_keys=False, **kw)¶
- class mfai.pytorch.models.resnet.ResNet50Settings(encoder_depth=5, encoder_weights=False, encoder_stride=32)[source]¶
Bases:
object- classmethod from_dict(kvs, *, infer_missing=False)¶
- classmethod from_json(s, *, parse_float=None, parse_int=None, parse_constant=None, infer_missing=False, **kw)¶
- classmethod schema(*, infer_missing=False, only=None, exclude=(), many=False, context=None, load_only=(), dump_only=(), partial=False, unknown=None)¶
- to_json(*, skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, indent=None, separators=None, default=None, sort_keys=False, **kw)¶
- class mfai.pytorch.models.resnet.ResNetEncoder(out_channels, depth=5, **kwargs)[source]¶
Bases:
ResNetResnet with encoder functionality such as: - output channels specification of feature tensors (produced by encoder). - patching first convolution for arbitrary input channels.
- forward(x)[source]¶
Define the computation performed at every call.
Should be overridden by all subclasses. :rtype:
list[Tensor]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_state_dict(state_dict, **kwargs)[source]¶
Copy parameters and buffers from
state_dictinto this module and its descendants.If
strictisTrue, then the keys ofstate_dictmust exactly match the keys returned by this module’sstate_dict()function.Warning
If
assignisTruethe optimizer must be created after the call toload_state_dictunlessget_swap_module_params_on_conversion()isTrue.- Parameters:
state_dict (dict) – a dict containing parameters and persistent buffers.
strict (bool, optional) – whether to strictly enforce that the keys in
state_dictmatch the keys returned by this module’sstate_dict()function. Default:Trueassign (bool, optional) – When set to
False, the properties of the tensors in the current module are preserved whereas setting it toTruepreserves properties of the Tensors in the state dict. The only exception is therequires_gradfield ofParameterfor which the value from the module is preserved. Default:Falsekwargs (Any)
- Returns:
missing_keysis a list of str containing any keys that are expectedby this module but missing from the provided
state_dict.
unexpected_keysis a list of str containing the keys that are notexpected by this module but present in the provided
state_dict.
- Return type:
NamedTuplewithmissing_keysandunexpected_keysfields
Note
If a parameter or buffer is registered as
Noneand its corresponding key exists instate_dict,load_state_dict()will raise aRuntimeError.