Pipeline

@RequiresApi(value = 27)
class Pipeline : BaseHandle

SpatialML pipeline.

Each pipeline defines a computation graph of tensors. A pipeline will not be run until it is submitted, and each submission will schedule one execution of the whole pipeline. One submitted execution will be put onto one thread in the backend, so that multiple submitted pipelines can be run concurrently.

Throws

If the usage is not allowed by the SpatialML run-time Framework, or if the framework encounters internal error and cannot perform the requested behavior.

Types

Link copied to clipboard

Color conversion types.

Link copied to clipboard

Defining the relationship between a Tensor, and undefined JS val in the JavaScript script to be executed by Pipeline.runJavaScript.

Link copied to clipboard

LiteRT / TensorFlow Lite model inference backend used to accelerate model inference.

Link copied to clipboard
class ModelNodeEncoding(val nodeName: String, val tensor: Tensor)

The association of a node in a model (TFLite, etc.) computation graph and a pipeline tensor.

Link copied to clipboard

Normalization type for normalize.

Link copied to clipboard

Norm type for norm.

Link copied to clipboard
class RunTask(pipeline: Pipeline, placeholderMap: Map<PipelineTensorPlaceholder, GlobalTensor>, condition: GlobalTensor?, waitFor: Pipeline.RunTask?)

The handle to one submitted pipeline run task.

Link copied to clipboard

Enum to determine how a matrix will be sorted.

Link copied to clipboard
Link copied to clipboard

Vertical alignment that can be used to update SceneGraphProperty.Text.VerticalAlignment.

Properties

Link copied to clipboard

The BaseHandle's implementation's destructor.

Link copied to clipboard

A helper getter to create a new local tensor in-place for an android android.graphics.Color. The R, G, B, and A values of the provided color will be set as the tensor's content automatically.

A helper getter to create a new local tensor in-place for a android android.graphics.Point. The X and Y values of the provided point will be set as the tensor's content automatically.

val Array<Color>.tensor: PipelineTensor

A helper getter to create a new local tensor in-place for an array of android.graphics.Color. The R, G, B, and A values of the provided colors will be set as the tensor's content automatically.

val Array<Point>.tensor: PipelineTensor

A helper getter to create a new local tensor in-place for an array of android android.graphics.Point. The X and Y values of the provided points will be set as the tensor's content automatically.

A helper getter to create a new local tensor in-place for a single byte scalar.

A helper getter to create a new local tensor in-place for a single double scalar.

val DoubleArray.tensor: PipelineTensor

A helper getter to create a new local tensor in-place for double array.

A helper getter to create a new local tensor in-place for a single float scalar.

val FloatArray.tensor: PipelineTensor

A helper getter to create a new local tensor in-place for a float array.

A helper getter to create a new local tensor in-place for a single int scalar.

val IntArray.tensor: PipelineTensor

A helper getter to create a new local tensor in-place for an int array.

A helper getter to create a new local tensor in-place for a single short scalar.

val ShortArray.tensor: PipelineTensor

A helper getter to create a new local tensor in-place for a short array.

A helper getter to create a new local tensor in-place for a string.

Functions

Link copied to clipboard
fun applyAffine(affineMatrix: Tensor, srcImage: Tensor, affinedImage: Tensor)

Applies the affine transform on 2D image.

Link copied to clipboard
fun applyAffinePoint(affineMatrix: Tensor, srcPoints: Tensor, affinedPoints: Tensor)

Applies the affine transform on 2D points rather than 2D images.

Link copied to clipboard
fun argmax(source: Tensor, result: Tensor)

Computes the argmax operation on a tensor, giving the indices of the maximum element of the input tensor.

Link copied to clipboard

Defines an arithmetic operator to the pipeline. The operator allows you to define complex operations between tensors. Different from the above overload which is defined by a string expression, this overload allows you to define the arithmetic operations directly, hence providing operand validations and type checks.

fun arithmetic(expression: String, operands: Array<Tensor>, result: Tensor)

Defines an arithmetic operator to the pipeline. An arithmetic operator takes in an array of PipelineTensor (size of which must be no more than 10), and write the arithmetic result into result. The arithmetic expression to be executed is defined by expression.

Link copied to clipboard
fun bitwiseAnd(tensor1: Tensor, tensor2: Tensor, result: Tensor)

Performs an bitwise-and of two input tensors.

Link copied to clipboard
fun bitwiseOr(tensor1: Tensor, tensor2: Tensor, result: Tensor)

Performs an bitwise-or of two input tensors.

Link copied to clipboard
fun bytewiseAll(operand: Tensor, result: Tensor)

