Class UltrasoundClassifier

Online ultrasound gesture classifier — ResNet-18 (single-frame B-mode in, softmax probabilities out) driven through the Python.NET bridge.

JSON configuration

Use these block entries inside a pipeline configuration. Input names must match other blocks in that pipeline; device addresses and file paths must match your setup.

"UsClassifier": {
  "Type":   "UltrasoundClassifier",
  "Inputs": ["Ultrasound", "Buffer"],
  "Params": ["your_classifier_module", 9, 224, 224, 1e-4, 42, ""]
}

How Type, Inputs and Params work · Block catalogue and parameter reference

Inheritance
UltrasoundClassifier
Namespace: MOSAIC.Models.MachineLearning
Assembly: MOSAIC.dll
Syntax
public sealed class UltrasoundClassifier : BaseBlock, INotifyPropertyChanged, INotifyPropertyChanging, ISubscriber, IPublisher, IBaseBlockProps, IJsonExportable, IDisposable, IAsyncDisposable
Remarks

Designed to mirror PyPredictorRegression so the two predictor families share UI / wiring patterns. Each incoming MathNet.Numerics.LinearAlgebra.Matrix<T> from an upstream ultrasound source is treated as one B-mode frame; the block pushes it through the Python Model, receives a softmax probability vector of length NumClasses, and publishes it downstream.

Training data is accumulated by an upstream TriggerBuffer: segments arrive as (Vector Target, Matrix Data) tuples where the target's first element is the class index and the matrix's rows are successive frame samples for that label. The ViewModel calls TrainIncremental(List<(string Label, Matrix<double> Targets, Matrix<double> Data)>, int, int, double?, double, double, string?) to dispatch them through the Python model's train_incremental entry point.

JSON configuration:

"UsClassifier": {
  "Type":   "UltrasoundClassifier",
  "Inputs": ["Ultrasound", "Buffer"],
  "Params": ["your_classifier_module", 9, 224, 224, 1e-4, 42, ""]
}

Params: [ modulePath, numClasses, inH, inW, learningRate, randomSeed, modelPath ]. The public repository does not include pretrained weights; modelPath must point to a user-generated or independently licensed artifact.

Constructors

UltrasoundClassifier(string, double, string, int, int, int, double, int, string, bool)

Declaration
public UltrasoundClassifier(string name, double desiredRate, string modulePath, int numClasses = 9, int inH = 224, int inW = 224, double learningRate = 0.0001, int randomSeed = 42, string modelPath = "", bool isRegression = false)
Parameters
Type Name Description
string name
double desiredRate
string modulePath
int numClasses
int inH
int inW
double learningRate
int randomSeed
string modelPath
bool isRegression

Fields

VizUpdateIntervalMs

Declaration
private const int VizUpdateIntervalMs = 16
Field Value
Type Description
int

_inH

Declaration
[ObservableProperty]
private int _inH
Field Value
Type Description
int

_inW

Declaration
[ObservableProperty]
private int _inW
Field Value
Type Description
int

_isRegression

Declaration
[ObservableProperty]
private bool _isRegression
Field Value
Type Description
bool

_isTrained

Declaration
[ObservableProperty]
private bool _isTrained
Field Value
Type Description
bool

_isTraining

Declaration
[ObservableProperty]
private bool _isTraining
Field Value
Type Description
bool

_lastFrameH

Declaration
private int _lastFrameH
Field Value
Type Description
int

_lastVizUpdate

Declaration
private DateTime _lastVizUpdate
Field Value
Type Description
DateTime

_learningRate

Declaration
[ObservableProperty]
private double _learningRate
Field Value
Type Description
double

_model

Declaration
private dynamic? _model
Field Value
Type Description
dynamic

_modelDescription

Declaration
[ObservableProperty]
private string _modelDescription
Field Value
Type Description
string

_modelPath

Path where the model's state_dict is saved / loaded. Initially populated from the JSON config's modelPath param; the UI's TextBox binds to this so the user can edit it and click Save/Load. Empty = no file associated yet.

