Training Script for ViT-S/Tiny/TinyPlus Depth Estimation Distillation from ViT-L#885
Draft
mrpositron wants to merge 3 commits into
Draft
Training Script for ViT-S/Tiny/TinyPlus Depth Estimation Distillation from ViT-L#885mrpositron wants to merge 3 commits into
mrpositron wants to merge 3 commits into
Conversation
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
mrpositron
force-pushed
the
nauryzbay-depth-distillation-relative-and-metric
branch
from
July 20, 2026 12:36
017300c to
0eb04f6
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What has changed and why?
This PR adds a depth estimation training path to LightlyTrain that fine-tunes Depth Anything V3 student models by distilling depth and sky pseudo-labels from a larger V3 ViT-L teacher into smaller, faster backbones. It exposes a new public entrypoint
lightly_train.train_depth_estimation(...)and supports both relative-depth and metric-depth models:dinov3/dav3-relative-tiny,dinov3/dav3-relative-tiny-plus,dinov2/dav3-relative-small.dinov3/dav3-metric-tiny,dinov3/dav3-metric-tiny-plus,dinov2/dav3-metric-small. A metric model is typically fine-tuned from a trained relative checkpoint (matching architectures, so weights transfer cleanly), with the pseudo-labels stored in the canonical-camera depth space.What's included:
train_depth_estimationadded tolightly_train.__init__and wired throughtrain_task.py/train_task_helpers.py.criterion.py):SILogLoss— scale-invariant log depth loss (the depth term).GradientMatchingLoss— multi-scale gradient matching (L_grad).SkyDistillLoss— BCE on the sigmoid sky head against the teacher's soft sky map (L_sky).RelativeL1Loss— scale-aware AbsRel term used only for metric depth to pin the absolute scale to the teacher (it does not vanish under global-scale error, unlike the scale-invariant term).FeatureAlignmentLoss— feature-space distillation of the teacher's DPT-input patch tokens via per-stage learnable projections + mean cosine distance (training-only, discarded at export).DepthEstimationDataArgs/ dataset (depth_estimation_dataset.py) reading RGB images plus.npydepth and sky pseudo-labels matched by filename stem (depth <= 0treated as invalid), and depth-specific transforms.task_metric.py) — AbsRel, RMSE, and delta1 over valid pixels, computed after per-image least-squares scale-and-shift alignment (the standard MiDaS/DAv3 relative-depth protocol). Defaultwatch_metricisval_metric/abs_rel.depth_estimation.py) — logs predicted depth and sky-mask overlays to TensorBoard.train_model.py) — orchestrates the online teacher, loss weighting, and student updates.How has it been tested?
test_criterion.pytest_train_model.py,test_task_model.pytest_depth_estimation_dataset.py,test_depth_estimation_transform.pytest_task_metric.pytest_depth_estimation.pytest_train_task.pyDid you update CHANGELOG.md?
Did you update the documentation?