codewithkyrian/transformers
A Laravel-friendly transformers package for turning models, arrays, and API responses into consistent, reusable output. Define transformer classes, map fields, nest relations, and format data cleanly for JSON APIs, with minimal boilerplate and flexible customization.
Image to text is a computer vision task that involves extracting text from images. The task accepts image inputs and returns a text related to the content of the image. The most common applications of image to text are in Image Captioning and Optical Character Recognition (OCR).
image-to-textXenova/vit-gpt2-image-captioningImage to text models find application in various scenarios, including:
Here's how to perform image to text using the pipeline:
use function Codewithkyrian\Transformers\Pipelines\pipeline;
$captioner = pipeline('image-to-text');
$result = $captioner('path/to/image.jpg');
::: details Click to view output
[
"text" => "A close up of a cat sitting on a bed"
]
:::
The task being performed here is image captioning, determined by the model used. If you want to perform OCR, you can use
a model specifically trained for that task eg. Xenova/trocr-small-handwritten, and then pass in an image of a single
line of handwritten text.
When running the image-to-text pipeline, you can the following options:
texts (string) $result = $captioner('https://example.com/image.jpg');
All other options are the same as the ones in
the text2text-generation pipeline, including the streamer.
The output is an array where each element corresponds to an input text and contains a key generated_text with the
detected text in the image.
[
[
"generated_text" => "A close up of a cat sitting on a bed"
]
]
The number of elements in the output array corresponds to the number of input images.
How can I help you explore Laravel packages today?