contrastive_utils.py - cmikke97/Automatic-Malware-Signature-Generation GitHub Wiki
-
import configparser- implements a basic configuration language for Python programs - configparser documentation -
import os- provides a portable way of using operating system dependent functionality - os documentation
-
import torch- tensor library like NumPy, with strong GPU support - pytorch documentation
_pairwise_distances(embeddings, squared) (function) - Computes the 2D matrix of distances between all the embeddings.
-
embeddings(arg) - Tensor of shape (batch_size, embed_dim) -
squared(arg) - Boolean. If true, output is the pairwise squared euclidean distance matrix. If false, output is the pairwise euclidean distance matrix. (default: False)
_get_anchor_positive_triplet_mask(labels) (function) - Returns a 2D mask where mask[a, p] is True iff a and p are distinct and have same label.
-
labels(arg) - Long Tensor with shape [batch_size]
_get_anchor_negative_triplet_mask(labels) (function) - Returns a 2D mask where mask[a, n] is True iff a and n have distinct labels.
-
labels(arg) - Long Tensor with shape [batch_size]
_get_triplet_mask(labels) (function) - Returns a 3D mask where mask[a, p, n] is True iff the triplet (a, p, n) is valid.
A triplet (i, j, k) is valid if:
- i, j, k are distinct
- labels[i] == labels[j] and labels[i] != labels[k]
-
labels(arg) - Long Tensor with shape [batch_size]
_batch_hard_triplet_loss(labels, embeddings, margin, squared) (function) - Builds the triplet loss over a batch of embeddings. For each anchor, gets the hardest positive and hardest negative to form a triplet.
-
labels(arg) - Labels of the current batch, of size (batch_size,) -
embeddings(arg) - Tensor of shape (batch_size, embed_dim) -
margin(arg) - Margin for triplet loss -
squared(arg) - Boolean. If true, output is the pairwise squared euclidean distance matrix. If false, output is the pairwise euclidean distance matrix. (default: False)