Model builders

This page contains class definitions of ENOT model builders.

We do not recommend you to use this functional as it can be replaced by autogeneration in most cases.

simple_block_model_builders

build_simple_block_model(in_channels, search_ops, blocks_out_channels, blocks_count, blocks_stride, width_multiplier=1.0, min_channels=8, stem=None, head=None, init_weights_kn=True)

Build sequential block model. This model is compatible for SearchSpaceModel(model).

Parameters
  • in_channels (int) – Number of input channels for model.

  • search_ops (List[str]) – List of string operations descriptions for search_blocks.

  • blocks_out_channels (list) – List of output channels for each block in the network.

  • blocks_count (list) – List of number of block repeats.

  • blocks_stride (list) – List of strides for each block in the network.

  • width_multiplier (float) – Adjusts number of channels in each layer by this amount. Default value: 1.0

  • min_channels (int) – Min_value parameter for _make_divisible function from original tf repo. It can be see here: https://github.com/tensorflow/models/blob/master/research/slim/nets/mobilenet/mobilenet.py. Default value: 8

  • stem (torch.nn.Module) – First layers of the network.

  • head (torch.nn.Module) – Last layers of the network

  • init_weights_kn (bool) – Flag for Kaiming He initialization. Default value: True

Returns

Sequence of stem (if passed), blocks, head(if passed)

Return type

torch.nn.Sequential

build_frozen_simple_block_model(in_channels, blocks_op_name, blocks_out_channels, blocks_count, blocks_stride, width_multiplier=1.0, min_channels=8, stem=None, head=None, init_weights_kn=True)

Build simple sequential block model. It use for creating searched model using string descriptions of operations.

Parameters
  • in_channels (int) – Number of input channels for model.

  • blocks_op_name (List[str]) – List of string operations descriptions for operations in the model.

  • blocks_out_channels (list) – List of output channels for each block in the network.

  • blocks_count (list) – List of number of block repeats.

  • blocks_stride (list) – List of strides for each block in the network.

  • width_multiplier (float) – Adjusts number of channels in each layer by this amount. Default value: 1.0

  • min_channels (int) – Min_value parameter for _make_divisible function from original tf repo. It can be see here: https://github.com/tensorflow/models/blob/master/research/slim/nets/mobilenet/mobilenet.py. Default value: 8

  • stem (torch.nn.Module) – First layers of the network.

  • head (torch.nn.Module) – Last layers of the network

  • init_weights_kn (bool) – Flag for Kaiming He initialization. Default value: True

Returns

Sequence of stem (if passed), blocks, head(if passed)

Return type

torch.nn.Sequential

mobilenet

build_mobilenet(search_ops, blocks_out_channels, blocks_count, blocks_stride, in_channels=3, width_multiplier=1.0, min_channels=8, stem_params=None, head_params=None, init_weights_kn=True, dropout_rate=0.0, num_classes=1000)

Build MobileNetV2 like architecture with search blocks instead of MIB. All search_ops will be in each search_block.

Parameters
  • search_ops (List[str]) – List of string operations descriptions for search_blocks.

  • blocks_out_channels (list) – List of output channels for each block in the network. Values for c from original MobileNetV2 paper.

  • blocks_count (list) – List of number of block repeats. Values for n from original MobileNetV2 paper.

  • blocks_stride (list) – List of strides for each block in the network. Values for s from original MobileNetV2 paper.

  • in_channels (int) – Number of input channels for model. Default value: 3

  • width_multiplier (float) – Adjusts number of channels in each layer by this amount. Default value: 1.0

  • min_channels (int) – Min_value parameter for _make_divisible function from original tf repo. It can be see here: https://github.com/tensorflow/models/blob/master/research/slim/nets/mobilenet/mobilenet.py. Default value: 8

  • stem_params (dict, optional) – Additional parameters for enot.mobilenet.mobilenet.stems.MobileNetBaseStem constructor. In channels for network will be use as in_channels for stem.

  • head_params (dict, optional) – Additional parameters for enot.mobilenet.mobilenet.stems.MobileNetBaseHead constructor. The last blocks_out_channels will be used as head_in_channels

  • init_weights_kn (bool) – Flag for Kaiming He initialization. Default value: True

  • dropout_rate (float) – Fraction of the neurons to drop. Default value: 0.0

  • num_classes (int) – Number of predicted classes. Default value: 1000.

Return type

Sequential

build_frozen_mobilenet(blocks_op_name, blocks_out_channels, blocks_count, blocks_stride, in_channels=3, width_multiplier=1.0, min_channels=8, stem_params=None, head_params=None, dropout_rate=0.0, num_classes=1000, init_weights_kn=True)

Construct MobileNetV2 like model with operations listed in blocks_op_name.

Parameters
  • blocks_op_name (List[str]) – List of string operations descriptions for operations in the model.

  • blocks_out_channels (list) – List of output channels for each block in the network. Values for c from original MobileNetV2 paper.

  • blocks_count (list) – List of number of block repeats. Values for n from original MobileNetV2 paper.

  • blocks_stride (list) – List of strides for each block in the network. Values for s from original MobileNetV2 paper.

  • in_channels (int) – Number of input channels for model.

  • width_multiplier (float) – Adjusts number of channels in each layer by this amount.

  • min_channels (int) – Min_value parameter for _make_divisible function from original tf repo. It can be see here: https://github.com/tensorflow/models/blob/master/research/slim/nets/mobilenet/mobilenet.py. Default value: 8

  • stem_params (dict, optional) – Additional parameters for enot.mobilenet.mobilenet.stems.MobileNetBaseStem constructor. In channels for network will be use as in_channels for stem.

  • head_params (dict, optional) – Additional parameters for enot.mobilenet.mobilenet.stems.MobileNetBaseHead constructor. The last blocks_out_channels will be used as head_in_channels

  • init_weights_kn (bool) – Flag for Kaiming He initialization. Default value: True

  • dropout_rate (float) – Fraction of the neurons to drop. Default value: 0.0

  • num_classes (int) – Number of predicted classes. Default value: 1000.

Return type

Sequential