holoscan::ops::SegmentationPostprocessorOp
holoscan::ops::SegmentationPostprocessorOp
Operator carrying out post-processing operations on segmentation outputs.
==Named Inputs==
- in_tensor :
nvidia::gxf::TensorExpects a message containing a 32-bit floating point device tensor with name in_tensor_name. The expected data layout of this tensor is HWC, NCHW or NHWC format as specified via data_format. If batch dimension, N, is present it should be size 1.- Expects a message containing a 32-bit floating point device tensor with name
in_tensor_name. The expected data layout of this tensor is HWC, NCHW or NHWC format as specified viadata_format. If batch dimension, N, is present it should be size 1.
- Expects a message containing a 32-bit floating point device tensor with name
==Named Outputs==
- out_tensor :
nvidia::gxf::TensorEmits a message containing a device tensor named “out_tensor” that contains the segmentation labels. This tensor will have unsigned 8-bit integer data type and shape (H, W, 1).- Emits a message containing a device tensor named “out_tensor” that contains the segmentation labels. This tensor will have unsigned 8-bit integer data type and shape (H, W, 1).
==Parameters==
- allocator: Memory allocator to use for the output.
- in_tensor_name: Name of the input tensor. Optional (default:
""). - network_output_type: Network output type (e.g. ‘softmax’). Optional (default:
"softmax"). - data_format: Data format of network output. Optional (default:
"hwc"). - cuda_stream_pool:
holoscan::CudaStreamPoolinstance to allocate CUDA streams. Optional (default:nullptr).
==Device Memory Requirements==
When used with a BlockMemoryPool, this operator requires only a single device memory block (storage_type = 1) of size height * width bytes.
==Notes==
This operator may launch CUDA kernels that execute asynchronously on a CUDA stream. As a result, the compute method may return before all GPU work has completed. Downstream operators that receive data from this operator should either:
- Call
op_input.receive_cuda_stream(<port_name>)(after callingreceivefor that port) to synchronize the CUDA stream with the downstream operator’s dedicated internal stream before accessing the data. - Add a
CudaStreamConditionto delay scheduling until upstream GPU work has completed.
For more details on CUDA stream handling in Holoscan, see: https://docs.nvidia.com/holoscan/sdk-user-guide/holoscan_cuda_stream_handling.html
Inherits from: holoscan::Operator (public)
Constructors
SegmentationPostprocessorOp
Methods
setup
Define the operator specification.
Parameters
The reference to the operator specification.
start
Implement the startup logic of the operator.
This method is called multiple times over the lifecycle of the operator according to the order defined in the lifecycle, and used for heavy initialization tasks such as allocating memory resources.
compute
Implement the compute method.
This method is called by the runtime multiple times. The runtime calls this method until the operator is stopped.
Parameters
The input context of the operator.
The output context of the operator.
The execution context of the operator.
operator_type
Get the operator type.
Returns: The operator type.
id
Mutable
Const
name
Mutable
Const
Set the name of the operator.
Returns: The reference to this operator.
Parameters
The name of the operator.
fragment
Set the fragment of the operator
Overload 2
Const
Set the fragment of the operator.
Returns: The reference to this operator.
Parameters
The pointer to the fragment of the operator.
spec
Set the operator spec
Get the operator spec
Set the operator spec.
Returns: The reference to this operator.
Parameters
The operator spec.
spec_shared
Get the shared pointer to the operator spec.
Returns: The shared pointer to the operator spec.
condition
Get a shared pointer to the Condition object.
Returns: The reference to the Condition object. If the condition does not exist, return the nullptr.
Parameters
The name of the condition.
conditions
Get the conditions of the operator.
Returns: The conditions of the operator.
resource
Get a shared pointer to the Resource object.
Returns: The reference to the Resource object. If the resource does not exist, returns the nullptr.
Parameters
The name of the resource.
resources
Get the resources of the operator.
Returns: The resources of the operator.
add_arg
Add a condition to the operator (1)
Add a condition to the operator (2)
Add a resource to the operator (1)
Add a resource to the operator (2)
Add an argument to the component (1)
Add an argument to the component (2)
Add a list of arguments to the component (1)
Add a list of arguments to the component (2)
Add a condition to the operator.
Parameters
The condition to add.
is_root
Returns whether the operator is a root operator based on its fragment’s graph.
Returns: True, if the operator is a root operator; false, otherwise
is_user_defined_root
Returns whether the operator is a user-defined root operator i.e., the first operator added to the graph.
Returns: True, if the operator is a user-defined root operator; false, otherwise
is_leaf
Returns whether the operator is a leaf operator based on its fragment’s graph.
Returns: True, if the operator is a leaf operator; false, otherwise
qualified_name
Returns the fully qualified name of the operator including the name of the fragment.
Returns: std::string fully qualified name of the operator in the format: “<fragment_name>.<operator_name>“
initialize
Initialize the operator.
This function is called when the fragment is initialized by Executor::initialize_fragment().
stop
Implement the shutdown logic of the operator.
This method is called multiple times over the lifecycle of the operator according to the order defined in the lifecycle, and used for heavy deinitialization tasks such as deallocation of all resources previously assigned in start.
to_yaml_node
Get a YAML representation of the operator.
Returns: YAML node including type, specs, conditions and resources of the operator in addition to the base component properties.
graph_entity
Get the GXF GraphEntity object corresponding to this operator.
Returns: graph entity corresponding to the operator
get_data_flow_tracking_label
Get the current message label for a given input port.
This method retrieves the MessageLabel associated with data received on the specified input port. The MessageLabel contains timing and path information for data flow tracking.
This method should ideally be called after receiving data on the input port.
If the input_port_name is invalid (not found in the operator’s input ports), an error is logged and an empty MessageLabel is returned.
Returns: MessageLabel The current message label for the input port. Returns an empty MessageLabel if the port does not have a message label or if the port does not exist (logs an error in the latter case as well).
Throws: std::runtime_error If the operator backend is not GXF-compatible.
Throws: std::runtime_error If fragment is not set.
Throws: std::runtime_error If operator spec is not set.
Throws: std::runtime_error If fragment flow tracking is not enabled.
Parameters
The name of the input port.
metadata
Get a shared pointer to the dynamic metadata of this operator.
Note: currently this metadata dictionary is only active if explicitly enabled for the application by setting Fragment::is_metadata_enabled(true). When metadata is disabled the dictionary will not be populated by receive calls and will not be emitted on emit calls.
This metadata dictionary is always empty at the start of each compute call. It is populated by metadata received on input ports during InputContext::receive() calls and can be modified as desired by the operator during the compute call. Any metadata corresponding to this object will be sent on the output ports by any OutputContext::emit() calls.
Returns: The metadata dictionary for this operator.
is_metadata_enabled
Determine if metadata is enabled for this operator.
Returns: Boolean indicating if metadata is enabled (returns fragment()``->``is_metadata_enabled() if enable_metadata was not explicitly called for the operator.
enable_metadata
Enable or disable metadata for this operator.
If this method has not been used to explicitly enable or disable metadata, the value for is_metadata_enabled() will be determined by Fragment::is_metadata_enabled() when the operator is initialized.
Parameters
Boolean indicating if metadata should be enabled.
metadata_policy
Mutable
Const
Set the metadata update policy used by this operator.
The metadata policy determines how metadata is merged across multiple receive calls:
MetadataPolicy::kUpdate: Update the existing value when a key already exists.MetadataPolicy::kInplaceUpdate: Update the existing MetadataObject’s value in-place when a key already exists.MetadataPolicy::kReject: Do not modify the existing value if a key already exists.MetadataPolicy::kRaise: Raise an exception if a key already exists (default).
Parameters
The metadata update policy to be used by this operator.
receiver
If no CudaStreamPool parameter or argument already exists, add a default one.
This method is available to be called by derived classes to add a default CudaStreamPool in This method is available to be called by derived classes to add a default CudaStreamPool inthe case that the user did not pass one in as an argument tomake_operator`.
This function will not add an additional CUDA stream pool if one was already passed in as an argument to make_operator (i.e. it is in resources_) or if a “cuda_stream_pool” parameter already exists in the operator spec.
/** Return the Receiver corresponding to a specific input port.
Returns: The Receiver corresponding to the input port, if it exists. Otherwise, return nullopt.
Parameters
The name of the input port.
transmitter
Return the Transmitter corresponding to a specific output port.
Returns: The Transmitter corresponding to the output port, if it exists. Otherwise, return nullopt.
Parameters
The name of the output port.
bind_input_topic
Bind an input port to a Pub/Sub topic.
This is the programmatic override path for topic-mapped ports and takes precedence over any lower-priority IOSpec::topic() default configured in setup().
Parameters
The input port to bind.
The topic name to subscribe to.
Optional QoS profile override. When nullopt, any QoS already configured on the port (e.g. in setup()) is preserved.
If true, replace an explicitly non-PubSub connector on this port with a Pub/Sub connector.
bind_output_topic
Bind an output port to a Pub/Sub topic.
This is the programmatic override path for topic-mapped ports and takes precedence over any lower-priority IOSpec::topic() default configured in setup().
Parameters
The output port to bind.
The topic name to publish to.
Optional QoS profile override. When nullopt, any QoS already configured on the port (e.g. in setup()) is preserved.
If true, replace an explicitly non-PubSub connector on this port with a Pub/Sub connector.
input_topic
Get the configured topic name for an input port, if any.
output_topic
Get the configured topic name for an output port, if any.
input_qos
Get the effective QoS profile for an input port, if it is topic-mapped.
output_qos
Get the effective QoS profile for an output port, if it is topic-mapped.
queue_policy
Set the queue policy to be used by an input or output port.
The following IOSpec::QueuePolicy values are supported:
- QueuePolicy::kPop - If the queue is full, pop the oldest item, then add the new one.
- QueuePolicy::kReject - If the queue is full, reject (discard) the new item.
- QueuePolicy::kFault - If the queue is full, log a warning and reject the new item.
Parameters
The name of the port.
Enum flag indicating whether port_name specifies an input or output port.
The queue policy to set for the port.
input_exec_spec
output_exec_spec
dynamic_flow_func
self_shared
next_flows
Get the list of next flows connected to this operator.
Returns: A vector of FlowInfo objects representing the flows to downstream operators.
add_dynamic_flow
Overload 1
Overload 2
Overload 3
Overload 4
Add a dynamic flow from this operator to another operator using a FlowInfo object.
Parameters
The flow information object describing the connection between operators.
dynamic_flows
Get the list of dynamic flows that have been added to this operator.
Returns: A shared pointer to a vector of FlowInfo objects representing the dynamic flows.
find_flow_info
Locate a flow info in the operator’s next flows based on a given predicate.
Returns: Shared pointer to the matching FlowInfo, or nullptr if not found.
Parameters
Lambda function that takes a FlowInfo shared pointer and returns a boolean.
find_all_flow_info
Find all FlowInfo objects in the operator’s next flows that match a given condition.
Returns: A vector of shared pointers to the matching FlowInfo objects.
Parameters
A lambda function that takes a shared pointer to a FlowInfo object and returns a boolean.
async_condition
Get the internal asynchronous condition for the operator.
Note: This object is only accessible after the executor has called Operator::initialize() via run() or run_async(). If accessed during Application::compose(), it will return nullptr.
Returns: A shared pointer to the internal asynchronous condition.
stop_execution
Stop the execution of the operator.
This method is used to stop the execution of the operator by setting the internal async condition to EVENT_NEVER state, which sets the scheduling condition to NEVER. Once stopped, the operator will not be scheduled for execution (the compute() method will not be called).
Note that executing this method does not trigger the operator’s stop() method. The stop() method is called only when the scheduler deactivates all operators together.
execution_context
Get the ExecutionContext object.
Returns: The shared pointer to the ExecutionContext object.
ensure_contexts
Ensure the contexts (input/output/execution) for the operator.
This method is called by the GXFExecutor when the operator is initialized.
release_internal_resources
Internal method to clean up operator resources and prevent circular references.
This is an internal method called automatically by the GXFWrapper during operator shutdown (in GXFWrapper::stop() method). It resets std::shared_ptr fields and std::function objects such as input_exec_spec_, output_exec_spec_, next_flows_, dynamic_flows_, and dynamic_flow_func_ to break potential circular references between connected Operator objects.
This is an internal method that should never be called directly by user code. Improper use can lead to undefined behavior.
operator
defaults
is_gxf_compatible_operator_type
Check if the operator is a GXF compatible operator type.
This checks the OperatorType and returns true if it is one of {kNative, kGXF, kVirtual}.
Returns: True if the operator is a GXF compatible operator type, false otherwise.
operator std::shared_ptr< Executor > executor
has_pubsub_connector
Check if the operator has any UCX connectors.
Check if the operator has any PubSub connectors.
has_network_connector
Check if the operator has any network (UCX or PubSub) connectors.
args
Get the list of arguments.
Returns: The vector of arguments.
description
Get a description of the component.
Returns: YAML string.
See also: to_yaml_node()
service
Retrieve a registered fragment service or resource.
Retrieves a previously registered fragment service or resource by its type and optional identifier. Returns nullptr if no service/resource is found with the specified type and identifier.
Note that any changes to the service retrieval logic in this method should be synchronized with the implementation in Fragment::service() method to maintain consistency.
Returns: The shared pointer to the service/resource, or nullptr if not found or if type casting fails.
Template parameters
The type of the service/resource to retrieve. Must inherit from either Resource or FragmentService. Defaults to DefaultFragmentService if not specified.
Parameters
The identifier of the service/resource. If empty, retrieves by type only.
get_service_by_type_info
Retrieve a registered fragment service or resource for Python bindings.
This is a helper method for Python bindings to retrieve a service by its C++ type info.
Returns: The shared pointer to the base service, or nullptr if not found.
Parameters
The type info of the service/resource to retrieve.
The identifier of the service/resource. If empty, retrieves by type only.
reset_backend_objects
Reset any backend-specific objects (e.g. GXF GraphEntity).
initialize_graph_entity
This function creates a GraphEntity corresponding to the operator.
Returns: The GXF entity eid corresponding to the graph entity.
Parameters
The GXF context.
Prefix to add to the operator’s name when creating the GraphEntity.
initialize_async_condition
Initialize the internal asynchronous condition to control the operator execution.
This method is called by the GXFExecutor when the operator is initialized.
add_codelet_to_graph_entity
Add this operator as the codelet in the GXF GraphEntity.
Returns: The codelet component id corresponding to GXF codelet.
initialize_conditions
initialize_resources
update_params_from_args
Overload 1
Update parameters based on the specified arguments
update_connector_arguments
Replace any “receiver” supplied as a string with the actual receiver of that name.
Can only be called after GXFExecutor::create_input_port so the input ports (receivers) exist.
find_ports_used_by_condition_args
Determine ports whose transmitter or receiver are associated with an Arg for a Condition.
Should be called before GXFExecutor::create_input_port or GXFExecutor::create_output_port.
get_consolidated_input_label
This function returns a consolidated MessageLabel for all the input ports of an Operator.
If there is no input port (root Operator), then a new MessageLabel with the current Operator and default receive timestamp is returned.
Returns: The consolidated MessageLabel
update_input_message_label
Update the input_message_labels map with the given MessageLabel a corresponding input_name.
Parameters
The input port name for which the MessageLabel is updated
The new MessageLabel that will be set for the input port
delete_input_message_label
Delete the input_message_labels map entry for the given input_name.
Parameters
The input port name for which the MessageLabel is deleted
reset_input_message_labels
Reset the input message labels to clear all its contents.
This is done for a leaf operator when it finishes its execution as it is assumed that all its inputs are processed.
has_input_message_labels
Check if the operator has any input message labels.
num_published_messages_map
Get the number of published messages for each output port indexed by the output port name.
The function is utilized by the DFFTCollector to update the DataFlowTracker with the number of published messages for root operators.
Returns: The map of the number of published messages for every output name.
update_published_messages
This function updates the number of published messages for a given output port.
Parameters
The name of the output port
operator.void initialize_next_flows
non_default_input_ports
non_default_output_ports
set_input_exec_spec
set_output_exec_spec
set_dynamic_flows
set_self_shared
initialize_execution_context
service_provider
Set the service provider that owns this component.
Static methods
is_all_operator_successor_virtual
Returns whether all the successors of an operator are virtual operators.
Returns: true if the operator has all virtual operator successors, false otherwise
Parameters
The shared_ptr to the operator for which the check is to be performed
The graph of operators. fragment()->graph() can usually be used to get this graph.
is_all_operator_predecessor_virtual
Returns whether all the predecessors of an operator are virtual operators.
Returns: true if the operator has all virtual operator predecessors, false otherwise
Parameters
The shared_ptr to the operator for which the check is to be performed
The graph of operators. fragment()->graph() can usually be used to get this graph.
parse_port_name
Return operator name and port name from a string in the format of “<op_name>[.<port_name>]“.
parse_operator_port_key
Return operator name and port name from a string in the format of “<op_name>-<port_name>“.
register_codec
Register the codec for serialization/deserialization of a custom type.
Deprecated
Use holoscan::gxf::GXFExecutor::register_codec instead.
validate_operator_name
Validate operator name against restricted keywords and patterns.
Throws: std::invalid_argument if the name contains restricted patterns.
Parameters
The name to validate.
register_converter
Register the argument setter for the given type.
If an operator or resource has an argument with a custom type, the argument setter must be registered using this method.
The argument setter is used to set the value of the argument from the YAML configuration.
This method can be called in the initialization phase of the operator/resource (e.g., initialize()). The example below shows how to register the argument setter for the custom type (Vec3):
It is assumed that YAML::convert<T>::encode and YAML::convert<T>::decode are implemented for the given type. You need to specialize the YAML::convert<> template class.
For example, suppose that you had a Vec3 class with the following members:
You can define the YAML::convert<Vec3> as follows in a ‘.cpp’ file:
Please refer to the yaml-cpp documentation for more details.
Template parameters
The type of the argument to register.
Example
Example
Example
register_argument_setter
Register the argument setter for the given type.
Please refer to the documentation of register_converter() for more details.
Template parameters
The type of the argument to register.
Types
OperatorType
Operator type used by the executor.