File size: 1,544 Bytes
677924d 5d03982 677924d 5d03982 677924d 5d03982 677924d 5d03982 677924d 5d03982 677924d e9c8711 5d03982 677924d 5d03982 677924d 5d03982 677924d 5d03982 677924d 5d03982 677924d 5d03982 677924d 5d03982 677924d 5d03982 677924d 5d03982 677924d 5d03982 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
---
library_name: transformers
license: apache-2.0
base_model:
- apple/DepthPro-hf
pipeline_tag: depth-estimation
---
This model is a quantized version of Apple's DepthPro-hf model. The model was quantized using 4-bit bitsandbytes.
## Quantize code
```python
quantization_config = BitsAndBytesConfig(
load_in_4bit=True,
bnb_4bit_compute_dtype=torch.float16,
bnb_4bit_use_double_quant=True,
bnb_4bit_quant_type="nf4",
)
depth_model = DepthProForDepthEstimation.from_pretrained(
"apple/DepthPro-hf",
quantization_config=quantization_config,
device_map="auto",
dtype="auto",
)
```
## How to use it
```bash
pip install --upgrade transformers accelerate bitsandbytes
```
```python
import torch
from PIL import Image
from transformers import DepthProForDepthEstimation, DepthProImageProcessorFast
device = "cuda" if torch.cuda.is_available() else "cpu"
depth_model = DepthProForDepthEstimation.from_pretrained(
"CineAI/Depth-Pro-hf-4bit",
device_map="auto",
)
image_processor = DepthProImageProcessorFast.from_pretrained("apple/DepthPro-hf")
image = Image.open("image path")
image = image.convert(mode="RGB")
inputs = image_processor(images=image, return_tensors="pt").to(device)
with torch.no_grad():
outputs = depth_model(**inputs)
source_sizes = [(image.height, image.width)]
post_processed_output = image_processor.post_process_depth_estimation(outputs, target_sizes=source_sizes,)
depth = post_processed_output[0]["predicted_depth"]
depth_np = depth.cpu().detach().numpy()
depth_np
``` |