Core#
- class streamer.core.buffer.MemBuffer(buffer_size=20, dist_mode='similarity')[source]#
Buffer class that maintains size of inputs to the temporal encoding model. The buffer replaces low prediction error inputs with high prediction error values while maintaining the order they were received in.
- Parameters:
buffer_size (int) – The maximum buffer size to maintain
dist_mode (str) – The distance mode for error calculation (e.g., ‘similarity’, ‘distance’)
- add_input(x, err)[source]#
Adds a single input and its corresponding error value to the buffer. If the buffer is full, this function takes care of replacing the low prediction error value if the new value is higher.
- Parameters:
x (torch.Tensor) – The input tensor to be added to the buffer
err (torch.Tensor) – The corresponding error or similarity value.
- class streamer.core.demarcation.EventDemarcation(dem_mode, dist_mode, **kwargs)[source]#
Define different Demarcation strategies
- Parameters:
dem_mode (str) – the type of demarcation loss: [‘fixed’, ‘accum’, ‘average’]
dist_mode (str) – the type of demarcation loss: [‘similarity’, ‘distance’]
threshold (float) – error or similarity threshold value. Only used with ‘accum’ and ‘fixed’ demarcation modes
window_size (int) – Window size for moving average. Only used for ‘average’ demarcation mode
modifier_type (str) – type of change to average: [‘add’, ‘multiply’]. Only used for ‘average’ demarcation mode
modifier (float) – multiplier to change the average value as threshold. Only used for ‘average’ demarcation mode
- class streamer.core.loss.StreamerLoss(dist_mode)[source]#
Streamer loss function is applied to minimize the distance between the prediction and actual input. Implemented for Cosine Similarity and Euclidean distance. Use only Cosine Similarity as it backpropagates bounded loss values across layers.
- Parameters:
dist_mode (str) – The distance mode: [‘similarity’, ‘distance’]
- forward(context, groundtruth)[source]#
Calculates the loss value from context and groundtruth
- Parameters:
context (torch.Tensor) – The prediction tensor. shape=[1,3,H,W] or [1,feature_dim]
groundtruth (torch.Tensor) – The groundtruth tensor. shape=[1,3,H,W] or [1,feature_dim]
- Returns:
(dict): dictionary of all the losses
(float): the loss value to be used for demarcation (i.e., input to the
__call__()
)