Skip to content

Available models

Functions for creating the models (mm_cesnet_v1 and mm_cesnet_v2) share the following behavior. When the weights parameter is specified, the pre-trained weights will be downloaded and cached in the model_dir folder. The returned model will be in the evaluation mode.

On the other hand, when the weights parameter is not specified, the model will be initialized with random weights (default PyTorch behavior), and the following arguments become mandatory:

  • num_classes - the number of classes, which defines the output size of the last linear layer.
  • flowstats_input_size - the number of flow statistics features and, therefore, the input size of the first linear layer processing them.
  • ppi_input_channels - the number of channels in PPI sequences. The standard value is three for packet sizes, directions, and inter-arrival times.

Input

The models expect input in the format of tuple(batch_ppi, batch_flowstats). The shapes are:

  • batch_ppi torch.tensor (B, ppi_input_channels, 30) - batch size of B and the length of PPI sequences is required to be 30.
  • batch_flowstats torch.tensor (B, flowstats_input_size)

All Jupyter notebooks listed on the getting started page show how to feed data into the models.

models.mm_cesnet_v2

mm_cesnet_v2(
    weights=None,
    model_dir=None,
    num_classes=None,
    flowstats_input_size=None,
    ppi_input_channels=None,
)

This is a second version of the multimodal CESNET architecture. It was used in the "Encrypted traffic classification: the QUIC case" paper.

Changes from the first version
  • Global pooling was added to the CNN part processing PPI sequences, instead of a simple flattening.
  • One more Conv1D layer was added to the CNN part and the number of channels was increased.
  • The size of the MLP processing flow statistics was increased.
  • The size of the MLP processing shared representations was decreased.
  • Some dropout rates were decreased.

Parameters:

Name Type Description Default
weights Optional[MM_CESNET_V2_Weights]

If provided, the model will be initialized with these weights.

None
model_dir Optional[str]

If weights are provided, this folder will be used to store the weights.

None
num_classes Optional[int]

Number of classes.

None
flowstats_input_size Optional[int]

Size of the flow statistics input.

None
ppi_input_channels Optional[int]

Number of channels in the PPI input.

None
Source code in cesnet_models\models.py
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
def mm_cesnet_v2(weights: Optional[MM_CESNET_V2_Weights] = None,
                 model_dir: Optional[str] = None,
                 num_classes: Optional[int] = None,
                 flowstats_input_size: Optional[int] = None,
                 ppi_input_channels: Optional[int] = None,
                 ) -> Multimodal_CESNET:
    """
    This is a second version of the multimodal CESNET architecture. It was used in
    the *"Encrypted traffic classification: the QUIC case"* paper.

    Changes from the first version:
        - Global pooling was added to the CNN part processing PPI sequences, instead of a simple flattening.
        - One more Conv1D layer was added to the CNN part and the number of channels was increased.
        - The size of the MLP processing flow statistics was increased.
        - The size of the MLP processing shared representations was decreased.
        - Some dropout rates were decreased.

    Parameters:
        weights: If provided, the model will be initialized with these weights.
        model_dir: If weights are provided, this folder will be used to store the weights.
        num_classes: Number of classes.
        flowstats_input_size: Size of the flow statistics input.
        ppi_input_channels: Number of channels in the PPI input.
    """
    v2_model_configuration = {
        "conv_normalization": NormalizationEnum.BATCH_NORM,
        "linear_normalization": NormalizationEnum.BATCH_NORM,
        "cnn_ppi_num_blocks": 3,
        "cnn_ppi_channels1": 200,
        "cnn_ppi_channels2": 300,
        "cnn_ppi_channels3": 300,
        "cnn_ppi_use_pooling": True,
        "cnn_ppi_dropout_rate": 0.1,
        "mlp_flowstats_num_hidden": 2,
        "mlp_flowstats_size1": 225,
        "mlp_flowstats_size2": 225,
        "mlp_flowstats_dropout_rate": 0.1,
        "mlp_shared_num_hidden":  0,
        "mlp_shared_size": 600,
        "mlp_shared_dropout_rate": 0.2,
    }
    return _multimodal_cesnet(model_configuration=v2_model_configuration,
                              weights=weights,
                              model_dir=model_dir,
                              num_classes=num_classes,
                              flowstats_input_size=flowstats_input_size,
                              ppi_input_channels=ppi_input_channels)

models.mm_cesnet_v1

mm_cesnet_v1(
    weights=None,
    model_dir=None,
    num_classes=None,
    flowstats_input_size=None,
    ppi_input_channels=None,
)

This model was used in the "Fine-grained TLS services classification with reject option" paper.

Parameters:

Name Type Description Default
weights Optional[MM_CESNET_V1_Weights]

If provided, the model will be initialized with these weights.

None
model_dir Optional[str]

If weights are provided, this folder will be used to store the weights.

None
num_classes Optional[int]

Number of classes.

None
flowstats_input_size Optional[int]

Size of the flow statistics input.

None
ppi_input_channels Optional[int]

Number of channels in the PPI input.

None
Source code in cesnet_models\models.py
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
def mm_cesnet_v1(weights: Optional[MM_CESNET_V1_Weights] = None,
                 model_dir: Optional[str] = None,
                 num_classes: Optional[int] = None,
                 flowstats_input_size: Optional[int] = None,
                 ppi_input_channels: Optional[int] = None,
                 ) -> Multimodal_CESNET:
    """
    This model was used in the *"Fine-grained TLS services classification with reject option"* paper.

    Parameters:
        weights: If provided, the model will be initialized with these weights.
        model_dir: If weights are provided, this folder will be used to store the weights.
        num_classes: Number of classes.
        flowstats_input_size: Size of the flow statistics input.
        ppi_input_channels: Number of channels in the PPI input.
    """
    v1_model_configuration = {
        "conv_normalization": NormalizationEnum.BATCH_NORM,
        "linear_normalization": NormalizationEnum.BATCH_NORM,
        "cnn_ppi_num_blocks": 2,
        "cnn_ppi_channels1": 72,
        "cnn_ppi_channels2": 128,
        "cnn_ppi_channels3": 128,
        "cnn_ppi_use_pooling": False,
        "cnn_ppi_dropout_rate": 0.2,
        "mlp_flowstats_num_hidden": 2,
        "mlp_flowstats_size1": 64,
        "mlp_flowstats_size2": 32,
        "mlp_flowstats_dropout_rate": 0.2,
        "mlp_shared_num_hidden": 1,
        "mlp_shared_size": 480,
        "mlp_shared_dropout_rate": 0.2,
    }
    return _multimodal_cesnet(model_configuration=v1_model_configuration,
                              weights=weights,
                              model_dir=model_dir,
                              num_classes=num_classes,
                              flowstats_input_size=flowstats_input_size,
                              ppi_input_channels=ppi_input_channels)