Models¶
KD_Lib.models.lenet module¶
-
class
KD_Lib.models.lenet.
LeNet
(img_size=32, num_classes=10, in_channels=3)[source]¶ Bases:
torch.nn.modules.module.Module
Implementation of a LeNet model
Parameters: - (int) (in_channels) – Dimension of input image
- (int) – Hidden layer dimension
- (int) – Number of classes for classification
- (int) – Number of channels in input specimens
-
forward
(x)[source]¶ 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
Module
instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
-
class
KD_Lib.models.lenet.
ModLeNet
(img_size=32, num_classes=10, in_channels=3)[source]¶ Bases:
torch.nn.modules.module.Module
Implementation of a ModLeNet model
Parameters: - (int) (in_channels) – Dimension of input image
- (int) – Hidden layer dimension
- (int) – Number of classes for classification
- (int) – Number of channels in input specimens
-
forward
(x)[source]¶ 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
Module
instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
KD_Lib.models.lstm module¶
-
class
KD_Lib.models.lstm.
LSTMNet
(input_dim=100, embed_dim=50, hidden_dim=32, num_classes=2, num_layers=5, dropout_prob=0, bidirectional=False, pad_idx=0)[source]¶ Bases:
torch.nn.modules.module.Module
Implementation of an LSTM model for classification
Parameters: - (int) (batch_size) – Size of the vocabulary
- (int) – Embedding dimension (word vector size)
- (int) – Hidden dimension for LSTM layers
- (int) – Number of classes for classification
- (int) – Dropout probability
- (int) – True if bidirectional LSTM needed
- (int) – Batch size of input
-
forward
(x, x_len)[source]¶ 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
Module
instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
KD_Lib.models.nin module¶
-
class
KD_Lib.models.nin.
NetworkInNetwork
(num_classes=10, in_channels=3)[source]¶ Bases:
torch.nn.modules.module.Module
Implementation of a Network In Network model
Parameters: - (int) (in_channels) – Number of classes for classification
- (int) – Number of channels in input specimens
-
forward
(x)[source]¶ 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
Module
instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
KD_Lib.models.resnet module¶
-
class
KD_Lib.models.resnet.
BasicBlock
(in_planes, planes, stride=1)[source]¶ Bases:
torch.nn.modules.module.Module
-
expansion
= 1¶
-
forward
(x)[source]¶ 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
Module
instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
-
-
class
KD_Lib.models.resnet.
Bottleneck
(in_planes, planes, stride=1)[source]¶ Bases:
torch.nn.modules.module.Module
-
expansion
= 4¶
-
forward
(x)[source]¶ 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
Module
instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
-
-
class
KD_Lib.models.resnet.
MeanResnet
(block, num_blocks, params, num_channel=3, num_classes=10)[source]¶ Bases:
KD_Lib.models.resnet.ResNet
-
forward
(x)[source]¶ 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
Module
instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
-
-
class
KD_Lib.models.resnet.
ResNet
(block, num_blocks, params, num_channel=3, num_classes=10)[source]¶ Bases:
torch.nn.modules.module.Module
-
forward
(x, out_feature=False)[source]¶ 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
Module
instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
-
-
KD_Lib.models.resnet.
ResNet101
(parameters, num_channel=3, num_classes=10, att=False, mean=False)[source]¶ Function that creates a ResNet 101 model
Parameters: - (list or tuple) (parameters) – List of parameters for the model
- (int) (num_classes) – Number of channels in input specimens
- (int) – Number of classes for classification
- (bool) (mean) – True if attention needs to be used
- (bool) – True if mean teacher model needs to be used
-
KD_Lib.models.resnet.
ResNet152
(parameters, num_channel=3, num_classes=10, att=False, mean=False)[source]¶ Function that creates a ResNet 152 model
Parameters: - (list or tuple) (parameters) – List of parameters for the model
- (int) (num_classes) – Number of channels in input specimens
- (int) – Number of classes for classification
- (bool) (mean) – True if attention needs to be used
- (bool) – True if mean teacher model needs to be used
-
KD_Lib.models.resnet.
ResNet18
(parameters, num_channel=3, num_classes=10, att=False, mean=False)[source]¶ Function that creates a ResNet 18 model
Parameters: - (list or tuple) (parameters) – List of parameters for the model
- (int) (num_classes) – Number of channels in input specimens
- (int) – Number of classes for classification
- (bool) (mean) – True if attention needs to be used
- (bool) – True if mean teacher model needs to be used
-
KD_Lib.models.resnet.
ResNet34
(parameters, num_channel=3, num_classes=10, att=False, mean=False)[source]¶ Function that creates a ResNet 34 model
Parameters: - (list or tuple) (parameters) – List of parameters for the model
- (int) (num_classes) – Number of channels in input specimens
- (int) – Number of classes for classification
- (bool) (mean) – True if attention needs to be used
- (bool) – True if mean teacher model needs to be used
-
KD_Lib.models.resnet.
ResNet50
(parameters, num_channel=3, num_classes=10, att=False, mean=False)[source]¶ Function that creates a ResNet 50 model
Parameters: - (list or tuple) (parameters) – List of parameters for the model
- (int) (num_classes) – Number of channels in input specimens
- (int) – Number of classes for classification
- (bool) (mean) – True if attention needs to be used
- (bool) – True if mean teacher model needs to be used
-
class
KD_Lib.models.resnet.
ResnetWithAT
(block, num_blocks, params, num_channel=3, num_classes=10)[source]¶ Bases:
KD_Lib.models.resnet.ResNet
-
forward
(x)[source]¶ 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
Module
instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
-
KD_Lib.models.shallow module¶
-
class
KD_Lib.models.shallow.
Shallow
(img_size=28, hidden_size=800, num_classes=10, num_channels=1)[source]¶ Bases:
torch.nn.modules.module.Module
Implementation of a Shallow model
Parameters: - (int) (num_classes) – Dimension of input image
- (int) – Hidden layer dimension
- (int) – Number of classes for classification
-
forward
(x)[source]¶ 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
Module
instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.