Depth Estimation
Transformers
Safetensors
PyTorch
English
depth_anything
computer-vision
absolute depth
Run this model with HF Jobs
Run Boxiang/depth_chm on Hugging Face's managed compute, monitor its progress, and retrieve the results when it's done.
Paste one of these prompts into your coding agent:
Fine-tune on my dataset
Use HF Jobs to fine-tune https://huggingface.co/Boxiang/depth_chm. Ask me which dataset to train on, then push the fine-tuned model to a new model repo. Run `hf jobs --help` first to learn the CLI.
Run batch inference
Use HF Jobs to run batch inference with https://huggingface.co/Boxiang/depth_chm on the inputs in a mounted HF Bucket. Ask me which Bucket to use, then write the outputs back to it and keep each input ID. Run `hf jobs --help` first to learn the CLI.
Instructions to use Boxiang/depth_chm with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use Boxiang/depth_chm with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("depth-estimation", model="Boxiang/depth_chm")# pip install -U transformers accelerate # Load model directly from transformers import AutoImageProcessor, AutoModelForDepthEstimation processor = AutoImageProcessor.from_pretrained("Boxiang/depth_chm") model = AutoModelForDepthEstimation.from_pretrained("Boxiang/depth_chm", device_map="auto") - Notebooks
- Google Colab
- Kaggle
Upload README.md with huggingface_hub
Browse files123456789---license: apache-2.0base_model:- depth-anything/Depth-Anything-V2-Large- depth-anything/Depth-Anything-V2-Base- depth-anything/Depth-Anything-V2-Smallpipeline_tag: depth-estimationlibrary_name: transformers---123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151# Depth-CHM ModelA fine-tuned Depth Anything V2 model for depth estimation, trained on forest canopy height data.## Model DescriptionThis model is based on [Depth-Anything-V2-Metric-Indoor-Base](https://huggingface.co/depth-anything/Depth-Anything-V2-Metric-Indoor-Base-hf) and fine-tuned for estimating depth/canopy height from aerial imagery.### Training Details- **Base Model**: depth-anything/Depth-Anything-V2-Metric-Indoor-Base-hf- **Max Depth**: 40.0 meters- **Loss Function**: SiLog + 0.1 * L1 Loss- **Hyperparameter Tuning**: Optuna (50 trials)## Installation```bashpip install transformers torch pillow numpy```## Usage### Method 1: Using Pipeline (Recommended)The simplest way to use the model:```pythonfrom transformers import pipelinefrom PIL import Imageimport numpy as np# Load pipelinepipe = pipeline(task="depth-estimation", model="Boxiang/depth_chm")# Load imageimage = Image.open("your_image.png").convert("RGB")# Run inferenceresult = pipe(image)depth_image = result["depth"] # PIL Image (normalized 0-255)# Convert to numpy array and scale to actual depth (0-40m)max_depth = 40.0depth = np.array(depth_image).astype(np.float32) / 255.0 * max_depthprint(f"Depth shape: {depth.shape}")print(f"Depth range: [{depth.min():.2f}, {depth.max():.2f}] meters")```### Method 2: Using AutoImageProcessor + ModelFor more control over the inference process:```pythonimport torchimport torch.nn.functional as Ffrom transformers import AutoImageProcessor, DepthAnythingForDepthEstimationfrom PIL import Imageimport numpy as np# Configurationmodel_id = "Boxiang/depth_chm"max_depth = 40.0# Load model and processorprocessor = AutoImageProcessor.from_pretrained(model_id)model = DepthAnythingForDepthEstimation.from_pretrained(model_id)# Use GPU if availabledevice = torch.device("cuda" if torch.cuda.is_available() else "cpu")model = model.to(device)model.eval()# Load and process imageimage = Image.open("your_image.png").convert("RGB")original_size = image.size # (width, height)# Prepare inputinputs = processor(images=image, return_tensors="pt")pixel_values = inputs["pixel_values"].to(device)# Run inferencewith torch.no_grad():outputs = model(pixel_values)predicted_depth = outputs.predicted_depth# Scale by max_depthpred_scaled = predicted_depth * max_depth# Resize to original image sizedepth = F.interpolate(pred_scaled.unsqueeze(0),size=(original_size[1], original_size[0]), # (height, width)mode="bilinear",align_corners=True).squeeze().cpu().numpy()print(f"Depth shape: {depth.shape}")print(f"Depth range: [{depth.min():.2f}, {depth.max():.2f}] meters")```### Method 3: Local Model PathIf you have the model saved locally:```pythonfrom transformers import AutoImageProcessor, DepthAnythingForDepthEstimation# Load from local pathmodel_path = "./depth_chm_trained"processor = AutoImageProcessor.from_pretrained(model_path, local_files_only=True)model = DepthAnythingForDepthEstimation.from_pretrained(model_path, local_files_only=True)```## Output Format- **Pipeline output**: Returns a PIL Image with normalized depth values (0-255). Multiply by `max_depth / 255.0` to get actual depth in meters.- **Model output**: Returns `predicted_depth` tensor with values in range [0, 1]. Multiply by `max_depth` (40.0) to get actual depth in meters.## Depth vs Height ConversionThe model outputs **depth** (distance from camera). To convert to **height** (like CHM - Canopy Height Model):```pythonheight = max_depth - depth```## Model Files- `model.safetensors` - Model weights- `config.json` - Model configuration- `preprocessor_config.json` - Image processor configuration- `training_info.json` - Training hyperparameters## CitationIf you use this model, please cite:```bibtex@misc{depth_chm_2024,title={Depth-CHM: Fine-tuned Depth Anything V2 for Canopy Height Estimation},author={Boxiang},year={2024},url={https://huggingface.co/Boxiang/depth_chm}}```## LicenseThis model inherits the license from the base Depth Anything V2 model.
README.md+151-9