shriarul5273 commited on
Commit
a7087a4
Β·
1 Parent(s): 1b68546

add GitHub Actions workflow for syncing to Hugging Face space

Browse files
Files changed (2) hide show
  1. .github/workflows/huggingface.yml +25 -0
  2. README.md +182 -1
.github/workflows/huggingface.yml ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ name: Sync to Hugging Face hub
2
+ on:
3
+ push:
4
+ branches: [main]
5
+
6
+ # to run this workflow manually from the Actions tab
7
+ workflow_dispatch:
8
+
9
+ jobs:
10
+ sync-to-hub:
11
+ runs-on: ubuntu-latest
12
+ steps:
13
+ - uses: actions/checkout@v5
14
+ with:
15
+ fetch-depth: 0
16
+ - name: Add remote
17
+ env:
18
+ HF: ${{secrets.HF_TOKEN }}
19
+ HFUSER: ${{secrets.HFUSER }}
20
+ run: git remote add space https://$HFUSER:$HF@huggingface.co/spaces/$HFUSER/Depth-Anything-Compare-demo
21
+ - name: Push to hub
22
+ env:
23
+ HF: ${{ secrets.HF_TOKEN}}
24
+ HFUSER: ${{secrets.HFUSER }}
25
+ run: git push --force https://$HFUSER:$HF@huggingface.co/spaces/$HFUSER/Depth-Anything-Compare-demo main
README.md CHANGED
@@ -9,4 +9,185 @@ app_file: app.py
9
  pinned: false
10
  ---
11
 
12
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9
  pinned: false
10
  ---
11
 