Performs a byte-wise all on all the values constituting the tensor.

Link copied to clipboard
fun bytewiseAny(operand: Tensor, result: Tensor)

Performs a byte-wise any on all the values constituting the tensor.

Link copied to clipboard
fun captureMicrophone(sampleRate: Int, stereoTrackResult: Tensor, timestampResult: Tensor? = null)

Captures microphone stereo-audio track into tensors, encoded in compatible PCM format.

fun captureMicrophone(sampleRate: Int, leftTrackResult: Tensor? = null, rightTrackResult: Tensor? = null, timestampResult: Tensor? = null)

Captures microphone left and right audio track into separated tensors, encoded in compatible PCM format. Note: at least one of the leftTrackResult and the rightTrackResult must be present.

Link copied to clipboard
fun convertColor(conversionType: Pipeline.ColorConversion, source: Tensor, result: Tensor)
fun convertColor(opencvConvertStr: String, source: Tensor, result: Tensor)

Converts the color, e.g. RGB-to-Grayscale, RGB-to-BGR, etc.

Link copied to clipboard

Copies from a slice of one pipeline tensor to a slice of another tensor. The slice of the copy source must contain the same number of values as the total number of values in the copy destination.

Copies from one slice of a pipeline tensor to another. The slice of the copy source must contain the same number of values as the total number of values in the copy destination.

Copies from one pipeline tensor to a slice of another tensor. The slice of the copy source must contain the same number of values as the total number of values in the copy destination.

fun copy(src: Tensor, dst: Tensor)

Copies from one pipeline tensor to another. The two pipeline tensors, respectively denoted as src and dst, must have the same number of values.

Link copied to clipboard
fun elementwiseMax(tensor1: Tensor, tensor2: Tensor, result: Tensor)

Performs an elementwise-max of two input tensors.

Link copied to clipboard
fun elementwiseMin(tensor1: Tensor, tensor2: Tensor, result: Tensor)

Performs an elementwise-min of two input tensors.

Link copied to clipboard
fun elementwiseMultiply(tensor1: Tensor, tensor2: Tensor, result: Tensor)

Performs an elementwise-multiplication of two input tensors.

Link copied to clipboard
fun equal(tensor1: Tensor, tensor2: Tensor, result: Tensor)

Performs an elementwise-equal comparison of two input tensors.

Link copied to clipboard

Convenient method to directly create a slice of a GlobalTensor using bracket operators from a tensor. This operator overload allows SpatialML framework users to apply tensors output from previous steps as a dynamic slices.

operator fun GlobalTensor.get(vararg indexAndSkips: IntProgression): PipelineTensorSlice

Convenient method to directly create a slice of a GlobalTensor using bracket operators from IntProgression. Different from the overloaded method that uses IntRange as inputs, IntProgression allows skip and backward iteration. Similarly, there must be the same number of IntProgression inputs as the number of this tensor's dimensions.

operator fun GlobalTensor.get(vararg indices: IntRange): PipelineTensorSlice

Convenient method to directly create a slice of a GlobalTensor using bracket operators from IntRanges like 0..5, 1..2.

operator fun PipelineTensorSlice.get(channelSliceTensor: Tensor): PipelineTensorSlice

Creates a slice on channels using bracket operators from a slice tensor.

Link copied to clipboard
fun getAffine(srcPoints: Tensor, affinedPoints: Tensor, affineMatrixResult: Tensor)

Computes the 2D affine transform between two triangles.

Link copied to clipboard
fun getDepthMap(depthMapResult: Tensor)

Using PICO's depth sensor to get the depth map. The depth map's FOV is fixed at 90 degrees vertically, 109 degrees horizontally.

Link copied to clipboard
infix fun Tensor.into(jsVarName: String): Pipeline.JavaScriptIO

Defines a relationship between a Tensor and a JS var in the JavaScript script to be executed by Pipeline.runJavaScript that: will copy the tensor's content into the JavaScript var name during execution of JavaScript, but the update of the JavaScript var name will not be written back to the tensor.

Link copied to clipboard
infix fun Tensor.intoAndOutFrom(jsVarName: String): Pipeline.JavaScriptIO

Defines a relationship between a Tensor and a JS var in the JavaScript script to be executed by Pipeline.runJavaScript that: will copy the tensor's content into the JavaScript var name during execution of JavaScript, and the update of the JavaScript var name will be written back to the tensor after the execution of JavaScript.

Link copied to clipboard
fun inversion(source: Tensor, result: Tensor)

Computes the matrix inversion.

Link copied to clipboard
fun largerEqual(tensor1: Tensor, tensor2: Tensor, result: Tensor)

