Skip to content

Create async Predict methods #4

@fmatulic

Description

@fmatulic

To facilitate integration in real-time applications, where invoking Predict shouldn't block the calling thread, it'd be great if there was an async version of the method, like:

public IEnumerator PredictAsync(float[] pointCoords, float[] pointLabels, Action<RenderTexture> onComplete)
{

 [...]

  yield return PredictAsync(point_coords, point_labels, mask_input, has_mask_input, orig_im_size, (result) =>
   {
     TextureConverter.RenderToTexture(result.Masks, Result, new TextureTransform().SetBroadcastChannels(true));
     onComplete?.Invoke(Result);
   });
}

with a corresponding PredictAsync for the method returning the DecoderOutput.

Then PredictAsync can be easily called from a coroutine without creating a wrapper class:

StartCoroutine(mobileSAM.PredictAsync(pointCoords, pointLabels, (result) =>
{
    if (result != null)
    {
        // Use result
    }
}));

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions