Skip to main content

VisionRuntime

Struct VisionRuntime 

Source
pub struct VisionRuntime { /* private fields */ }
Expand description

Routes vision calls to backends, prepares and releases their images, meters them, maps their answers to source pixels and escalates.

§Example

use std::sync::Arc;
use adk_vision::{DeterministicEditor, VisionRuntime};

let runtime = VisionRuntime::builder()
    .editor(Arc::new(DeterministicEditor::new()))
    .build()
    .unwrap();
assert!(runtime.backends().iter().any(|id| id.as_str() == "deterministic-editor"));

Implementations§

Source§

impl VisionRuntime

Source

pub async fn detect( &self, cx: &VisionCx, image: &SourceImage, query: &DetectQuery, ) -> Result<VisionOutput<Vec<Region>>>

Detects objects in a source image on the detection route.

§Errors

The route’s, the gate’s or the backend’s error; see detect_with.

Source

pub async fn detect_with( &self, cx: &VisionCx, image: &SourceImage, query: &DetectQuery, options: &CallOptions, ) -> Result<VisionOutput<Vec<Region>>>

Detects objects with per-call options. Regions come back in source pixels; a route with an escalation crops each uncertain region, plus margin, and sends only that.

§Errors

VisionError::BackendNotFound, the egress gate’s refusals for a remote backend, a budget or kill-switch refusal before the request, VisionError::Cancelled, or the backend’s error.

Source

pub async fn segment( &self, cx: &VisionCx, image: &SourceImage, prompts: &[SegmentPrompt], ) -> Result<VisionOutput<Vec<Region>>>

Segments a source image on the segmentation route. Prompts are in source pixels.

§Errors

As detect_with.

Source

pub async fn segment_with( &self, cx: &VisionCx, image: &SourceImage, prompts: &[SegmentPrompt], options: &CallOptions, ) -> Result<VisionOutput<Vec<Region>>>

Segments with per-call options.

§Errors

As detect_with, and VisionError::Unsupported for a mask prompt to a backend whose frame has no raster.

Source

pub async fn read( &self, cx: &VisionCx, page: &SourceImage, read: &ReadOptions, ) -> Result<VisionOutput<DocumentPage>>

Reads a document page on the reading route.

§Errors

As detect_with.

Source

pub async fn read_with( &self, cx: &VisionCx, page: &SourceImage, read: &ReadOptions, options: &CallOptions, ) -> Result<VisionOutput<DocumentPage>>

Reads with per-call options. A block below a low-confidence trigger is re-read from its crop by the escalation backend, which replaces its text with escalatedFrom provenance on its region.

§Errors

As detect_with.

Source

pub async fn describe( &self, cx: &VisionCx, images: &[&SourceImage], spec: &DescribeSpec, ) -> Result<VisionOutput<Description>>

Describes source images on the describing route.

§Errors

As detect_with.

Source

pub async fn describe_with( &self, cx: &VisionCx, images: &[&SourceImage], spec: &DescribeSpec, options: &CallOptions, ) -> Result<VisionOutput<Description>>

Describes with per-call options. On a trigger the escalation backend answers the same request, and its answer replaces the primary’s with escalatedFrom provenance.

§Errors

As detect_with, and VisionError::InvalidInput for no image.

Source

pub async fn embed_images( &self, cx: &VisionCx, images: &[&SourceImage], options: &CallOptions, ) -> Result<VisionOutput<Vec<Vec<f32>>>>

Embeds source images with the embedding route’s backend.

§Errors

As detect_with, and VisionError::Parse when the backend returns the wrong number of vectors or vectors outside its space’s dimensions.

Source

pub async fn embed_texts( &self, cx: &VisionCx, texts: &[&str], options: &CallOptions, ) -> Result<VisionOutput<Vec<Vec<f32>>>>

Embeds texts with the embedding route’s backend, into the same space as its images.

§Errors

As embed_images.

Source

pub async fn edit( &self, cx: &VisionCx, image: &SourceImage, operation: &EditOp, options: &CallOptions, ) -> Result<VisionOutput<Edited>>