Declaration
[ObservableProperty]
private string _modelPath
Field Value
Type Description
string

_modulePath

Declaration
[ObservableProperty]
private string _modulePath
Field Value
Type Description
string

_np

Declaration
private dynamic? _np
Field Value
Type Description
dynamic

_numClasses

Declaration
[ObservableProperty]
private int _numClasses
Field Value
Type Description
int

_predictedClass

Declaration
[ObservableProperty]
private int _predictedClass
Field Value
Type Description
int

_predictedConfidence

Declaration
[ObservableProperty]
private double _predictedConfidence
Field Value
Type Description
double

_predictionCount

Declaration
[ObservableProperty]
private long _predictionCount
Field Value
Type Description
long

_randomSeed

Declaration
[ObservableProperty]
private int _randomSeed
Field Value
Type Description
int

_viz

Visualization bundle for live prediction output. Settable so the ViewModel can attach its own instance (mirrors IncrementalPredictor's pattern, where the VM owns the visualization and the block feeds it).

Declaration
private BlockVisualization _viz
Field Value
Type Description
BlockVisualization

Properties

Buffer

Declaration
public TriggerBuffer? Buffer { get; set; }
Property Value
Type Description
TriggerBuffer

DumpFilePrefix

Recordings from this block are named <block>_predictions.csv.

Declaration
protected override string DumpFilePrefix { get; }
Property Value
Type Description
string
Overrides
BaseBlock.DumpFilePrefix

InH

Declaration
[ExcludeFromCodeCoverage]
public int InH { get; set; }
Property Value
Type Description
int

InW

Declaration
[ExcludeFromCodeCoverage]
public int InW { get; set; }
Property Value
Type Description
int

IsRegression

Declaration
[ExcludeFromCodeCoverage]
public bool IsRegression { get; set; }
Property Value
Type Description
bool

IsTrained

Declaration
[ExcludeFromCodeCoverage]
public bool IsTrained { get; set; }
Property Value
Type Description
bool

IsTraining

Declaration
[ExcludeFromCodeCoverage]
public bool IsTraining { get; set; }
Property Value
Type Description
bool

JsonTypeName

Block type identifier for JSON serialization. Override for a custom name.

Declaration
protected override string JsonTypeName { get; }
Property Value
Type Description
string
Overrides
BaseBlock.JsonTypeName

LearningRate

Declaration
[ExcludeFromCodeCoverage]
public double LearningRate { get; set; }
Property Value
Type Description
double

MaxInputs

Needs exactly two inputs (e.g. a data stream + a Trigger/TriggerBuffer).

Declaration
public override int MaxInputs { get; }
Property Value
Type Description
int
Overrides
BaseBlock.MaxInputs

MinInputs

Needs exactly two inputs (e.g. a data stream + a Trigger/TriggerBuffer).

Declaration
public override int MinInputs { get; }
Property Value
Type Description
int
Overrides
BaseBlock.MinInputs

ModelDescription

Declaration
[ExcludeFromCodeCoverage]
public string ModelDescription { get; set; }
Property Value
Type Description
string

ModelPath

Path where the model's state_dict is saved / loaded. Initially populated from the JSON config's modelPath param; the UI's TextBox binds to this so the user can edit it and click Save/Load. Empty = no file associated yet.

Declaration
[ExcludeFromCodeCoverage]
public string ModelPath { get; set; }
Property Value
Type Description
string

ModulePath

Declaration
[ExcludeFromCodeCoverage]
public string ModulePath { get; set; }
Property Value
Type Description
string

NumClasses

Declaration
[ExcludeFromCodeCoverage]
public int NumClasses { get; set; }
Property Value
Type Description
int

PredictedClass

Declaration
[ExcludeFromCodeCoverage]
public int PredictedClass { get; set; }
Property Value
Type Description
int

PredictedConfidence

Declaration
[ExcludeFromCodeCoverage]
public double PredictedConfidence { get; set; }
Property Value
Type Description
double

PredictionCount

Declaration
[ExcludeFromCodeCoverage]
public long PredictionCount { get; set; }
Property Value
Type Description
long

RandomSeed

Declaration
[ExcludeFromCodeCoverage]
public int RandomSeed { get; set; }
Property Value
Type Description
int

Visualization

This block's visualization, or null when it has none.

Declaration
protected override BlockVisualization? Visualization { get; }
Property Value
Type Description
BlockVisualization
Overrides
BaseBlock.Visualization
Remarks

Blocks own their scope as a public Viz property rather than inheriting one, so the base class has no way to reach it. Overriding this is what lets the rate below be wired up automatically. With correct publication metadata, the bundle derives the time axis for one vector per publication or fixed-size contiguous sample packets from the feed shape.

When a plot needs a rate that publication frequency and feed shape cannot express (for example, variable-sized packets or overlapping windows), declare it with Viz.UpdateSignalRate. An explicit declaration wins over the derived rate. A block with several bundles must configure each one; this hook exposes only one bundle.

Viz

Live plot for this block. Assigned by the ViewModel, which owns the scope.

Declaration
public BlockVisualization Viz { get; set; }
Property Value
Type Description
BlockVisualization
Remarks

Setting this re-pushes the publish rate: the rate is normally pushed when it changes, which for these blocks happens during construction — before the ViewModel has handed over the scope — so without this the scope would never learn its time base.

Methods

ConfigureInput(IServiceProvider, JsonModel)

Declaration
public static UltrasoundClassifier ConfigureInput(IServiceProvider sp, JsonModel m)
Parameters
Type Name Description
IServiceProvider sp
JsonModel m
Returns
Type Description
UltrasoundClassifier

GetDouble(object?, double)

Declaration
private static double GetDouble(object? v, double fallback)
Parameters
Type Name Description
object v
double fallback
Returns
Type Description
double

GetJsonParams()

Block-specific parameters for JSON. Override to provide custom parameters.

Declaration
protected override IReadOnlyList<object>? GetJsonParams()
Returns
Type Description
IReadOnlyList<object>

The values for Params, in the order this block's ConfigureInput reads them, or null when the block takes no parameters.

Overrides
BaseBlock.GetJsonParams()

LoadModel(string?)

Load a previously-saved state_dict from path (or ModelPath if null/empty). Sets IsTrained so the card stops showing the "untrained" indicator.

Declaration
public void LoadModel(string? path = null)
Parameters
Type Name Description
string path

OnInHChanged(int)

Executes the logic for when InH just changed.

Declaration
private void OnInHChanged(int value)
Parameters
Type Name Description
int value

The new property value that was set.

Remarks

This method is invoked right after the value of InH is changed.

OnInHChanged(int, int)

Executes the logic for when InH just changed.

Declaration
private void OnInHChanged(int oldValue, int newValue)
Parameters
Type Name Description
int oldValue

The previous property value that was replaced.

int newValue

The new property value that was set.

Remarks

This method is invoked right after the value of InH is changed.

OnInHChanging(int)

Executes the logic for when InH is changing.

Declaration
private void OnInHChanging(int value)
Parameters
Type Name Description
int value

The new property value being set.

Remarks

This method is invoked right before the value of InH is changed.

OnInHChanging(int, int)

Executes the logic for when InH is changing.

Declaration
private void OnInHChanging(int oldValue, int newValue)
Parameters
Type Name Description
int oldValue

The previous property value that is being replaced.

int newValue

The new property value being set.

Remarks

This method is invoked right before the value of InH is changed.

OnInWChanged(int)

Executes the logic for when InW just changed.

Declaration
private void OnInWChanged(int value)
Parameters
Type Name Description
int value

The new property value that was set.

Remarks

This method is invoked right after the value of InW is changed.

OnInWChanged(int, int)

Executes the logic for when InW just changed.

Declaration
private void OnInWChanged(int oldValue, int newValue)
Parameters
Type Name Description
int oldValue

The previous property value that was replaced.

int newValue

The new property value that was set.

Remarks

This method is invoked right after the value of InW is changed.

OnInWChanging(int)

Executes the logic for when InW is changing.

Declaration
private void OnInWChanging(int value)
Parameters
Type Name Description
int value

The new property value being set.

Remarks

This method is invoked right before the value of InW is changed.

OnInWChanging(int, int)

Executes the logic for when InW is changing.

Declaration
private void OnInWChanging(int oldValue, int newValue)
Parameters
Type Name Description
int oldValue

The previous property value that is being replaced.

int newValue

The new property value being set.

Remarks

This method is invoked right before the value of InW is changed.

OnIsRegressionChanged(bool)

Executes the logic for when IsRegression just changed.

Declaration
private void OnIsRegressionChanged(bool value)
Parameters
Type Name Description
bool value

The new property value that was set.

Remarks

This method is invoked right after the value of IsRegression is changed.

OnIsRegressionChanged(bool, bool)

Executes the logic for when IsRegression just changed.

Declaration
private void OnIsRegressionChanged(bool oldValue, bool newValue)
Parameters
Type Name Description
bool oldValue

The previous property value that was replaced.

bool newValue

The new property value that was set.

Remarks

This method is invoked right after the value of IsRegression is changed.

OnIsRegressionChanging(bool)

Executes the logic for when IsRegression is changing.

Declaration
private void OnIsRegressionChanging(bool value)
Parameters
Type Name Description
bool value

The new property value being set.

Remarks

This method is invoked right before the value of IsRegression is changed.

OnIsRegressionChanging(bool, bool)

Executes the logic for when IsRegression is changing.

Declaration
private void OnIsRegressionChanging(bool oldValue, bool newValue)
Parameters
Type Name Description
bool oldValue

The previous property value that is being replaced.

bool newValue

The new property value being set.

Remarks

This method is invoked right before the value of IsRegression is changed.

OnIsTrainedChanged(bool)

Executes the logic for when IsTrained just changed.

Declaration
private void OnIsTrainedChanged(bool value)
Parameters
Type Name Description
bool value

The new property value that was set.

Remarks

This method is invoked right after the value of IsTrained is changed.

OnIsTrainedChanged(bool, bool)

Executes the logic for when IsTrained just changed.

Declaration
private void OnIsTrainedChanged(bool oldValue, bool newValue)
Parameters
Type Name Description
bool oldValue

The previous property value that was replaced.

bool newValue

The new property value that was set.

Remarks

This method is invoked right after the value of IsTrained is changed.

OnIsTrainedChanging(bool)

Executes the logic for when IsTrained is changing.

Declaration
private void OnIsTrainedChanging(bool value)
Parameters
Type Name Description
bool value

The new property value being set.

Remarks

This method is invoked right before the value of IsTrained is changed.

OnIsTrainedChanging(bool, bool)

Executes the logic for when IsTrained is changing.

Declaration
private void OnIsTrainedChanging(bool oldValue, bool newValue)
Parameters
Type Name Description
bool oldValue

The previous property value that is being replaced.

bool newValue

The new property value being set.

Remarks

This method is invoked right before the value of IsTrained is changed.

OnIsTrainingChanged(bool)

Executes the logic for when IsTraining just changed.

Declaration
private void OnIsTrainingChanged(bool value)
Parameters
Type Name Description
bool value

The new property value that was set.

Remarks

This method is invoked right after the value of IsTraining is changed.

OnIsTrainingChanged(bool, bool)

Executes the logic for when IsTraining just changed.

Declaration
private void OnIsTrainingChanged(bool oldValue, bool newValue)
Parameters
Type Name Description
bool oldValue

The previous property value that was replaced.

bool newValue

The new property value that was set.

Remarks

This method is invoked right after the value of IsTraining is changed.

OnIsTrainingChanging(bool)

Executes the logic for when IsTraining is changing.

Declaration
private void OnIsTrainingChanging(bool value)
Parameters
Type Name Description
bool value

The new property value being set.

Remarks

This method is invoked right before the value of IsTraining is changed.

OnIsTrainingChanging(bool, bool)

Executes the logic for when IsTraining is changing.

Declaration
private void OnIsTrainingChanging(bool oldValue, bool newValue)
Parameters
Type Name Description
bool oldValue

The previous property value that is being replaced.

bool newValue

The new property value being set.

Remarks

This method is invoked right before the value of IsTraining is changed.

OnLearningRateChanged(double)

Executes the logic for when LearningRate just changed.

Declaration
private void OnLearningRateChanged(double value)
Parameters
Type Name Description
double value

The new property value that was set.

Remarks

This method is invoked right after the value of LearningRate is changed.

OnLearningRateChanged(double, double)

Executes the logic for when LearningRate just changed.

Declaration
private void OnLearningRateChanged(double oldValue, double newValue)
Parameters
Type Name Description
double oldValue

The previous property value that was replaced.

double newValue

The new property value that was set.

Remarks

This method is invoked right after the value of LearningRate is changed.

OnLearningRateChanging(double)

Executes the logic for when LearningRate is changing.

Declaration
private void OnLearningRateChanging(double value)
Parameters
Type Name Description
double value

The new property value being set.

Remarks

This method is invoked right before the value of LearningRate is changed.

OnLearningRateChanging(double, double)

Executes the logic for when LearningRate is changing.

Declaration
private void OnLearningRateChanging(double oldValue, double newValue)
Parameters
Type Name Description
double oldValue

The previous property value that is being replaced.

double newValue

The new property value being set.

Remarks

This method is invoked right before the value of LearningRate is changed.

OnModelDescriptionChanged(string)

Executes the logic for when ModelDescription just changed.

Declaration
private void OnModelDescriptionChanged(string value)
Parameters
Type Name Description
string value

The new property value that was set.

Remarks

This method is invoked right after the value of ModelDescription is changed.

OnModelDescriptionChanged(string?, string)

Executes the logic for when ModelDescription just changed.

Declaration
private void OnModelDescriptionChanged(string? oldValue, string newValue)
Parameters
Type Name Description
string oldValue

The previous property value that was replaced.

string newValue

The new property value that was set.

Remarks

This method is invoked right after the value of ModelDescription is changed.

OnModelDescriptionChanging(string)

Executes the logic for when ModelDescription is changing.

Declaration
private void OnModelDescriptionChanging(string value)
Parameters
Type Name Description
string value

The new property value being set.

Remarks

This method is invoked right before the value of ModelDescription is changed.

OnModelDescriptionChanging(string?, string)

Executes the logic for when ModelDescription is changing.

Declaration
private void OnModelDescriptionChanging(string? oldValue, string newValue)
Parameters
Type Name Description
string oldValue

The previous property value that is being replaced.

string newValue

The new property value being set.

Remarks

This method is invoked right before the value of ModelDescription is changed.

OnModelPathChanged(string)

Executes the logic for when ModelPath just changed.

Declaration
private void OnModelPathChanged(string value)
Parameters
Type Name Description
string value

The new property value that was set.

Remarks

This method is invoked right after the value of ModelPath is changed.

OnModelPathChanged(string?, string)

Executes the logic for when ModelPath just changed.

Declaration
private void OnModelPathChanged(string? oldValue, string newValue)
Parameters
Type Name Description
string oldValue

The previous property value that was replaced.

string newValue

The new property value that was set.

Remarks

This method is invoked right after the value of ModelPath is changed.

OnModelPathChanging(string)

Executes the logic for when ModelPath is changing.

Declaration
private void OnModelPathChanging(string value)
Parameters
Type Name Description
string value

The new property value being set.

Remarks

This method is invoked right before the value of ModelPath is changed.

OnModelPathChanging(string?, string)

Executes the logic for when ModelPath is changing.

Declaration
private void OnModelPathChanging(string? oldValue, string newValue)
Parameters
Type Name Description
string oldValue

The previous property value that is being replaced.

string newValue

The new property value being set.

Remarks

This method is invoked right before the value of ModelPath is changed.

OnModulePathChanged(string)

Executes the logic for when ModulePath just changed.

Declaration
private void OnModulePathChanged(string value)
Parameters
Type Name Description
string value

The new property value that was set.

Remarks

This method is invoked right after the value of ModulePath is changed.

OnModulePathChanged(string?, string)

Executes the logic for when ModulePath just changed.

Declaration
private void OnModulePathChanged(string? oldValue, string newValue)
Parameters
Type Name Description
string oldValue

The previous property value that was replaced.

string newValue

The new property value that was set.

Remarks

This method is invoked right after the value of ModulePath is changed.

OnModulePathChanging(string)

Executes the logic for when ModulePath is changing.

Declaration
private void OnModulePathChanging(string value)
Parameters
Type Name Description
string value

The new property value being set.

Remarks

This method is invoked right before the value of ModulePath is changed.

OnModulePathChanging(string?, string)

Executes the logic for when ModulePath is changing.

Declaration
private void OnModulePathChanging(string? oldValue, string newValue)
Parameters
Type Name Description
string oldValue

The previous property value that is being replaced.

string newValue

The new property value being set.

Remarks

This method is invoked right before the value of ModulePath is changed.

OnNumClassesChanged(int)

Executes the logic for when NumClasses just changed.

Declaration
private void OnNumClassesChanged(int value)
Parameters
Type Name Description
int value

The new property value that was set.

Remarks

This method is invoked right after the value of NumClasses is changed.

OnNumClassesChanged(int, int)

Executes the logic for when NumClasses just changed.

Declaration
private void OnNumClassesChanged(int oldValue, int newValue)
Parameters
Type Name Description
int oldValue

The previous property value that was replaced.

int newValue

The new property value that was set.

Remarks

This method is invoked right after the value of NumClasses is changed.

OnNumClassesChanging(int)

Executes the logic for when NumClasses is changing.

Declaration
private void OnNumClassesChanging(int value)
Parameters
Type Name Description
int value

The new property value being set.

Remarks

This method is invoked right before the value of NumClasses is changed.

OnNumClassesChanging(int, int)

Executes the logic for when NumClasses is changing.

Declaration
private void OnNumClassesChanging(int oldValue, int newValue)
Parameters
Type Name Description
int oldValue

The previous property value that is being replaced.

int newValue

The new property value being set.

Remarks

This method is invoked right before the value of NumClasses is changed.

OnPredictedClassChanged(int)

Executes the logic for when PredictedClass just changed.

Declaration
private void OnPredictedClassChanged(int value)
Parameters
Type Name Description
int value

The new property value that was set.

Remarks

This method is invoked right after the value of PredictedClass is changed.

OnPredictedClassChanged(int, int)

Executes the logic for when PredictedClass just changed.

Declaration
private void OnPredictedClassChanged(int oldValue, int newValue)
Parameters
Type Name Description
int oldValue

The previous property value that was replaced.

int newValue

The new property value that was set.

Remarks

This method is invoked right after the value of PredictedClass is changed.

OnPredictedClassChanging(int)

Executes the logic for when PredictedClass is changing.

Declaration
private void OnPredictedClassChanging(int value)
Parameters
Type Name Description
int value

The new property value being set.

Remarks

This method is invoked right before the value of PredictedClass is changed.

OnPredictedClassChanging(int, int)

Executes the logic for when PredictedClass is changing.

Declaration
private void OnPredictedClassChanging(int oldValue, int newValue)
Parameters
Type Name Description
int oldValue

The previous property value that is being replaced.

int newValue

The new property value being set.

Remarks

This method is invoked right before the value of PredictedClass is changed.

OnPredictedConfidenceChanged(double)

Executes the logic for when PredictedConfidence just changed.

Declaration
private void OnPredictedConfidenceChanged(double value)
Parameters
Type Name Description
double value

The new property value that was set.

Remarks

This method is invoked right after the value of PredictedConfidence is changed.

OnPredictedConfidenceChanged(double, double)

Executes the logic for when PredictedConfidence just changed.

Declaration
private void OnPredictedConfidenceChanged(double oldValue, double newValue)
Parameters
Type Name Description
double oldValue

The previous property value that was replaced.

double newValue

The new property value that was set.

Remarks

This method is invoked right after the value of PredictedConfidence is changed.

OnPredictedConfidenceChanging(double)

Executes the logic for when PredictedConfidence is changing.

Declaration
private void OnPredictedConfidenceChanging(double value)
Parameters
Type Name Description
double value

The new property value being set.

Remarks

This method is invoked right before the value of PredictedConfidence is changed.

OnPredictedConfidenceChanging(double, double)

Executes the logic for when PredictedConfidence is changing.

Declaration
private void OnPredictedConfidenceChanging(double oldValue, double newValue)
Parameters
Type Name Description
double oldValue

The previous property value that is being replaced.

double newValue

The new property value being set.

Remarks

This method is invoked right before the value of PredictedConfidence is changed.

OnPredictionCountChanged(long)

Executes the logic for when PredictionCount just changed.

Declaration
private void OnPredictionCountChanged(long value)
Parameters
Type Name Description
long value

The new property value that was set.

Remarks

This method is invoked right after the value of PredictionCount is changed.

OnPredictionCountChanged(long, long)

Executes the logic for when PredictionCount just changed.

Declaration
private void OnPredictionCountChanged(long oldValue, long newValue)
Parameters
Type Name Description
long oldValue

The previous property value that was replaced.

long newValue

The new property value that was set.

Remarks

This method is invoked right after the value of PredictionCount is changed.

OnPredictionCountChanging(long)

Executes the logic for when PredictionCount is changing.

Declaration
private void OnPredictionCountChanging(long value)
Parameters
Type Name Description
long value

The new property value being set.

Remarks

This method is invoked right before the value of PredictionCount is changed.

OnPredictionCountChanging(long, long)

Executes the logic for when PredictionCount is changing.

Declaration
private void OnPredictionCountChanging(long oldValue, long newValue)
Parameters
Type Name Description
long oldValue

The previous property value that is being replaced.

long newValue

The new property value being set.

Remarks

This method is invoked right before the value of PredictionCount is changed.

OnRandomSeedChanged(int)

Executes the logic for when RandomSeed just changed.

Declaration
private void OnRandomSeedChanged(int value)
Parameters
Type Name Description
int value

The new property value that was set.

Remarks

This method is invoked right after the value of RandomSeed is changed.

OnRandomSeedChanged(int, int)

Executes the logic for when RandomSeed just changed.

Declaration
private void OnRandomSeedChanged(int oldValue, int newValue)
Parameters
Type Name Description
int oldValue

The previous property value that was replaced.

int newValue

The new property value that was set.

Remarks

This method is invoked right after the value of RandomSeed is changed.

OnRandomSeedChanging(int)

Executes the logic for when RandomSeed is changing.

Declaration
private void OnRandomSeedChanging(int value)
Parameters
Type Name Description
int value

The new property value being set.

Remarks

This method is invoked right before the value of RandomSeed is changed.

OnRandomSeedChanging(int, int)

Executes the logic for when RandomSeed is changing.

Declaration
private void OnRandomSeedChanging(int oldValue, int newValue)
Parameters
Type Name Description
int oldValue

The previous property value that is being replaced.

int newValue

The new property value being set.

Remarks

This method is invoked right before the value of RandomSeed is changed.

OnReceive(object, object)

Routes incoming data: TriggerBuffer senders update the training buffer reference, anything else is treated as a live ultrasound frame and forwarded to Predict(Matrix<double>).

Declaration
protected override void OnReceive(object sender, object data)
Parameters
Type Name Description
object sender
object data
Overrides
BaseBlock.OnReceive(object, object)

ParseBoolish(object?)

Coerces a JSON-supplied value to a bool. Accepts native bool, strings "true"/"false"/"1"/"0"/"yes"/"no", integer 0/1, and the string forms of all of those (which is what most JSON deserialisers give us when the target type is object).

Declaration
private static bool ParseBoolish(object? v)
Parameters
Type Name Description
object v
Returns
Type Description
bool

Predict(Matrix<double>)

Push one frame through the network and publish softmax probabilities.

Declaration
private void Predict(Matrix<double> frame)
Parameters
Type Name Description
Matrix<double> frame

ResetModel()

Declaration
public void ResetModel()

ResetToCheckpoint()

Declaration
public void ResetToCheckpoint()

SaveModel(string?)

Save the current model state_dict to path (or ModelPath if path is null/empty). Updates ModelPath on success so future Load presses default to the same location.

Declaration
public void SaveModel(string? path = null)
Parameters
Type Name Description
string path

StackClusters(List<(string Label, Matrix<double> Targets, Matrix<double> Data)>, int, bool, int)

Split the buffer's vertically-stacked segment data back into individual frames and produce a parallel array of integer class labels.

Declaration
private static (Matrix<double>[] frames, long[]? classLabels, double[]? regLabels) StackClusters(List<(string Label, Matrix<double> Targets, Matrix<double> Data)> clusters, int frameH, bool isRegression, int numOutputs)
Parameters
Type Name Description
List<(string Label, Matrix<double> Targets, Matrix<double> Data)> clusters

Database entries from dB.

int frameH

Expected height of each frame, used to slice stacked rows back into per-frame matrices. Must match the ultrasound capture's row count.

bool isRegression

When true, builds a row-major flat array of per-frame regression targets sized N × numOutputs; when false, builds an N-length array of integer class indices.

int numOutputs

Number of regression output channels (used only when isRegression is true; pads / truncates the target vector to this exact length).

Returns
Type Description
(Matrix<double>[] frames, long[] classLabels, double[] regLabels)

frames — per-frame matrices, length N. classLabels — int64 class indices (null in regression mode). regLabels — flat float64 array of length N × numOutputs (null in classification mode).

Remarks

TriggerBuffer stacks every incoming matrix vertically inside a session, so a session that captured N frames of shape H × W ends up as a single (N × H) × W matrix. We unstack it back into N frames by slicing the row range [k×H, (k+1)×H) for each frame index k, using the frame height frameH as the slice size.

All segments in a session share the single class label stored at target[0] — labels are per-segment, not per-frame, because the upstream Trigger fires once per gesture.

TrainIncremental(List<(string Label, Matrix<double> Targets, Matrix<double> Data)>, int, int, double?, double, double, string?)

Train (or fine-tune) the network on labelled segments accumulated by the upstream TriggerBuffer.

Declaration
public void TrainIncremental(List<(string Label, Matrix<double> Targets, Matrix<double> Data)> clusters, int epochs = 10, int batchSize = 16, double? lr = null, double weightDecay = 1E-05, double gradientClip = 1, string? savePath = null)
Parameters
Type Name Description
List<(string Label, Matrix<double> Targets, Matrix<double> Data)> clusters

Each entry is one labelled recording session — Label is the human-readable gesture name (unused here, kept for buffer-API parity), Target's first element gives the class index, and Data's rows are successive captured ultrasound frames stacked vertically.

int epochs
int batchSize
double? lr
double weightDecay
double gradientClip
string savePath

UpdateDescription()

Declaration
private void UpdateDescription()

Events

OnBufferSegmentAdded

Declaration
public event Action? OnBufferSegmentAdded
Event Type
Type Description
Action

OnPrediction

Declaration
public event Action<Vector<double>>? OnPrediction
Event Type
Type Description
Action<Vector<double>>

OnTrainingStateChanged

Declaration
public event Action<bool>? OnTrainingStateChanged
Event Type
Type Description
Action<bool>

Implements

INotifyPropertyChanged
INotifyPropertyChanging
ISubscriber
IPublisher
IBaseBlockProps
IJsonExportable
IDisposable
IAsyncDisposable

Search documentation

Start typing to search the documentation.