Instructions to use halimb/depth-anything-small-hf with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use halimb/depth-anything-small-hf with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("depth-estimation", model="halimb/depth-anything-small-hf")# Load model directly from transformers import AutoImageProcessor, AutoModelForDepthEstimation processor = AutoImageProcessor.from_pretrained("halimb/depth-anything-small-hf") model = AutoModelForDepthEstimation.from_pretrained("halimb/depth-anything-small-hf") - Notebooks
- Google Colab
- Kaggle
| from typing import Dict, List, Any | |
| from transformers import pipeline | |
| import transformers | |
| from PIL import Image | |
| import base64 | |
| from io import BytesIO | |
| print('TRANSFORMERS VERSION') | |
| print(transformers.__version__) | |
| class EndpointHandler(): | |
| def __init__(self, path=""): | |
| # load pipe | |
| self.pipe = pipeline(task="depth-estimation", model=path) | |
| def __call__(self, data: Dict[str, Any]) -> List[Dict[str, Any]]: | |
| base64_image = data.pop("inputs",data) | |
| if base64_image is None: | |
| raise ValueError("No image provided") | |
| if base64_image.startswith('data:image/jpeg;base64,'): | |
| base64_image = base64_image.replace('data:image/jpeg;base64,', '') | |
| image_bytes = base64.b64decode(base64_image) | |
| image = Image.open(BytesIO(image_bytes)) | |
| depth = self.pipe(image)["depth"] | |
| return depth |