Prasuna Chatla
Robotics Institute, Carnegie Mellon University
A PyTorch implementation of self-supervised monocular depth estimation using a Vision Transformer (ViT) encoder, a multi-scale CNN decoder, relative-pose estimation, differentiable view reconstruction, SSIM/L1 photometric loss, and edge-aware disparity smoothness.
The trained depth network predicts a dense depth map from a single RGB image. During training, adjacent video frames and camera intrinsics provide the geometric signal, so ground-truth depth is not required.
- Vision Transformer encoder for global scene context
- Multi-scale CNN decoder for dense depth prediction
- Pose network for target-to-source camera transformation
- Differentiable back-projection, projection, and image warping
- SSIM + L1 photometric reconstruction objective
- Edge-aware disparity smoothness
- CNN baseline and standard depth-evaluation metrics
- Training-loss, qualitative-depth, resolution, initialization, and post-processing experiments
The upper path shows self-supervised training from target and source frames. The lower path shows monocular inference from one RGB image.
For target image
The training objective is:
$$ L_{\mathrm{photo}} = \alpha\frac{1-\operatorname{SSIM}(I_t,\hat{I}_t)}{2}
- (1-\alpha)\left|I_t-\hat{I}_t\right|_1, $$
$$ L_{\mathrm{smooth}} = |\partial_x d|e^{-|\partial_x I|}
- |\partial_y d|e^{-|\partial_y I|}, $$
$$ L_{\mathrm{total}} = \sum_s w_s\left(L_{\mathrm{photo}}^{(s)}
- \lambda_sL_{\mathrm{smooth}}^{(s)}\right). $$
The input image is divided into non-overlapping
| Parameter | Value |
|---|---|
| Patch size | 16 x 16 |
| Embedding dimension | 768 |
| Attention heads | 8 |
| Transformer blocks | 6 |
| MLP hidden dimension | 3072 |
The decoder progressively restores spatial resolution and predicts depth at full, half, and quarter scales. A representative channel progression is:
768 -> 256 -> 128 -> 64 -> 32 -> 1
The experimental scale weights are:
[1.0, 0.5, 0.25]
models/
vit_encoder.py # patch embedding and transformer blocks
depth_decoder.py # multi-scale convolutional decoder
depth_model.py # end-to-end depth model
pose_net.py # relative camera pose network
cnn_baseline.py # convolutional baseline
losses/
ssim.py
photometric.py
smoothness.py
self_supervised.py
geometry/
projection.py # depth conversion, SE(3), projection, and warping
datasets/
triplet_dataset.py # target/source frame manifest loader
utils/
metrics.py # AbsRel, SqRel, RMSE, RMSE-log, delta metrics
scripts/
train.py
evaluate.py
predict.py
configs/
kitti.yaml
docs/
PROJECT_REPORT.md
Self-Supervised-Monocular-Depth-Estimation-Using-Vision-Transformers.pdf
python -m venv .venv
source .venv/bin/activate # Linux/macOS
# .venv\Scripts\activate # Windows
pip install -r requirements.txtSelf-supervised training requires temporally adjacent frames from the same calibrated camera sequence.
prev,target,next,fx,fy,cx,cy
sequence/000000.png,sequence/000001.png,sequence/000002.png,721.5,721.5,609.6,172.9Camera intrinsics must correspond to the resized images.
python scripts/train.py \
--manifest data/train_triplets.csv \
--root /path/to/dataset \
--epochs 20 \
--batch-size 4 \
--height 192 \
--width 640Checkpoints are written to checkpoints/last.pt by default.
python scripts/predict.py \
--image example.jpg \
--checkpoint checkpoints/last.pt \
--output depth.pngOnly one RGB image is required at inference time.
The evaluator expects a CSV containing image,depth columns. Ground-truth depth is used only for evaluation.
python scripts/evaluate.py \
--manifest data/eval.csv \
--checkpoint checkpoints/last.ptReported metrics:
- Absolute Relative Error (
AbsRel) - Squared Relative Error (
SqRel) - RMSE
- RMSE-log
$\delta < 1.25$ $\delta < 1.25^2$ $\delta < 1.25^3$
Median scaling is supported because monocular self-supervised depth has global-scale ambiguity.
The recorded experiments used a custom ViT/CNN depth estimator, multi-scale predictions, Adam-based optimization, and training runs extending to 500 epochs. Input sizes between 224 x 224 and 256 x 256 were explored for the image-level experiments; the temporal training script defaults to 192 x 640 for driving sequences. The experiments were conducted in Google Colab Pro with an NVIDIA CUDA-capable GPU, with approximately 16 GB of memory required for larger configurations.
| Experiment | Main observation |
|---|---|
| Training convergence | Several runs showed a rapid early loss decrease followed by a low plateau; convergence speed and late-stage noise varied |
| Input resolution | Higher-resolution images retained more spatial detail; lower-resolution runs were less stable and sometimes required longer training |
| Transformer initialization | Pretrained ViT initialization converged faster and produced stronger qualitative outputs than random initialization |
| Composite loss | Photometric reconstruction, SSIM, and edge-aware smoothness together produced the most stable behavior |
| Smoothness weight | Excessive weighting introduced artifacts or softened fine boundaries |
| Multi-scale prediction | Coarse outputs preserved global layout while fine outputs retained more local structure |
| Bilateral filtering | Filtering reduced local variation and produced smoother maps, with a trade-off in fine boundary detail |
| Scene diversity | Depth maps retained broad foreground/background organization across animal, landscape, urban, crowd, indoor, repetitive-pattern, and underwater scenes |
Four runs show a strong initial decrease in loss. Three approach a low plateau, while one remains more variable.
The 500-epoch run also converges sharply during the early phase and shows intermittent late-stage spikes.
The examples preserve broad scene organization, including foreground/background separation, sky/ground structure, and dominant object boundaries. Fine details remain challenging in crowded scenes, repetitive textures, thin structures, and low-texture regions.
Bilateral filtering generates smoother visual output. Raw and filtered predictions are kept separate because post-processing can soften fine depth discontinuities.
The recorded multi-view experiment preserves the dominant animal and branch structure; bilateral filtering produces a smoother version of the prediction.
This release reports training-loss behavior and qualitative depth maps. A fixed benchmark split, complete per-run metadata, and standard metric values were not captured for these experiment runs, so the repository does not claim benchmark depth accuracy.
The complete experiment discussion and extended result galleries are available in the project report.
pytest -qThe tests cover model output shapes and the differentiable geometry path.
- Monocular depth has inherent global-scale ambiguity.
- Dynamic objects, occlusions, reflections, and low-texture regions can violate photometric assumptions.
- Larger transformer configurations require substantial GPU memory.
- Dataset-specific cropping, intrinsic rescaling, dynamic-object handling, and reproducible splits are required for benchmark evaluation.
- Evaluate on a fixed KITTI split with standard metrics
- Add minimum reprojection, auto-masking, occlusion handling, and dynamic-object masking
- Compare CNN, ViT, and Swin Transformer encoders
- Add matched pretrained-versus-random initialization experiments
- Measure peak memory, latency, and throughput at multiple resolutions
- Explore pruning, quantization, knowledge distillation, and lightweight transformer variants







