Instructions to use Thomasboosinger/owlv2-large-patch14 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use Thomasboosinger/owlv2-large-patch14 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("zero-shot-object-detection", model="Thomasboosinger/owlv2-large-patch14")# Load model directly from transformers import AutoProcessor, AutoModelForZeroShotObjectDetection processor = AutoProcessor.from_pretrained("Thomasboosinger/owlv2-large-patch14") model = AutoModelForZeroShotObjectDetection.from_pretrained("Thomasboosinger/owlv2-large-patch14") - Notebooks
- Google Colab
- Kaggle
| from transformers import pipeline | |
| from PIL import Image | |
| from io import BytesIO | |
| import base64 | |
| from typing import Dict, List, Any | |
| class EndpointHandler(): | |
| def __init__(self, model_path=""): | |
| # Initialize the pipeline with the specified model and set the device to GPU | |
| self.pipeline = pipeline(task="zero-shot-object-detection", model=model_path, device=0) | |
| def __call__(self, data: Dict[str, Any]) -> List[Dict[str, Any]]: | |
| """ | |
| Process an incoming request for zero-shot object detection. | |
| Args: | |
| data (Dict[str, Any]): The input data containing an encoded image and candidate labels. | |
| Returns: | |
| A list of dictionaries, each containing a label and its corresponding score. | |
| """ | |
| # Correctly accessing the 'inputs' key and fixing the typo in 'candidates' | |
| inputs = data.get("inputs", {}) | |
| # Decode the base64 image to a PIL image | |
| image = Image.open(BytesIO(base64.b64decode(inputs['image']))) | |
| # Get candidate labels | |
| candidate_labels=inputs["candidates"] | |
| # Correctly passing the image and candidate labels to the pipeline | |
| detection_results = self.pipeline(image=image, candidate_labels=inputs["candidates"], threshold = 0) | |
| # Adjusting the return statement to match the expected output structure | |
| return detection_results | |