sparseml.keras.models.classification package¶
Submodules¶
sparseml.keras.models.classification.resnet module¶
Keras ResNet implementation. Further info on ResNet can be found in the paper here.
-
class
sparseml.keras.models.classification.resnet.
ResNetSection
(num_blocks: int, out_channels: int, downsample: bool, proj_channels: int = - 1)[source]¶ Bases:
object
Settings to describe how to put together a ResNet based architecture using user supplied configurations.
- Parameters
num_blocks – the number of blocks to put in the section (ie Basic or Bottleneck blocks)
out_channels – the number of output channels from the section
downsample – True to apply stride 2 for downsampling of the input, False otherwise
proj_channels – The number of channels in the projection for a bottleneck block, if < 0 then uses basic
-
create
(name: str, x_tens: tensorflow.python.framework.ops.Tensor, training: Union[bool, tensorflow.python.framework.ops.Tensor], kernel_initializer, bias_initializer, beta_initializer, gamma_initializer) → tensorflow.python.framework.ops.Tensor[source]¶ Create the section in the current graph and scope
- Parameters
name – the name for the scope to create the section under
x_tens – The input tensor to the ResNet architecture
training – bool or Tensor to specify if the model should be run in training or inference mode
kernel_initializer – Initializer to use for the conv and fully connected kernels
bias_initializer – Initializer to use for the bias in the fully connected
beta_initializer – Initializer to use for the batch norm beta variables
gamma_initializer – Initializer to use for the batch norm gama variables
- Returns
the output tensor from the section
-
sparseml.keras.models.classification.resnet.
resnet101
(pretrained_path: Optional[str] = None, pretrained: Union[bool, str] = False, pretrained_dataset: Optional[str] = None, inputs: tensorflow.python.framework.ops.Tensor = None, training: Union[bool, tensorflow.python.framework.ops.Tensor] = True, num_classes: int = 1000, class_type: str = None, kernel_initializer=<tensorflow.python.ops.init_ops_v2.GlorotUniform object>, bias_initializer=<tensorflow.python.ops.init_ops_v2.GlorotUniform object>, beta_initializer=<tensorflow.python.ops.init_ops_v2.GlorotUniform object>, gamma_initializer=<tensorflow.python.ops.init_ops_v2.GlorotUniform object>) → tensorflow.python.keras.engine.training.Model[source]¶ Standard ResNet101 implementation; expected input shape is (B, 224, 224, 3)
- Parameters
inputs – The input tensor to the ResNet architecture
training – bool or Tensor to specify if the model should be run in training or inference mode
num_classes – The number of classes to classify
class_type – One of [single, multi, None] to support multi class training. Default single. If None, then will not add the fully connected at the end.
kernel_initializer – Initializer to use for the conv and fully connected kernels
bias_initializer – Initializer to use for the bias in the fully connected
beta_initializer – Initializer to use for the batch norm beta variables
gamma_initializer – Initializer to use for the batch norm gama variables
pretrained_path – A path to the pretrained weights to load, if provided will override the pretrained param
pretrained – True to load the default pretrained weights, a string to load a specific pretrained weight (ex: base, optim, optim-perf), or False to not load any pretrained weights
pretrained_dataset – The dataset to load pretrained weights for (ex: imagenet, mnist, etc). If not supplied will default to the one preconfigured for the model.
- Returns
the output tensor from the created graph
-
sparseml.keras.models.classification.resnet.
resnet152
(pretrained_path: Optional[str] = None, pretrained: Union[bool, str] = False, pretrained_dataset: Optional[str] = None, inputs: tensorflow.python.framework.ops.Tensor = None, training: Union[bool, tensorflow.python.framework.ops.Tensor] = True, num_classes: int = 1000, class_type: str = None, kernel_initializer=<tensorflow.python.ops.init_ops_v2.GlorotUniform object>, bias_initializer=<tensorflow.python.ops.init_ops_v2.GlorotUniform object>, beta_initializer=<tensorflow.python.ops.init_ops_v2.GlorotUniform object>, gamma_initializer=<tensorflow.python.ops.init_ops_v2.GlorotUniform object>) → tensorflow.python.keras.engine.training.Model[source]¶ Standard ResNet152 implementation; expected input shape is (B, 224, 224, 3)
- Parameters
inputs – The input tensor to the ResNet architecture
training – bool or Tensor to specify if the model should be run in training or inference mode
num_classes – The number of classes to classify
class_type – One of [single, multi, None] to support multi class training. Default single. If None, then will not add the fully connected at the end.
kernel_initializer – Initializer to use for the conv and fully connected kernels
bias_initializer – Initializer to use for the bias in the fully connected
beta_initializer – Initializer to use for the batch norm beta variables
gamma_initializer – Initializer to use for the batch norm gama variables
pretrained_path – A path to the pretrained weights to load, if provided will override the pretrained param
pretrained – True to load the default pretrained weights, a string to load a specific pretrained weight (ex: base, optim, optim-perf), or False to not load any pretrained weights
pretrained_dataset – The dataset to load pretrained weights for (ex: imagenet, mnist, etc). If not supplied will default to the one preconfigured for the model.
- Returns
the output tensor from the created graph
-
sparseml.keras.models.classification.resnet.
resnet50
(pretrained_path: Optional[str] = None, pretrained: Union[bool, str] = False, pretrained_dataset: Optional[str] = None, inputs: tensorflow.python.framework.ops.Tensor = None, training: Union[bool, tensorflow.python.framework.ops.Tensor] = True, num_classes: int = 1000, class_type: str = None, kernel_initializer=<tensorflow.python.ops.init_ops_v2.GlorotUniform object>, bias_initializer=<tensorflow.python.ops.init_ops_v2.GlorotUniform object>, beta_initializer=<tensorflow.python.ops.init_ops_v2.GlorotUniform object>, gamma_initializer=<tensorflow.python.ops.init_ops_v2.GlorotUniform object>) → tensorflow.python.keras.engine.training.Model[source]¶ Standard ResNet50 implementation; expected input shape is (B, 224, 224, 3)
- Parameters
inputs – The input tensor to the ResNet architecture
training – bool or Tensor to specify if the model should be run in training or inference mode
num_classes – The number of classes to classify
class_type – One of [single, multi, None] to support multi class training. Default single. If None, then will not add the fully connected at the end.
kernel_initializer – Initializer to use for the conv and fully connected kernels
bias_initializer – Initializer to use for the bias in the fully connected
beta_initializer – Initializer to use for the batch norm beta variables
gamma_initializer – Initializer to use for the batch norm gama variables
pretrained_path – A path to the pretrained weights to load, if provided will override the pretrained param
pretrained – True to load the default pretrained weights, a string to load a specific pretrained weight (ex: base, optim, optim-perf), or False to not load any pretrained weights
pretrained_dataset – The dataset to load pretrained weights for (ex: imagenet, mnist, etc). If not supplied will default to the one preconfigured for the model.
- Returns
the output tensor from the created graph
-
sparseml.keras.models.classification.resnet.
resnet_const
(x_tens: tensorflow.python.framework.ops.Tensor, training: Union[bool, tensorflow.python.framework.ops.Tensor], sec_settings: List[sparseml.keras.models.classification.resnet.ResNetSection], num_classes: int, class_type: str, kernel_initializer, bias_initializer, beta_initializer, gamma_initializer) → tensorflow.python.keras.engine.training.Model[source]¶ Graph constructor for ResNet implementation.
- Parameters
x_tens – The input tensor to the ResNet architecture
training – bool or Tensor to specify if the model should be run in training or inference mode
sec_settings – The settings for each section in the ResNet modoel
num_classes – The number of classes to classify
class_type – One of [single, multi, None] to support multi class training. Default single. If None, then will not add the fully connected at the end.
kernel_initializer – Initializer to use for the conv and fully connected kernels
bias_initializer – Initializer to use for the bias in the fully connected
beta_initializer – Initializer to use for the batch norm beta variables
gamma_initializer – Initializer to use for the batch norm gama variables
- Returns
the output tensor from the created graph