Interface IPostprocessor<T, TInput, TOutput>
- Namespace
- AiDotNet.Interfaces
- Assembly
- AiDotNet.dll
Defines a postprocessor that transforms model outputs into final results.
public interface IPostprocessor<T, TInput, TOutput>
Type Parameters
TThe numeric type for calculations (e.g., float, double).
TInputThe input data type (model output).
TOutputThe output data type after postprocessing.
Remarks
This is the core interface for all postprocessing operations in AiDotNet. Unlike preprocessing (which follows sklearn-style Fit/Transform pattern), postprocessing typically doesn't require fitting - it transforms model outputs directly into the desired format.
For Beginners: A postprocessor is like a translator that: 1. Takes raw model output (like numbers or probabilities) 2. Converts it into something meaningful (like text, labels, or structured data)
Examples:
- Converting softmax outputs to class labels
- Decoding text from token IDs
- Applying Non-Maximum Suppression to bounding boxes
- Cleaning up OCR text output
Properties
IsConfigured
Gets whether this postprocessor requires configuration before use.
bool IsConfigured { get; }
Property Value
Remarks
Some postprocessors (like label decoders) need configuration (like label mappings). Returns true after Configure(Dictionary<string, object>?) has been called for such postprocessors. Stateless postprocessors always return true.
For Beginners: This tells you if the postprocessor is ready to use. Most postprocessors are ready immediately; some need setup first.
SupportsInverse
Gets whether this postprocessor supports inverse transformation.
bool SupportsInverse { get; }
Property Value
Remarks
Some postprocessors can reverse their transformation (e.g., converting labels back to indices). Others cannot (e.g., NMS removes information permanently).
For Beginners: If this is true, you can "undo" the transformation. This is useful for converting human-readable outputs back to model format.
Methods
Configure(Dictionary<string, object>?)
Configures the postprocessor with optional settings.
void Configure(Dictionary<string, object>? settings = null)
Parameters
settingsDictionary<string, object>Optional configuration dictionary.
Remarks
Call this method to configure postprocessors that require setup. For example, a label decoder might need a label-to-index mapping. Stateless postprocessors can ignore this call.
For Beginners: Use this to set up any options the postprocessor needs. Many postprocessors work out of the box without configuration.
Inverse(TOutput)
Reverses the postprocessing (if supported).
TInput Inverse(TOutput output)
Parameters
outputTOutputThe postprocessed result.
Returns
- TInput
The original model output format.
Remarks
Converts postprocessed results back to model output format. This is useful for converting user inputs into model-compatible format.
For Beginners: If you have a class label like "cat" and need to convert it back to model format for comparison, use this method.
Exceptions
- NotSupportedException
Thrown if inverse is not supported.
Process(TInput)
Transforms model output into the final result format.
TOutput Process(TInput input)
Parameters
inputTInputThe model output to process.
Returns
- TOutput
The postprocessed result.
Remarks
This is the main method that converts raw model output into useful results.
For Beginners: This is where the magic happens - raw model outputs become meaningful results like class labels, cleaned text, or structured data.
ProcessBatch(IEnumerable<TInput>)
Transforms a batch of model outputs.
IList<TOutput> ProcessBatch(IEnumerable<TInput> inputs)
Parameters
inputsIEnumerable<TInput>The model outputs to process.
Returns
- IList<TOutput>
The postprocessed results.
Remarks
Processes multiple inputs efficiently. The default implementation calls Process(TInput) for each input, but implementations may override for batch-optimized processing.