Struct grpc_vision_svc::image_captioning::ImageProcessor
source · pub struct ImageProcessor { /* private fields */ }
Expand description
Struct for processing images and generating captions.
Implementations§
source§impl ImageProcessor
impl ImageProcessor
sourcepub fn new(models: &Models, device: Device) -> Result<Self>
pub fn new(models: &Models, device: Device) -> Result<Self>
Creates a new instance of ImageProcessor
.
This function initializes the ImageProcessor
with the provided models and device. It loads
the BLIP and quantized BLIP models, sets up the tokenizer, and prepares the processor for
image captioning tasks.
§Arguments
models
- A reference to aModels
struct containing model configurations.device
- The device on which the models will be loaded (e.g., CPU or GPU).
§Returns
A Result
containing the new ImageProcessor
instance or an error if initialization fails.
§Errors
Returns an error if any of the required models cannot be found or initialized.
sourcepub fn process_image(&self, model: ModelType, image: &[u8]) -> Result<String>
pub fn process_image(&self, model: ModelType, image: &[u8]) -> Result<String>
Processes an image and generates a caption.
This function processes the input image using the specified model and generates a textual description of the image. It involves preprocessing the image, converting it into a tensor, passing it through the model to get image embeddings, and then generating text based on these embeddings.
§Arguments
model
- The type of model to use for processing the image.image
- A byte slice containing the image data.
§Returns
A Result
containing the generated caption as a String
or an error if processing fails.
§Errors
Returns an error if image processing or caption generation fails.
Trait Implementations§
source§impl Clone for ImageProcessor
impl Clone for ImageProcessor
source§fn clone(&self) -> ImageProcessor
fn clone(&self) -> ImageProcessor
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreAuto Trait Implementations§
impl !Freeze for ImageProcessor
impl !RefUnwindSafe for ImageProcessor
impl Send for ImageProcessor
impl Sync for ImageProcessor
impl Unpin for ImageProcessor
impl !UnwindSafe for ImageProcessor
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T
in a tonic::Request