12
+ # Depth Anything v1 vs v2 Comparison Demo
13
+
14
+ A comprehensive comparison tool for **Depth Anything v1** and **Depth Anything v2** models, built with Gradio and optimized for HuggingFace Spaces with ZeroGPU support.
15
+
16
+ ## πŸš€ Features
17
+
18
+ ### Three Comparison Modes
19
+
20
+ 1. **🎚️ Slider Comparison**: Interactive side-by-side comparison with a draggable slider
21
+ 2. **πŸ” Method Comparison**: Traditional side-by-side view with model labels
22
+ 3. **πŸ”¬ Single Model**: Run individual models for detailed analysis
23
+
24
+ ### Supported Models
25
+
26
+ #### Depth Anything v1
27
+ - **ViT-S (Small)**: Fastest inference, good quality
28
+ - **ViT-B (Base)**: Balanced speed and quality
29
+ - **ViT-L (Large)**: Best quality, slower inference
30
+
31
+ #### Depth Anything v2
32
+ - **ViT-Small**: Enhanced small model with improved accuracy
33
+ - **ViT-Base**: Balanced performance with v2 improvements
34
+ - **ViT-Large**: State-of-the-art depth estimation quality
35
+
36
+ ## πŸ–ΌοΈ Example Images
37
+
38
+ The demo includes 20+ carefully selected example images showcasing various scenarios:
39
+ - Indoor and outdoor scenes
40
+ - Different lighting conditions
41
+ - Various object types and compositions
42
+ - Challenging depth estimation scenarios
43
+
44
+ ## πŸ› οΈ Technical Details
45
+
46
+ ### Architecture
47
+ - **Framework**: Gradio 4.0+ with modern UI components
48
+ - **Backend**: PyTorch with CUDA acceleration
49
+ - **Deployment**: ZeroGPU-optimized for HuggingFace Spaces
50
+ - **Memory Management**: Automatic model loading/unloading for efficient GPU usage
51
+
52
+ ### ZeroGPU Optimizations
53
+ - `@spaces.GPU` decorators for GPU-intensive functions
54
+ - Automatic memory cleanup between inferences
55
+ - On-demand model loading to prevent OOM errors
56
+ - Efficient resource allocation and deallocation
57
+
58
+ ### Depth Visualization
59
+ - **Colormap**: Spectral_r colormap for intuitive depth representation
60
+ - **Normalization**: Min-max scaling for consistent visualization
61
+ - **Resolution**: Maintains original image aspect ratios
62
+
63
+ ## πŸ“¦ Installation & Setup
64
+
65
+ ### Local Development
66
+
67
+ 1. **Clone the repository**:
68
+ ```bash
69
+ git clone <repository-url>
70
+ cd Depth-Anything-Compare-demo
71
+ ```
72
+
73
+ 2. **Install dependencies**:
74
+ ```bash
75
+ pip install -r requirements.txt
76
+ ```
77
+
78
+ 3. **Download model checkpoints** (for local usage):
79
+ ```bash
80
+ # Depth Anything v1 models are downloaded automatically from HuggingFace Hub
81
+ # For v2 models, download checkpoints to Depth-Anything-V2/checkpoints/
82
+ ```
83
+
84
+ 4. **Run locally**:
85
+ ```bash
86
+ python app_local.py # For local development
87
+ python app.py # For ZeroGPU deployment
88
+ ```
89
+
90
+ ### HuggingFace Spaces Deployment
91
+
92
+ This app is optimized for HuggingFace Spaces with ZeroGPU. Simply:
93
+
94
+ 1. Upload the repository to your HuggingFace Space
95
+ 2. Set hardware to "ZeroGPU"
96
+ 3. The app will automatically handle GPU allocation and model loading
97
+
98
+ ## πŸ“ Project Structure
99
+
100
+ ```
101
+ Depth-Anything-Compare-demo/
102
+ β”œβ”€β”€ app.py # ZeroGPU-optimized main application
103
+ β”œβ”€β”€ app_local.py # Local development version
104
+ β”œβ”€β”€ requirements.txt # Python dependencies
105
+ β”œβ”€β”€ README.md # This file
106
+ β”œβ”€β”€ assets/
107
+ β”‚ └── examples/ # Example images for testing
108
+ β”œβ”€β”€ Depth-Anything/ # Depth Anything v1 implementation
109
+ β”‚ β”œβ”€β”€ depth_anything/
110
+ β”‚ β”‚ β”œβ”€β”€ dpt.py # v1 model architecture
111
+ β”‚ β”‚ └── util/ # v1 utilities and transforms
112
+ β”‚ └── torchhub/ # Required dependencies
113
+ └── Depth-Anything-V2/ # Depth Anything v2 implementation
114
+ β”œβ”€β”€ depth_anything_v2/
115
+ β”‚ β”œβ”€β”€ dpt.py # v2 model architecture
116
+ β”‚ └── dinov2_layers/ # DINOv2 components
117
+ └── assets/
118
+ └── examples/ # v2-specific examples
119
+ ```
120
+
121
+ ## πŸ”§ Configuration
122
+
123
+ ### Model Configuration
124
+ Models are configured in the respective config dictionaries:
125
+ - `V1_MODEL_CONFIGS`: HuggingFace Hub model identifiers
126
+ - `V2_MODEL_CONFIGS`: Local checkpoint paths and architecture parameters
127
+
128
+ ### Environment Variables
129
+ - `DEVICE`: Automatically detects CUDA availability
130
+ - GPU memory is managed automatically by ZeroGPU
131
+
132
+ ## πŸ“Š Performance
133
+
134
+ ### Inference Times (Approximate)
135
+ - **ViT-S models**: ~1-2 seconds
136
+ - **ViT-B models**: ~2-4 seconds
137
+ - **ViT-L models**: ~4-8 seconds
138
+
139
+ *Times vary based on image resolution and GPU availability*
140
+
141
+ ### Memory Usage
142
+ - Optimized for ZeroGPU's memory constraints
143
+ - Automatic model unloading prevents OOM errors
144
+ - Efficient batch processing for multiple comparisons
145
+
146
+ ## 🎯 Usage Examples
147
+
148
+ ### Compare v1 vs v2 Models
149
+ 1. Upload an image or select from examples
150
+ 2. Choose models from both v1 and v2 families
151
+ 3. Click "Compare" or "Slider Compare"
152
+ 4. Analyze the depth estimation differences
153
+
154
+ ### Analyze Single Model Performance
155
+ 1. Select "Single Model" tab
156
+ 2. Choose any available model
157
+ 3. Upload image and click "Run"
158
+ 4. Examine detailed depth map output
159
+
160
+ ## 🀝 Contributing
161
+
162
+ Contributions are welcome! Areas for improvement:
163
+ - Additional model variants
164
+ - New visualization options
165
+ - Performance optimizations
166
+ - UI/UX enhancements
167
+
168
+ ## πŸ“š References
169
+
170
+ - **Depth Anything v1**: [LiheYoung/Depth-Anything](https://github.com/LiheYoung/Depth-Anything)
171
+ - **Depth Anything v2**: [DepthAnything/Depth-Anything-V2](https://github.com/DepthAnything/Depth-Anything-V2)
172
+ - **Original Papers**:
173
+ - [Depth Anything: Unleashing the Power of Large-Scale Unlabeled Data](https://arxiv.org/abs/2401.10891)
174
+ - [Depth Anything V2: More Efficient, Better Supervised](https://arxiv.org/abs/2406.09414)
175
+
176
+ ## πŸ“„ License
177
+
178
+ This project combines implementations from:
179
+ - Depth Anything v1: MIT License
180
+ - Depth Anything v2: Apache 2.0 License
181
+ - Demo code: MIT License
182
+
183
+ Please check individual component licenses for specific terms.
184
+
185
+ ## πŸ™ Acknowledgments
186
+
187
+ - Original Depth Anything authors and contributors
188
+ - HuggingFace team for Spaces and ZeroGPU infrastructure
189
+ - Gradio team for the excellent UI framework
190
+
191
+ ---
192
+
193
+ **Note**: This is a demonstration/comparison tool. For production use of the Depth Anything models, please refer to the original repositories and follow their recommended practices.