Edits a source image with the edit route’s backend and stores the result with Provenance::Derived, under the context’s media scope.

§Errors

VisionError::InvalidInput without a media store or a media scope, as detect_with otherwise.

Source§

impl VisionRuntime

Source

pub async fn analyze_video( &self, cx: &VisionCx, video: VideoSource<'_>, request: &VideoRequest, ) -> Result<VisionOutput<VideoAnalysis>>

Analyses a video on the video route.

§Errors

As analyze_video_with.

Source

pub async fn analyze_video_with( &self, cx: &VisionCx, video: VideoSource<'_>, request: &VideoRequest, options: &CallOptions, ) -> Result<VisionOutput<VideoAnalysis>>

Analyses a video with per-call options.

The call opens one hold before anything is prepared (V-I6): the frames the backend analyses as UsageUnit::Frames, at its per-frame price (with its per-request minimum), at zero cost on the device, or up to its own estimate for a token-billed backend. Sampled frames are prepared as images are, released one by one through the egress gate for a remote backend; a clip is released through EgressGate::release_clip as data class video unless the options name another. Track regions come back in source pixels of the clip or of their frame, with their track identifiers.

§Errors

VisionError::InvalidInput for a call with no clip and no frame, and the errors of detect_with.

Source§

impl VisionRuntime

Source

pub fn builder() -> VisionRuntimeBuilder

A builder with no backend.

Source

pub fn embedding_space(&self, options: &CallOptions) -> Result<EmbeddingSpace>

The embedding space a call with options embeds into: the space of its embedding route’s backend. A visual memory collection records the space it was built in and refuses vectors of any other.

§Errors

VisionError::BackendNotFound when no embedder serves the call.

Source

pub fn backends(&self) -> Vec<BackendId>

Every registered backend’s id.

Source

pub fn descriptor( &self, task: VisionTask, id: &BackendId, ) -> Option<&BackendDescriptor>

The descriptor of a backend registered for task.

Source

pub fn route(&self, task: VisionTask, options: &CallOptions) -> Result<Route>

The route a call of task with options takes: the call’s own route, the task’s configured route, or the task’s default backend (the first on-device one registered, else the first remote one).

§Errors

VisionError::BackendNotFound when no backend serves the task, and VisionError::InvalidInput for a call route that names an unknown backend.

Source

pub fn egress_gate(&self) -> Option<&EgressGate>

The egress gate, if one is installed.

Source

pub fn shared_egress_gate(&self) -> Option<Arc<EgressGate>>

The egress gate as a shared handle, for an ImagePrivacyGuardrail that releases through the same gate.

Source

pub fn media_store(&self) -> Option<&MediaStore>

The media store, if one is installed.

Trait Implementations§

Source§

impl Debug for VisionRuntime

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl !RefUnwindSafe for VisionRuntime

§

impl !UnwindSafe for VisionRuntime

§

impl Forget for VisionRuntime

§

impl Freeze for VisionRuntime

§

impl Move for VisionRuntime

§

impl Send for VisionRuntime

§

impl Sync for VisionRuntime

§

impl Unpin for VisionRuntime

§

impl UnsafeUnpin for VisionRuntime

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> AsAny for T
where T: Any,

Source§

fn as_any(&self) -> &(dyn Any + 'static)

Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Source§

fn type_name(&self) -> &'static str

Gets the type name of self
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> Downcast for T
where T: AsAny + ?Sized,

Source§

fn is<T>(&self) -> bool
where T: AsAny,

Returns true if the boxed type is the same as T. Read more
Source§

fn downcast_ref<T>(&self) -> Option<&T>
where T: AsAny,

Forward to the method defined on the type Any.
Source§

fn downcast_mut<T>(&mut self) -> Option<&mut T>
where T: AsAny,

Forward to the method defined on the type Any.
Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<F, T> IntoSample<T> for F
where T: FromSample<F>,

Source§

fn into_sample(self) -> T

Source§

impl<T> MaybeSend for T
where T: Send,

Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more