Performs an elementwise-large-equal comparison of two input tensors.

Link copied to clipboard
fun largerThan(tensor1: Tensor, tensor2: Tensor, result: Tensor)

Performs an elementwise-large-than comparison of two input tensors.

Link copied to clipboard
fun makeTransform(rotationVec: Tensor?, translationVec: Tensor?, scaleVec: Tensor?, result: Tensor)

Computes the 4x4 transform matrix for translation, rotation, and scale.

Link copied to clipboard

A helper function to create a new local tensor in-place for an android android.graphics.Color. The R, G, B, and A values of the provided color will be set as the tensor's content automatically.

A helper function to create a new local tensor in-place for a android android.graphics.Point. The X and Y values of the provided point will be set as the tensor's content automatically.

Creates a new local tensor inside this pipeline. The tensor have memory allocated local to the pipeline.

fun newLocalTensor(colorArray: Array<Color>): PipelineTensorLocal

A helper function to create a new local tensor in-place for an array of android.graphics.Color. The R, G, B, and A values of the provided colors will be set as the tensor's content automatically.

fun newLocalTensor(point2Array: Array<Point>): PipelineTensorLocal

A helper function to create a new local tensor in-place for an array of android android.graphics.Point. The X and Y values of the provided points will be set as the tensor's content automatically.

A helper function to create a new local tensor in-place for a single character.

fun newLocalTensor(doubleVal: Double): PipelineTensorLocal

A helper function to create a new local tensor in-place for a single double scalar.

fun newLocalTensor(doubleVal: DoubleArray): PipelineTensorLocal

A helper function to create a new local tensor in-place for a double array.

fun newLocalTensor(floatVal: Float): PipelineTensorLocal

A helper function to create a new local tensor in-place for a single float scalar.

fun newLocalTensor(floatVal: FloatArray): PipelineTensorLocal

A helper function to create a new local tensor in-place for a float array.

A helper function to create a new local tensor in-place for a single int scalar.

fun newLocalTensor(intVal: IntArray): PipelineTensorLocal

A helper function to create a new local tensor in-place for an int array.

fun newLocalTensor(shortVal: Short): PipelineTensorLocal

A helper function to create a new local tensor in-place for a single short scalar.

fun newLocalTensor(shortVal: ShortArray): PipelineTensorLocal

A helper function to create a new local tensor in-place for a short array.

fun newLocalTensor(string: String): PipelineTensorLocal

A helper function to create a new local tensor in-place for a string.

Link copied to clipboard

Creates a new placeholder tensor inside this pipeline. Different from a local tensor, a placeholder tensor has no local memory allocated in the pipeline's scope; on the contrary, the placeholder must refer to a compatible global tensor when the pipeline is submitted for execution.

Link copied to clipboard

Creates a new placeholder tensor inside this pipeline with guarantee compatibility with the a GlobalTensor, i.e., the newly created placeholder share the same configuration with the GlobalTensor. Note: a placeholder tensor has no local memory allocated in the pipeline's scope; on the contrary, the placeholder must refer to a compatible global tensor when the pipeline is submitted for execution.

Link copied to clipboard
fun newSceneFromGLTF(gltfSceneMemory: SharedMemory): PipelineTensor

Creates an SpatialML scene from a glTF file already loaded into SharedMemory. Similar to SpatialMLSession.newSceneFromGLTF but that one creates a global scene graph handle, so that multiple pipelines can share, whereas this method creates one scene graph local to the pipeline only.

Link copied to clipboard
fun nonMaximumSuppression(iou: Float, scores: Tensor, boxes: Tensor, scoresResult: Tensor? = null, boxesResult: Tensor? = null, indicesResult: Tensor? = null)

Runs non-maximum-suppression (NMS) on 2D bounding boxes.

Link copied to clipboard
fun norm(type: Pipeline.NormType, srcTensor: Tensor, result: Tensor)

Computes the norm of a tensor.

Link copied to clipboard
fun normalize(type: Pipeline.NormalizeType, source: Tensor, alphaBeta: Tensor?, result: Tensor)

Normalize a tensor.

Link copied to clipboard
fun notEqual(tensor1: Tensor, tensor2: Tensor, result: Tensor)

Performs an elementwise-not-equal comparison of two input tensors.

Link copied to clipboard
infix fun Tensor.outFrom(jsVarName: String): Pipeline.JavaScriptIO

Defines a relationship between a Tensor and a JS var in the JavaScript script to be executed by Pipeline.runJavaScript that: will write the content of the specified JS var to the tensor after the JavaScript's execution is done. The JS var will be initialized as an all-zero JS array of the corresponding datatype, with length = the total count of elements in the Tensor.

Link copied to clipboard
fun outputSounds(sampleRate: Int, audioTrack: Tensor)

Play sounds from an audio track. The audio track must be encoded in PCM format.

Link copied to clipboard
fun rectifiedVSTAccess(rightImageResult: Tensor?, leftImageResult: Tensor?, timestampResult: Tensor?, cameraMatrixResult: Tensor?)

Obtain the latest camera images. The images will be rectified internal against len distortion.

Link copied to clipboard
fun runJavaScript(script: String, jsVarIO: List<Pipeline.JavaScriptIO>)

Put a JS script into the SpatialML pipeline for execution.

Link copied to clipboard
fun runModelInference(modelName: String, modelType: Pipeline.ModelInferenceType, modelBinary: SharedMemory, inputs: Array<Pipeline.ModelNodeEncoding>, outputs: Array<Pipeline.ModelNodeEncoding>)

Runs the inference of an algorithm model provided in binary package.

Link copied to clipboard
fun singularValueDecomposition(source: Tensor, wResult: Tensor?, uResult: Tensor?, vtResult: Tensor?)

Performs singular value decomposition of a matrix.

Link copied to clipboard
fun smallerEqual(tensor1: Tensor, tensor2: Tensor, result: Tensor)

Performs an elementwise-smaller-equal comparison of two input tensors.

Link copied to clipboard
fun smallerThan(tensor1: Tensor, tensor2: Tensor, result: Tensor)

Performs an elementwise-smaller-than comparison of two input tensors.

Link copied to clipboard
fun solvePnP(objPoints: Tensor, imgPoints: Tensor, camMatrix: Tensor, rotationVecResult: Tensor? = null, translationVecResult: Tensor? = null)

Runs the OpenCV solve PnP algorithm. Solve PnP reverses the camera projection procedure: given the projected result (2D points) of the vertices of a mesh, and the original 3D coordinates of the mesh vertices corresponding to the mesh's local space, inferring the most likely pose of the mesh corresponding to the camera space.

Link copied to clipboard
fun sortMatrix(sortType: Pipeline.SortType, source: Tensor, sortedResult: Tensor?, indexResult: Tensor?)

Sort a matrix, column-by-column or row-by-row.

Link copied to clipboard
fun sortVec(source: Tensor, sortedResult: Tensor?, indexResult: Tensor?)

Sort a scalar array.

Link copied to clipboard

Submit the pipeline for one run. Note: the method only submits the run as a task, and SpatialML framework will schedule the task based on its waitFor task, the GlobalTensor it will access, and the current computation resource availability.

Link copied to clipboard
fun switchCHWAndHWC(source: Tensor, result: Tensor)

Switch tensor content between a CHW and HWC format. A tensor of CHW format means it is a multi-dimensional tensor of datatype = Tensor.DataType, and 3 dimensions: CxHxW. A tensor of HWC format means it is a multi-dimensional tensor of 2 dimensions: HxW, with datatype = Tensor.DataType.Image.

Link copied to clipboard
fun switchSceneVisibility(sceneEntity: Tensor, visible: Tensor)

Control the visibility of an already-loaded scene graph tensor.

Link copied to clipboard
fun updateSceneGraphProperty(sceneEntity: Tensor, entityPath: String, targetProperty: SceneGraphProperty, data: Tensor)

Updates data of a specified component property in the scene graph, using the values from a tensor.

Link copied to clipboard
fun updateSceneGraphTextContent(sceneEntity: Tensor, entityPath: String, text: String)

Updates data of text content of a text component in the scene graph using a text String.

Link copied to clipboard
fun updateSceneGraphTextHorizontalAlignment(sceneEntity: Tensor, entityPath: String, horizontalAlignment: Pipeline.TextHorizontalAlignment)

Updates data of horizontal alignment of a text component in the scene graph using the alignment enum defined in TextHorizontalAlignment.

Link copied to clipboard
fun updateSceneGraphTextVerticalAlignment(sceneEntity: Tensor, entityPath: String, verticalAlignment: Pipeline.TextVerticalAlignment)

Updates data of vertical alignment of a text component in the scene graph using the alignment enum defined in TextVerticalAlignment.

Link copied to clipboard
fun uvTo3DInCameraSpace(uv: Tensor, timestamp: Tensor, camMatrix: Tensor, leftImage: Tensor, rightImage: Tensor, point3Result: Tensor)

Using PICO's depth sensor and stereo view RGB images, estimate the 3D coordinates of 2D points on camera output.