stpete2 commited on
Commit
3e31272
·
verified ·
1 Parent(s): 9f43576

Upload biplet_colmap_2dgs_colab_02.ipynb

Browse files
Files changed (1) hide show
  1. biplet_colmap_2dgs_colab_02.ipynb +1431 -0
biplet_colmap_2dgs_colab_02.ipynb ADDED
@@ -0,0 +1,1431 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "markdown",
5
+ "id": "fb1f1fdc",
6
+ "metadata": {
7
+ "papermill": {
8
+ "duration": 0.002985,
9
+ "end_time": "2026-01-10T18:17:32.170524",
10
+ "exception": false,
11
+ "start_time": "2026-01-10T18:17:32.167539",
12
+ "status": "completed"
13
+ },
14
+ "tags": [],
15
+ "id": "fb1f1fdc"
16
+ },
17
+ "source": [
18
+ "# **biplet-dino-colmap-2dgs**"
19
+ ]
20
+ },
21
+ {
22
+ "cell_type": "code",
23
+ "source": [
24
+ "#サイズの異なる画像を扱う\n",
25
+ "from google.colab import drive\n",
26
+ "drive.mount('/content/drive')"
27
+ ],
28
+ "metadata": {
29
+ "colab": {
30
+ "base_uri": "https://localhost:8080/"
31
+ },
32
+ "id": "JON4rYSEOzCg",
33
+ "outputId": "79cbc182-979e-4e50-811f-88a9b8d77160"
34
+ },
35
+ "id": "JON4rYSEOzCg",
36
+ "execution_count": 1,
37
+ "outputs": [
38
+ {
39
+ "output_type": "stream",
40
+ "name": "stdout",
41
+ "text": [
42
+ "Mounted at /content/drive\n"
43
+ ]
44
+ }
45
+ ]
46
+ },
47
+ {
48
+ "cell_type": "code",
49
+ "execution_count": 2,
50
+ "id": "22353010",
51
+ "metadata": {
52
+ "execution": {
53
+ "iopub.execute_input": "2026-01-10T18:17:32.181455Z",
54
+ "iopub.status.busy": "2026-01-10T18:17:32.180969Z",
55
+ "iopub.status.idle": "2026-01-10T18:17:32.355942Z",
56
+ "shell.execute_reply": "2026-01-10T18:17:32.355229Z"
57
+ },
58
+ "papermill": {
59
+ "duration": 0.179454,
60
+ "end_time": "2026-01-10T18:17:32.357275",
61
+ "exception": false,
62
+ "start_time": "2026-01-10T18:17:32.177821",
63
+ "status": "completed"
64
+ },
65
+ "tags": [],
66
+ "id": "22353010"
67
+ },
68
+ "outputs": [],
69
+ "source": [
70
+ "import os\n",
71
+ "import sys\n",
72
+ "import subprocess\n",
73
+ "import shutil\n",
74
+ "from pathlib import Path\n",
75
+ "import cv2\n",
76
+ "from PIL import Image\n",
77
+ "import glob\n",
78
+ "\n",
79
+ "IMAGE_PATH=\"/content/drive/MyDrive/your_folder/fountain100\"\n",
80
+ "\n",
81
+ "#WORK_DIR = '/content/gaussian-splatting'\n",
82
+ "WORK_DIR = \"/content/2d-gaussian-splatting\"\n",
83
+ "\n",
84
+ "OUTPUT_DIR = '/content/output'\n",
85
+ "COLMAP_DIR = '/content/colmap_data'"
86
+ ]
87
+ },
88
+ {
89
+ "cell_type": "code",
90
+ "execution_count": 2,
91
+ "metadata": {
92
+ "execution": {
93
+ "iopub.execute_input": "2026-01-10T18:22:43.807508Z",
94
+ "iopub.status.busy": "2026-01-10T18:22:43.807294Z",
95
+ "iopub.status.idle": "2026-01-11T00:00:17.030890Z",
96
+ "shell.execute_reply": "2026-01-11T00:00:17.029927Z"
97
+ },
98
+ "papermill": {
99
+ "duration": 20253.434865,
100
+ "end_time": "2026-01-11T00:00:17.234174",
101
+ "exception": false,
102
+ "start_time": "2026-01-10T18:22:43.799309",
103
+ "status": "completed"
104
+ },
105
+ "tags": [],
106
+ "id": "QXI_UOXaNbgI"
107
+ },
108
+ "outputs": [],
109
+ "source": [
110
+ "\n"
111
+ ],
112
+ "id": "QXI_UOXaNbgI"
113
+ },
114
+ {
115
+ "cell_type": "code",
116
+ "execution_count": 3,
117
+ "id": "be6df249",
118
+ "metadata": {
119
+ "execution": {
120
+ "iopub.execute_input": "2026-01-10T18:17:32.363444Z",
121
+ "iopub.status.busy": "2026-01-10T18:17:32.363175Z",
122
+ "iopub.status.idle": "2026-01-10T18:22:43.720241Z",
123
+ "shell.execute_reply": "2026-01-10T18:22:43.719380Z"
124
+ },
125
+ "papermill": {
126
+ "duration": 311.361656,
127
+ "end_time": "2026-01-10T18:22:43.721610",
128
+ "exception": false,
129
+ "start_time": "2026-01-10T18:17:32.359954",
130
+ "status": "completed"
131
+ },
132
+ "tags": [],
133
+ "id": "be6df249",
134
+ "outputId": "c6ebe7e1-8e00-46d9-e3c1-09bd1e1f5e60",
135
+ "colab": {
136
+ "base_uri": "https://localhost:8080/"
137
+ }
138
+ },
139
+ "outputs": [
140
+ {
141
+ "output_type": "stream",
142
+ "name": "stdout",
143
+ "text": [
144
+ "🚀 Setting up COLAB environment (v8 - Python 3.12 compatible)\n",
145
+ "\n",
146
+ "======================================================================\n",
147
+ "STEP 0: Fix NumPy (Python 3.12 compatible)\n",
148
+ "======================================================================\n",
149
+ "Found existing installation: torch 2.9.0+cu128\n",
150
+ "Uninstalling torch-2.9.0+cu128:\n",
151
+ " Successfully uninstalled torch-2.9.0+cu128\n",
152
+ "Found existing installation: torchvision 0.24.0+cu128\n",
153
+ "Uninstalling torchvision-0.24.0+cu128:\n",
154
+ " Successfully uninstalled torchvision-0.24.0+cu128\n",
155
+ "Found existing installation: torchaudio 2.9.0+cu128\n",
156
+ "Uninstalling torchaudio-2.9.0+cu128:\n",
157
+ " Successfully uninstalled torchaudio-2.9.0+cu128\n",
158
+ "Looking in indexes: https://download.pytorch.org/whl/cu118\n",
159
+ "\u001b[31mERROR: Could not find a version that satisfies the requirement torch==2.1.2+cu118 (from versions: 2.2.0+cu118, 2.2.1+cu118, 2.2.2+cu118, 2.3.0+cu118, 2.3.1+cu118, 2.4.0+cu118, 2.4.1+cu118, 2.5.0+cu118, 2.5.1+cu118, 2.6.0+cu118, 2.7.0+cu118, 2.7.1+cu118)\u001b[0m\u001b[31m\n",
160
+ "\u001b[0m\u001b[31mERROR: No matching distribution found for torch==2.1.2+cu118\u001b[0m\u001b[31m\n",
161
+ "\u001b[0m\n",
162
+ "======================================================================\n",
163
+ "STEP 1: System packages\n",
164
+ "======================================================================\n",
165
+ "Running: apt-get update -qq\n",
166
+ "Running: apt-get install -y -qq colmap build-essential cmake git libopenblas-dev xvfb\n",
167
+ "\n",
168
+ "======================================================================\n",
169
+ "STEP 2: Clone Gaussian Splatting\n",
170
+ "======================================================================\n",
171
+ "Running: git clone --recursive https://github.com/hbb1/2d-gaussian-splatting.git 2d-gaussian-splatting\n",
172
+ "\n",
173
+ "======================================================================\n",
174
+ "STEP 3: Python packages (VERBOSE MODE)\n",
175
+ "======================================================================\n",
176
+ "\n",
177
+ "📦 Installing PyTorch...\n",
178
+ "Running: /usr/bin/python3 -m pip install torch torchvision torchaudio\n",
179
+ "\n",
180
+ "📦 Installing core utilities...\n",
181
+ "Running: /usr/bin/python3 -m pip install opencv-python pillow imageio imageio-ffmpeg plyfile tqdm tensorboard\n",
182
+ "\n",
183
+ "📦 Installing transformers (NumPy 1.26 compatible)...\n",
184
+ "Running: /usr/bin/python3 -m pip install transformers==4.45.0\n",
185
+ "\n",
186
+ "📦 Installing LightGlue stack...\n",
187
+ "Running: /usr/bin/python3 -m pip install kornia\n",
188
+ "Running: /usr/bin/python3 -m pip install h5py\n",
189
+ "Running: /usr/bin/python3 -m pip install matplotlib\n",
190
+ "Running: /usr/bin/python3 -m pip install pycolmap\n",
191
+ "\n",
192
+ "======================================================================\n",
193
+ "STEP 5: Detailed Verification\n",
194
+ "======================================================================\n",
195
+ "\n",
196
+ "🔍 Testing PyTorch...\n",
197
+ " ✓ PyTorch: 2.10.0+cu128\n",
198
+ " ✓ CUDA available: True\n",
199
+ " ✓ CUDA version: 12.8\n",
200
+ "\n",
201
+ "🔍 Testing transformers...\n",
202
+ " ✓ transformers version: 4.45.0\n",
203
+ " ✓ AutoModel import: OK\n",
204
+ "\n",
205
+ "🔍 Testing pycolmap...\n",
206
+ " ✓ pycolmap: OK\n",
207
+ "\n",
208
+ "🔍 Testing kornia...\n",
209
+ " ✓ kornia: 0.8.2\n",
210
+ "\n",
211
+ "======================================================================\n",
212
+ "✅ SETUP COMPLETE\n",
213
+ "======================================================================\n",
214
+ "Working dir: 2d-gaussian-splatting\n"
215
+ ]
216
+ }
217
+ ],
218
+ "source": [
219
+ "def run_cmd(cmd, check=True, capture=False):\n",
220
+ " \"\"\"Run command with better error handling\"\"\"\n",
221
+ " print(f\"Running: {' '.join(cmd)}\")\n",
222
+ " result = subprocess.run(\n",
223
+ " cmd,\n",
224
+ " capture_output=capture,\n",
225
+ " text=True,\n",
226
+ " check=False\n",
227
+ " )\n",
228
+ " if check and result.returncode != 0:\n",
229
+ " print(f\"❌ Command failed with code {result.returncode}\")\n",
230
+ " if capture:\n",
231
+ " print(f\"STDOUT: {result.stdout}\")\n",
232
+ " print(f\"STDERR: {result.stderr}\")\n",
233
+ " return result\n",
234
+ "\n",
235
+ "\n",
236
+ "def setup_environment():\n",
237
+ " \"\"\"\n",
238
+ " Colab environment setup for Gaussian Splatting + LightGlue + pycolmap\n",
239
+ " Python 3.12 compatible version (v8)\n",
240
+ " \"\"\"\n",
241
+ "\n",
242
+ " print(\"🚀 Setting up COLAB environment (v8 - Python 3.12 compatible)\")\n",
243
+ "\n",
244
+ " WORK_DIR = \"gaussian-splatting\"\n",
245
+ "\n",
246
+ " # =====================================================================\n",
247
+ " # STEP 0: NumPy FIX (Python 3.12 compatible)\n",
248
+ " # =====================================================================\n",
249
+ " print(\"\\n\" + \"=\"*70)\n",
250
+ " print(\"STEP 0: Fix NumPy (Python 3.12 compatible)\")\n",
251
+ " print(\"=\"*70)\n",
252
+ "\n",
253
+ " # Python 3.12 requires numpy >= 1.26\n",
254
+ " run_cmd([sys.executable, \"-m\", \"pip\", \"uninstall\", \"-y\", \"numpy\"])\n",
255
+ " run_cmd([sys.executable, \"-m\", \"pip\", \"install\", \"numpy==1.26.4\"])\n",
256
+ "\n",
257
+ " # sanity check\n",
258
+ " run_cmd([sys.executable, \"-c\", \"import numpy; print('NumPy:', numpy.__version__)\"])\n",
259
+ "\n",
260
+ " # =====================================================================\n",
261
+ " # STEP 1: System packages (Colab)\n",
262
+ " # =====================================================================\n",
263
+ " print(\"\\n\" + \"=\"*70)\n",
264
+ " print(\"STEP 1: System packages\")\n",
265
+ " print(\"=\"*70)\n",
266
+ "\n",
267
+ " run_cmd([\"apt-get\", \"update\", \"-qq\"])\n",
268
+ " run_cmd([\n",
269
+ " \"apt-get\", \"install\", \"-y\", \"-qq\",\n",
270
+ " \"colmap\",\n",
271
+ " \"build-essential\",\n",
272
+ " \"cmake\",\n",
273
+ " \"git\",\n",
274
+ " \"libopenblas-dev\",\n",
275
+ " \"xvfb\"\n",
276
+ " ])\n",
277
+ "\n",
278
+ " # virtual display (COLMAP / OpenCV safety)\n",
279
+ " os.environ[\"QT_QPA_PLATFORM\"] = \"offscreen\"\n",
280
+ " os.environ[\"DISPLAY\"] = \":99\"\n",
281
+ " subprocess.Popen(\n",
282
+ " [\"Xvfb\", \":99\", \"-screen\", \"0\", \"1024x768x24\"],\n",
283
+ " stdout=subprocess.DEVNULL,\n",
284
+ " stderr=subprocess.DEVNULL\n",
285
+ " )\n",
286
+ "\n",
287
+ " # =====================================================================\n",
288
+ " # STEP 2: Clone 2D Gaussian Splatting\n",
289
+ " # =====================================================================\n",
290
+ " print(\"\\n\" + \"=\"*70)\n",
291
+ " print(\"STEP 2: Clone Gaussian Splatting\")\n",
292
+ " print(\"=\"*70)\n",
293
+ "\n",
294
+ " if not os.path.exists(WORK_DIR):\n",
295
+ " run_cmd([\n",
296
+ " \"git\", \"clone\", \"--recursive\",\n",
297
+ " \"https://github.com/hbb1/2d-gaussian-splatting.git\",\n",
298
+ " WORK_DIR\n",
299
+ " ])\n",
300
+ " else:\n",
301
+ " print(\"✓ Repository already exists\")\n",
302
+ "\n",
303
+ " # =====================================================================\n",
304
+ " # STEP 3: Python packages (FIXED ORDER & VERSIONS)\n",
305
+ " # =====================================================================\n",
306
+ " print(\"\\n\" + \"=\"*70)\n",
307
+ " print(\"STEP 3: Python packages (VERBOSE MODE)\")\n",
308
+ " print(\"=\"*70)\n",
309
+ "\n",
310
+ " # ---- PyTorch (Colab CUDA対応) ----\n",
311
+ " print(\"\\n📦 Installing PyTorch...\")\n",
312
+ " run_cmd([\n",
313
+ " sys.executable, \"-m\", \"pip\", \"install\",\n",
314
+ " \"torch\", \"torchvision\", \"torchaudio\"\n",
315
+ " ])\n",
316
+ "\n",
317
+ " # ---- Core utils ----\n",
318
+ " print(\"\\n📦 Installing core utilities...\")\n",
319
+ " run_cmd([\n",
320
+ " sys.executable, \"-m\", \"pip\", \"install\",\n",
321
+ " \"opencv-python\",\n",
322
+ " \"pillow\",\n",
323
+ " \"imageio\",\n",
324
+ " \"imageio-ffmpeg\",\n",
325
+ " \"plyfile\",\n",
326
+ " \"tqdm\",\n",
327
+ " \"tensorboard\"\n",
328
+ " ])\n",
329
+ "\n",
330
+ " # ---- transformers (NumPy 1.26 compatible) ----\n",
331
+ " print(\"\\n📦 Installing transformers (NumPy 1.26 compatible)...\")\n",
332
+ " # Install transformers with proper dependencies\n",
333
+ " run_cmd([\n",
334
+ " sys.executable, \"-m\", \"pip\", \"install\",\n",
335
+ " \"transformers==4.40.0\"\n",
336
+ " ])\n",
337
+ "\n",
338
+ " # ---- LightGlue stack (GITHUB INSTALL) ----\n",
339
+ " print(\"\\n📦 Installing LightGlue stack...\")\n",
340
+ "\n",
341
+ " # Install kornia first\n",
342
+ " run_cmd([sys.executable, \"-m\", \"pip\", \"install\", \"kornia\"])\n",
343
+ "\n",
344
+ " # Install h5py (sometimes needed)\n",
345
+ " run_cmd([sys.executable, \"-m\", \"pip\", \"install\", \"h5py\"])\n",
346
+ "\n",
347
+ " # Install matplotlib (LightGlue dependency)\n",
348
+ " run_cmd([sys.executable, \"-m\", \"pip\", \"install\", \"matplotlib\"])\n",
349
+ "\n",
350
+ " # Install pycolmap\n",
351
+ " run_cmd([sys.executable, \"-m\", \"pip\", \"install\", \"pycolmap\"])\n",
352
+ "\n",
353
+ " # =====================================================================\n",
354
+ " # STEP 4: Build 2D GS submodules\n",
355
+ " # =====================================================================\n",
356
+ " print(\"\\n\" + \"=\"*70)\n",
357
+ " print(\"STEP 4: Build Gaussian Splatting submodules\")\n",
358
+ " print(\"=\"*70)\n",
359
+ "\n",
360
+ " submodules = {\n",
361
+ " \"diff-surfel-rasterization\":\n",
362
+ " \"https://github.com/hbb1/diff-surfel-rasterization.git\",\n",
363
+ " \"simple-knn\":\n",
364
+ " \"https://github.com/camenduru/simple-knn.git\"\n",
365
+ " }\n",
366
+ "\n",
367
+ " for name, repo in submodules.items():\n",
368
+ " print(f\"\\n📦 Installing {name}...\")\n",
369
+ " path = os.path.join(WORK_DIR, \"submodules\", name)\n",
370
+ " if not os.path.exists(path):\n",
371
+ " run_cmd([\"git\", \"clone\", repo, path])\n",
372
+ " run_cmd([sys.executable, \"-m\", \"pip\", \"install\", path])\n",
373
+ "\n",
374
+ " # =====================================================================\n",
375
+ " # STEP 5: Detailed Verification\n",
376
+ " # =====================================================================\n",
377
+ " print(\"\\n\" + \"=\"*70)\n",
378
+ " print(\"STEP 5: Detailed Verification\")\n",
379
+ " print(\"=\"*70)\n",
380
+ "\n",
381
+ " # NumPy (verify version first)\n",
382
+ " print(\"\\n🔍 Testing NumPy...\")\n",
383
+ " try:\n",
384
+ " import numpy as np\n",
385
+ " print(f\" ✓ NumPy: {np.__version__}\")\n",
386
+ " except Exception as e:\n",
387
+ " print(f\" ❌ NumPy failed: {e}\")\n",
388
+ "\n",
389
+ " # PyTorch\n",
390
+ " print(\"\\n🔍 Testing PyTorch...\")\n",
391
+ " try:\n",
392
+ " import torch\n",
393
+ " print(f\" ✓ PyTorch: {torch.__version__}\")\n",
394
+ " print(f\" ✓ CUDA available: {torch.cuda.is_available()}\")\n",
395
+ " if torch.cuda.is_available():\n",
396
+ " print(f\" ✓ CUDA version: {torch.version.cuda}\")\n",
397
+ " except Exception as e:\n",
398
+ " print(f\" ❌ PyTorch failed: {e}\")\n",
399
+ "\n",
400
+ " # transformers\n",
401
+ " print(\"\\n🔍 Testing transformers...\")\n",
402
+ " try:\n",
403
+ " import transformers\n",
404
+ " print(f\" ✓ transformers version: {transformers.__version__}\")\n",
405
+ " from transformers import AutoModel\n",
406
+ " print(f\" ✓ AutoModel import: OK\")\n",
407
+ " except Exception as e:\n",
408
+ " print(f\" ❌ transformers failed: {e}\")\n",
409
+ " print(f\" Attempting detailed diagnosis...\")\n",
410
+ " result = run_cmd([\n",
411
+ " sys.executable, \"-c\",\n",
412
+ " \"import transformers; print(transformers.__version__)\"\n",
413
+ " ], capture=True)\n",
414
+ " print(f\" Output: {result.stdout}\")\n",
415
+ " print(f\" Error: {result.stderr}\")\n",
416
+ "\n",
417
+ " '''\n",
418
+ " # LightGlue\n",
419
+ " print(\"\\n🔍 Testing LightGlue...\")\n",
420
+ " try:\n",
421
+ " from lightglue import LightGlue, ALIKED\n",
422
+ " print(f\" ✓ LightGlue: OK\")\n",
423
+ " print(f\" ✓ ALIKED: OK\")\n",
424
+ " except Exception as e:\n",
425
+ " print(f\" ❌ LightGlue failed: {e}\")\n",
426
+ " print(f\" Attempting detailed diagnosis...\")\n",
427
+ " result = run_cmd([\n",
428
+ " sys.executable, \"-c\",\n",
429
+ " \"from lightglue import LightGlue\"\n",
430
+ " ], capture=True)\n",
431
+ " print(f\" Output: {result.stdout}\")\n",
432
+ " print(f\" Error: {result.stderr}\")\n",
433
+ " '''\n",
434
+ "\n",
435
+ " # pycolmap\n",
436
+ " print(\"\\n🔍 Testing pycolmap...\")\n",
437
+ " try:\n",
438
+ " import pycolmap\n",
439
+ " print(f\" ✓ pycolmap: OK\")\n",
440
+ " except Exception as e:\n",
441
+ " print(f\" ❌ pycolmap failed: {e}\")\n",
442
+ "\n",
443
+ " # kornia\n",
444
+ " print(\"\\n🔍 Testing kornia...\")\n",
445
+ " try:\n",
446
+ " import kornia\n",
447
+ " print(f\" ✓ kornia: {kornia.__version__}\")\n",
448
+ " except Exception as e:\n",
449
+ " print(f\" ❌ kornia failed: {e}\")\n",
450
+ "\n",
451
+ " print(\"\\n\" + \"=\"*70)\n",
452
+ " print(\"✅ SETUP COMPLETE\")\n",
453
+ " print(\"=\"*70)\n",
454
+ " print(f\"Working dir: {WORK_DIR}\")\n",
455
+ "\n",
456
+ " return WORK_DIR\n",
457
+ "\n",
458
+ "\n",
459
+ "if __name__ == \"__main__\":\n",
460
+ " setup_environment()"
461
+ ]
462
+ },
463
+ {
464
+ "cell_type": "code",
465
+ "source": [],
466
+ "metadata": {
467
+ "colab": {
468
+ "base_uri": "https://localhost:8080/"
469
+ },
470
+ "id": "cgpyET_KmGhe",
471
+ "outputId": "eaef7613-1658-4621-f9af-c51d5aaa8f5f"
472
+ },
473
+ "id": "cgpyET_KmGhe",
474
+ "execution_count": 9,
475
+ "outputs": [
476
+ {
477
+ "output_type": "stream",
478
+ "name": "stdout",
479
+ "text": [
480
+ "🚀 Setting up COLAB environment (v8 - Python 3.12 compatible)\n",
481
+ "\n",
482
+ "======================================================================\n",
483
+ "STEP 4: Build Gaussian Splatting submodules\n",
484
+ "======================================================================\n",
485
+ "\n",
486
+ "📦 Installing diff-gaussian-rasterization...\n",
487
+ "Running: /usr/bin/python3 -m pip install 2d-gaussian-splatting/submodules/diff-gaussian-rasterization\n",
488
+ "❌ Command failed with code 1\n",
489
+ "\n",
490
+ "📦 Installing simple-knn...\n",
491
+ "Running: /usr/bin/python3 -m pip install 2d-gaussian-splatting/submodules/simple-knn\n",
492
+ "❌ Command failed with code 1\n"
493
+ ]
494
+ }
495
+ ]
496
+ },
497
+ {
498
+ "cell_type": "code",
499
+ "source": [
500
+ "break"
501
+ ],
502
+ "metadata": {
503
+ "id": "9rV1ML69tNnt"
504
+ },
505
+ "id": "9rV1ML69tNnt",
506
+ "execution_count": null,
507
+ "outputs": []
508
+ },
509
+ {
510
+ "cell_type": "code",
511
+ "source": [
512
+ "!nvcc --version\n",
513
+ "import torch\n",
514
+ "print(torch.__version__)\n",
515
+ "print(torch.version.cuda)"
516
+ ],
517
+ "metadata": {
518
+ "colab": {
519
+ "base_uri": "https://localhost:8080/"
520
+ },
521
+ "id": "Ev9PEUdtpEAx",
522
+ "outputId": "5bfecbbb-f9fc-4bad-af15-f9893c4da7dc"
523
+ },
524
+ "id": "Ev9PEUdtpEAx",
525
+ "execution_count": 5,
526
+ "outputs": [
527
+ {
528
+ "output_type": "stream",
529
+ "name": "stdout",
530
+ "text": [
531
+ "nvcc: NVIDIA (R) Cuda compiler driver\n",
532
+ "Copyright (c) 2005-2025 NVIDIA Corporation\n",
533
+ "Built on Fri_Feb_21_20:23:50_PST_2025\n",
534
+ "Cuda compilation tools, release 12.8, V12.8.93\n",
535
+ "Build cuda_12.8.r12.8/compiler.35583870_0\n",
536
+ "2.10.0+cu128\n",
537
+ "12.8\n"
538
+ ]
539
+ }
540
+ ]
541
+ },
542
+ {
543
+ "cell_type": "code",
544
+ "execution_count": 6,
545
+ "id": "b8690389",
546
+ "metadata": {
547
+ "execution": {
548
+ "iopub.execute_input": "2026-01-10T18:22:43.739411Z",
549
+ "iopub.status.busy": "2026-01-10T18:22:43.738855Z",
550
+ "iopub.status.idle": "2026-01-10T18:22:43.755664Z",
551
+ "shell.execute_reply": "2026-01-10T18:22:43.754865Z"
552
+ },
553
+ "papermill": {
554
+ "duration": 0.027297,
555
+ "end_time": "2026-01-10T18:22:43.756758",
556
+ "exception": false,
557
+ "start_time": "2026-01-10T18:22:43.729461",
558
+ "status": "completed"
559
+ },
560
+ "tags": [],
561
+ "id": "b8690389"
562
+ },
563
+ "outputs": [],
564
+ "source": [
565
+ "import os\n",
566
+ "import glob\n",
567
+ "import cv2\n",
568
+ "import numpy as np\n",
569
+ "from PIL import Image\n",
570
+ "\n",
571
+ "# =========================================================\n",
572
+ "# Utility: aspect ratio preserved + black padding\n",
573
+ "# =========================================================\n",
574
+ "\n",
575
+ "def normalize_image_sizes_biplet(input_dir, output_dir=None, size=1024, max_images=None):\n",
576
+ " \"\"\"\n",
577
+ " Generates two square crops (Left & Right or Top & Bottom)\n",
578
+ " from each image in a directory and returns the output directory\n",
579
+ " and the list of generated file paths.\n",
580
+ "\n",
581
+ " Args:\n",
582
+ " input_dir: Input directory containing source images\n",
583
+ " output_dir: Output directory for processed images\n",
584
+ " size: Target square size (default: 1024)\n",
585
+ " max_images: Maximum number of SOURCE images to process (default: None = all images)\n",
586
+ " \"\"\"\n",
587
+ " if output_dir is None:\n",
588
+ " output_dir = 'output/images_biplet'\n",
589
+ " os.makedirs(output_dir, exist_ok=True)\n",
590
+ "\n",
591
+ " print(f\"--- Step 1: Biplet-Square Normalization ---\")\n",
592
+ " print(f\"Generating 2 cropped squares (Left/Right or Top/Bottom) for each image...\")\n",
593
+ " print()\n",
594
+ "\n",
595
+ " generated_paths = []\n",
596
+ " converted_count = 0\n",
597
+ " size_stats = {}\n",
598
+ "\n",
599
+ " # Sort for consistent processing order\n",
600
+ " image_files = sorted([f for f in os.listdir(input_dir)\n",
601
+ " if f.lower().endswith(('.jpg', '.jpeg', '.png'))])\n",
602
+ "\n",
603
+ " # ★ max_images で元画像数を制限\n",
604
+ " if max_images is not None:\n",
605
+ " image_files = image_files[:max_images]\n",
606
+ " print(f\"Processing limited to {max_images} source images (will generate {max_images * 2} cropped images)\")\n",
607
+ "\n",
608
+ " for img_file in image_files:\n",
609
+ " input_path = os.path.join(input_dir, img_file)\n",
610
+ " try:\n",
611
+ " img = Image.open(input_path)\n",
612
+ " original_size = img.size\n",
613
+ "\n",
614
+ " # Tracking original aspect ratios\n",
615
+ " size_key = f\"{original_size[0]}x{original_size[1]}\"\n",
616
+ " size_stats[size_key] = size_stats.get(size_key, 0) + 1\n",
617
+ "\n",
618
+ " # Generate 2 crops using the helper function\n",
619
+ " crops = generate_two_crops(img, size)\n",
620
+ " base_name, ext = os.path.splitext(img_file)\n",
621
+ "\n",
622
+ " for mode, cropped_img in crops.items():\n",
623
+ " output_path = os.path.join(output_dir, f\"{base_name}_{mode}{ext}\")\n",
624
+ " cropped_img.save(output_path, quality=95)\n",
625
+ " generated_paths.append(output_path)\n",
626
+ "\n",
627
+ " converted_count += 1\n",
628
+ " print(f\" ✓ {img_file}: {original_size} → 2 square images generated\")\n",
629
+ "\n",
630
+ " except Exception as e:\n",
631
+ " print(f\" ✗ Error processing {img_file}: {e}\")\n",
632
+ "\n",
633
+ " print(f\"\\nProcessing complete: {converted_count} source images processed\")\n",
634
+ " print(f\"Total output images: {len(generated_paths)}\")\n",
635
+ " print(f\"Original size distribution: {size_stats}\")\n",
636
+ "\n",
637
+ " return output_dir, generated_paths\n",
638
+ "\n",
639
+ "\n",
640
+ "def generate_two_crops(img, size):\n",
641
+ " \"\"\"\n",
642
+ " Crops the image into a square and returns 2 variations\n",
643
+ " (Left/Right for landscape, Top/Bottom for portrait).\n",
644
+ " \"\"\"\n",
645
+ " width, height = img.size\n",
646
+ " crop_size = min(width, height)\n",
647
+ " crops = {}\n",
648
+ "\n",
649
+ " if width > height:\n",
650
+ " # Landscape → Left & Right\n",
651
+ " positions = {\n",
652
+ " 'left': 0,\n",
653
+ " 'right': width - crop_size\n",
654
+ " }\n",
655
+ " for mode, x_offset in positions.items():\n",
656
+ " box = (x_offset, 0, x_offset + crop_size, crop_size)\n",
657
+ " crops[mode] = img.crop(box).resize(\n",
658
+ " (size, size),\n",
659
+ " Image.Resampling.LANCZOS\n",
660
+ " )\n",
661
+ "\n",
662
+ " else:\n",
663
+ " # Portrait or Square → Top & Bottom\n",
664
+ " positions = {\n",
665
+ " 'top': 0,\n",
666
+ " 'bottom': height - crop_size\n",
667
+ " }\n",
668
+ " for mode, y_offset in positions.items():\n",
669
+ " box = (0, y_offset, crop_size, y_offset + crop_size)\n",
670
+ " crops[mode] = img.crop(box).resize(\n",
671
+ " (size, size),\n",
672
+ " Image.Resampling.LANCZOS\n",
673
+ " )\n",
674
+ "\n",
675
+ " return crops\n"
676
+ ]
677
+ },
678
+ {
679
+ "cell_type": "code",
680
+ "execution_count": 7,
681
+ "id": "7acc20b6",
682
+ "metadata": {
683
+ "execution": {
684
+ "iopub.execute_input": "2026-01-10T18:22:43.772525Z",
685
+ "iopub.status.busy": "2026-01-10T18:22:43.772303Z",
686
+ "iopub.status.idle": "2026-01-10T18:22:43.790574Z",
687
+ "shell.execute_reply": "2026-01-10T18:22:43.789515Z"
688
+ },
689
+ "papermill": {
690
+ "duration": 0.027612,
691
+ "end_time": "2026-01-10T18:22:43.791681",
692
+ "exception": false,
693
+ "start_time": "2026-01-10T18:22:43.764069",
694
+ "status": "completed"
695
+ },
696
+ "tags": [],
697
+ "id": "7acc20b6"
698
+ },
699
+ "outputs": [],
700
+ "source": [
701
+ "def run_colmap_reconstruction(image_dir, colmap_dir):\n",
702
+ " \"\"\"Estimate camera poses and 3D point cloud with COLMAP\"\"\"\n",
703
+ " print(\"Running SfM reconstruction with COLMAP...\")\n",
704
+ "\n",
705
+ " database_path = os.path.join(colmap_dir, \"database.db\")\n",
706
+ " sparse_dir = os.path.join(colmap_dir, \"sparse\")\n",
707
+ " os.makedirs(sparse_dir, exist_ok=True)\n",
708
+ "\n",
709
+ " # Set environment variable\n",
710
+ " env = os.environ.copy()\n",
711
+ " env['QT_QPA_PLATFORM'] = 'offscreen'\n",
712
+ "\n",
713
+ " # Feature extraction\n",
714
+ " print(\"1/4: Extracting features...\")\n",
715
+ " subprocess.run([\n",
716
+ " 'colmap', 'feature_extractor',\n",
717
+ " '--database_path', database_path,\n",
718
+ " '--image_path', image_dir,\n",
719
+ " '--ImageReader.single_camera', '1',\n",
720
+ " '--ImageReader.camera_model', 'OPENCV',\n",
721
+ " '--SiftExtraction.use_gpu', '0' # Use CPU\n",
722
+ " ], check=True, env=env)\n",
723
+ "\n",
724
+ " # Feature matching\n",
725
+ " print(\"2/4: Matching features...\")\n",
726
+ " subprocess.run([\n",
727
+ " 'colmap', 'exhaustive_matcher', # Use sequential_matcher instead of exhaustive_matcher\n",
728
+ " '--database_path', database_path,\n",
729
+ " '--SiftMatching.use_gpu', '0' # Use CPU\n",
730
+ " ], check=True, env=env)\n",
731
+ "\n",
732
+ " # Sparse reconstruction\n",
733
+ " print(\"3/4: Sparse reconstruction...\")\n",
734
+ " subprocess.run([\n",
735
+ " 'colmap', 'mapper',\n",
736
+ " '--database_path', database_path,\n",
737
+ " '--image_path', image_dir,\n",
738
+ " '--output_path', sparse_dir,\n",
739
+ " '--Mapper.ba_global_max_num_iterations', '20', # Speed up\n",
740
+ " '--Mapper.ba_local_max_num_iterations', '10'\n",
741
+ " ], check=True, env=env)\n",
742
+ "\n",
743
+ " # Export to text format\n",
744
+ " print(\"4/4: Exporting to text format...\")\n",
745
+ " model_dir = os.path.join(sparse_dir, '0')\n",
746
+ " if not os.path.exists(model_dir):\n",
747
+ " # Use the first model found\n",
748
+ " subdirs = [d for d in os.listdir(sparse_dir) if os.path.isdir(os.path.join(sparse_dir, d))]\n",
749
+ " if subdirs:\n",
750
+ " model_dir = os.path.join(sparse_dir, subdirs[0])\n",
751
+ " else:\n",
752
+ " raise FileNotFoundError(\"COLMAP reconstruction failed\")\n",
753
+ "\n",
754
+ " subprocess.run([\n",
755
+ " 'colmap', 'model_converter',\n",
756
+ " '--input_path', model_dir,\n",
757
+ " '--output_path', model_dir,\n",
758
+ " '--output_type', 'TXT'\n",
759
+ " ], check=True, env=env)\n",
760
+ "\n",
761
+ " print(f\"COLMAP reconstruction complete: {model_dir}\")\n",
762
+ " return model_dir\n",
763
+ "\n",
764
+ "\n",
765
+ "def convert_cameras_to_pinhole(input_file, output_file):\n",
766
+ " \"\"\"Convert camera model to PINHOLE format\"\"\"\n",
767
+ " print(f\"Reading camera file: {input_file}\")\n",
768
+ "\n",
769
+ " with open(input_file, 'r') as f:\n",
770
+ " lines = f.readlines()\n",
771
+ "\n",
772
+ " converted_count = 0\n",
773
+ " with open(output_file, 'w') as f:\n",
774
+ " for line in lines:\n",
775
+ " if line.startswith('#') or line.strip() == '':\n",
776
+ " f.write(line)\n",
777
+ " else:\n",
778
+ " parts = line.strip().split()\n",
779
+ " if len(parts) >= 4:\n",
780
+ " cam_id = parts[0]\n",
781
+ " model = parts[1]\n",
782
+ " width = parts[2]\n",
783
+ " height = parts[3]\n",
784
+ " params = parts[4:]\n",
785
+ "\n",
786
+ " # Convert to PINHOLE format\n",
787
+ " if model == \"PINHOLE\":\n",
788
+ " f.write(line)\n",
789
+ " elif model == \"OPENCV\":\n",
790
+ " # OPENCV: fx, fy, cx, cy, k1, k2, p1, p2\n",
791
+ " fx = params[0]\n",
792
+ " fy = params[1]\n",
793
+ " cx = params[2]\n",
794
+ " cy = params[3]\n",
795
+ " f.write(f\"{cam_id} PINHOLE {width} {height} {fx} {fy} {cx} {cy}\\n\")\n",
796
+ " converted_count += 1\n",
797
+ " else:\n",
798
+ " # Convert other models too\n",
799
+ " fx = fy = max(float(width), float(height))\n",
800
+ " cx = float(width) / 2\n",
801
+ " cy = float(height) / 2\n",
802
+ " f.write(f\"{cam_id} PINHOLE {width} {height} {fx} {fy} {cx} {cy}\\n\")\n",
803
+ " converted_count += 1\n",
804
+ " else:\n",
805
+ " f.write(line)\n",
806
+ "\n",
807
+ " print(f\"Converted {converted_count} cameras to PINHOLE format\")\n",
808
+ "\n",
809
+ "\n",
810
+ "def prepare_gaussian_splatting_data(image_dir, colmap_model_dir):\n",
811
+ " \"\"\"Prepare data for Gaussian Splatting\"\"\"\n",
812
+ " print(\"Preparing data for Gaussian Splatting...\")\n",
813
+ "\n",
814
+ " data_dir = f\"{WORK_DIR}/data/video\"\n",
815
+ " os.makedirs(f\"{data_dir}/sparse/0\", exist_ok=True)\n",
816
+ " os.makedirs(f\"{data_dir}/images\", exist_ok=True)\n",
817
+ "\n",
818
+ " # Copy images\n",
819
+ " print(\"Copying images...\")\n",
820
+ " img_count = 0\n",
821
+ " for img_file in os.listdir(image_dir):\n",
822
+ " if img_file.lower().endswith(('.jpg', '.jpeg', '.png')):\n",
823
+ " shutil.copy(\n",
824
+ " os.path.join(image_dir, img_file),\n",
825
+ " f\"{data_dir}/images/{img_file}\"\n",
826
+ " )\n",
827
+ " img_count += 1\n",
828
+ " print(f\"Copied {img_count} images\")\n",
829
+ "\n",
830
+ " # Convert and copy camera file to PINHOLE format\n",
831
+ " print(\"Converting camera model to PINHOLE format...\")\n",
832
+ " convert_cameras_to_pinhole(\n",
833
+ " os.path.join(colmap_model_dir, 'cameras.txt'),\n",
834
+ " f\"{data_dir}/sparse/0/cameras.txt\"\n",
835
+ " )\n",
836
+ "\n",
837
+ " # Copy other files\n",
838
+ " for filename in ['images.txt', 'points3D.txt']:\n",
839
+ " src = os.path.join(colmap_model_dir, filename)\n",
840
+ " dst = f\"{data_dir}/sparse/0/{filename}\"\n",
841
+ " if os.path.exists(src):\n",
842
+ " shutil.copy(src, dst)\n",
843
+ " print(f\"Copied {filename}\")\n",
844
+ " else:\n",
845
+ " print(f\"Warning: {filename} not found\")\n",
846
+ "\n",
847
+ " print(f\"Data preparation complete: {data_dir}\")\n",
848
+ " return data_dir\n",
849
+ "\n",
850
+ "def run_colmap_reconstruction(image_dir, colmap_dir):\n",
851
+ " \"\"\"Estimate camera poses and 3D point cloud with COLMAP\"\"\"\n",
852
+ " print(\"Running SfM reconstruction with COLMAP...\")\n",
853
+ "\n",
854
+ " database_path = os.path.join(colmap_dir, \"database.db\")\n",
855
+ " sparse_dir = os.path.join(colmap_dir, \"sparse\")\n",
856
+ " os.makedirs(sparse_dir, exist_ok=True)\n",
857
+ "\n",
858
+ " # Set environment variable\n",
859
+ " env = os.environ.copy()\n",
860
+ " env['QT_QPA_PLATFORM'] = 'offscreen'\n",
861
+ "\n",
862
+ " # Feature extraction\n",
863
+ " print(\"1/4: Extracting features...\")\n",
864
+ " subprocess.run([\n",
865
+ " 'colmap', 'feature_extractor',\n",
866
+ " '--database_path', database_path,\n",
867
+ " '--image_path', image_dir,\n",
868
+ " '--ImageReader.single_camera', '1',\n",
869
+ " '--ImageReader.camera_model', 'OPENCV',\n",
870
+ " '--SiftExtraction.use_gpu', '0' # Use CPU\n",
871
+ " ], check=True, env=env)\n",
872
+ "\n",
873
+ " # Feature matching\n",
874
+ " print(\"2/4: Matching features...\")\n",
875
+ " subprocess.run([\n",
876
+ " 'colmap', 'exhaustive_matcher', # Use sequential_matcher instead of exhaustive_matcher\n",
877
+ " '--database_path', database_path,\n",
878
+ " '--SiftMatching.use_gpu', '0' # Use CPU\n",
879
+ " ], check=True, env=env)\n",
880
+ "\n",
881
+ " # Sparse reconstruction\n",
882
+ " print(\"3/4: Sparse reconstruction...\")\n",
883
+ " subprocess.run([\n",
884
+ " 'colmap', 'mapper',\n",
885
+ " '--database_path', database_path,\n",
886
+ " '--image_path', image_dir,\n",
887
+ " '--output_path', sparse_dir,\n",
888
+ " '--Mapper.ba_global_max_num_iterations', '20', # Speed up\n",
889
+ " '--Mapper.ba_local_max_num_iterations', '10'\n",
890
+ " ], check=True, env=env)\n",
891
+ "\n",
892
+ " # Export to text format\n",
893
+ " print(\"4/4: Exporting to text format...\")\n",
894
+ " model_dir = os.path.join(sparse_dir, '0')\n",
895
+ " if not os.path.exists(model_dir):\n",
896
+ " # Use the first model found\n",
897
+ " subdirs = [d for d in os.listdir(sparse_dir) if os.path.isdir(os.path.join(sparse_dir, d))]\n",
898
+ " if subdirs:\n",
899
+ " model_dir = os.path.join(sparse_dir, subdirs[0])\n",
900
+ " else:\n",
901
+ " raise FileNotFoundError(\"COLMAP reconstruction failed\")\n",
902
+ "\n",
903
+ " subprocess.run([\n",
904
+ " 'colmap', 'model_converter',\n",
905
+ " '--input_path', model_dir,\n",
906
+ " '--output_path', model_dir,\n",
907
+ " '--output_type', 'TXT'\n",
908
+ " ], check=True, env=env)\n",
909
+ "\n",
910
+ " print(f\"COLMAP reconstruction complete: {model_dir}\")\n",
911
+ " return model_dir\n",
912
+ "\n",
913
+ "\n",
914
+ "def convert_cameras_to_pinhole(input_file, output_file):\n",
915
+ " \"\"\"Convert camera model to PINHOLE format\"\"\"\n",
916
+ " print(f\"Reading camera file: {input_file}\")\n",
917
+ "\n",
918
+ " with open(input_file, 'r') as f:\n",
919
+ " lines = f.readlines()\n",
920
+ "\n",
921
+ " converted_count = 0\n",
922
+ " with open(output_file, 'w') as f:\n",
923
+ " for line in lines:\n",
924
+ " if line.startswith('#') or line.strip() == '':\n",
925
+ " f.write(line)\n",
926
+ " else:\n",
927
+ " parts = line.strip().split()\n",
928
+ " if len(parts) >= 4:\n",
929
+ " cam_id = parts[0]\n",
930
+ " model = parts[1]\n",
931
+ " width = parts[2]\n",
932
+ " height = parts[3]\n",
933
+ " params = parts[4:]\n",
934
+ "\n",
935
+ " # Convert to PINHOLE format\n",
936
+ " if model == \"PINHOLE\":\n",
937
+ " f.write(line)\n",
938
+ " elif model == \"OPENCV\":\n",
939
+ " # OPENCV: fx, fy, cx, cy, k1, k2, p1, p2\n",
940
+ " fx = params[0]\n",
941
+ " fy = params[1]\n",
942
+ " cx = params[2]\n",
943
+ " cy = params[3]\n",
944
+ " f.write(f\"{cam_id} PINHOLE {width} {height} {fx} {fy} {cx} {cy}\\n\")\n",
945
+ " converted_count += 1\n",
946
+ " else:\n",
947
+ " # Convert other models too\n",
948
+ " fx = fy = max(float(width), float(height))\n",
949
+ " cx = float(width) / 2\n",
950
+ " cy = float(height) / 2\n",
951
+ " f.write(f\"{cam_id} PINHOLE {width} {height} {fx} {fy} {cx} {cy}\\n\")\n",
952
+ " converted_count += 1\n",
953
+ " else:\n",
954
+ " f.write(line)\n",
955
+ "\n",
956
+ " print(f\"Converted {converted_count} cameras to PINHOLE format\")\n",
957
+ "\n",
958
+ "\n",
959
+ "def prepare_gaussian_splatting_data(image_dir, colmap_model_dir):\n",
960
+ " \"\"\"Prepare data for Gaussian Splatting\"\"\"\n",
961
+ " print(\"Preparing data for Gaussian Splatting...\")\n",
962
+ "\n",
963
+ " data_dir = f\"{WORK_DIR}/data/video\"\n",
964
+ " os.makedirs(f\"{data_dir}/sparse/0\", exist_ok=True)\n",
965
+ " os.makedirs(f\"{data_dir}/images\", exist_ok=True)\n",
966
+ "\n",
967
+ " # Copy images\n",
968
+ " print(\"Copying images...\")\n",
969
+ " img_count = 0\n",
970
+ " for img_file in os.listdir(image_dir):\n",
971
+ " if img_file.lower().endswith(('.jpg', '.jpeg', '.png')):\n",
972
+ " shutil.copy(\n",
973
+ " os.path.join(image_dir, img_file),\n",
974
+ " f\"{data_dir}/images/{img_file}\"\n",
975
+ " )\n",
976
+ " img_count += 1\n",
977
+ " print(f\"Copied {img_count} images\")\n",
978
+ "\n",
979
+ " # Convert and copy camera file to PINHOLE format\n",
980
+ " print(\"Converting camera model to PINHOLE format...\")\n",
981
+ " convert_cameras_to_pinhole(\n",
982
+ " os.path.join(colmap_model_dir, 'cameras.txt'),\n",
983
+ " f\"{data_dir}/sparse/0/cameras.txt\"\n",
984
+ " )\n",
985
+ "\n",
986
+ " # Copy other files\n",
987
+ " for filename in ['images.txt', 'points3D.txt']:\n",
988
+ " src = os.path.join(colmap_model_dir, filename)\n",
989
+ " dst = f\"{data_dir}/sparse/0/{filename}\"\n",
990
+ " if os.path.exists(src):\n",
991
+ " shutil.copy(src, dst)\n",
992
+ " print(f\"Copied {filename}\")\n",
993
+ " else:\n",
994
+ " print(f\"Warning: {filename} not found\")\n",
995
+ "\n",
996
+ " print(f\"Data preparation complete: {data_dir}\")\n",
997
+ " return data_dir\n",
998
+ "\n",
999
+ "\n",
1000
+ "\n",
1001
+ "###############################################################\n",
1002
+ "\n",
1003
+ "# 変更後 (2DGS) - 正則化パラメータを追加\n",
1004
+ "def train_gaussian_splatting(data_dir, iterations=7000,\n",
1005
+ " lambda_normal=0.05,\n",
1006
+ " lambda_distortion=0,\n",
1007
+ " depth_ratio=0):\n",
1008
+ " \"\"\"\n",
1009
+ " 2DGS用のトレーニング関数\n",
1010
+ "\n",
1011
+ " Args:\n",
1012
+ " lambda_normal: 法線一貫性の重み (デフォルト: 0.05)\n",
1013
+ " lambda_distortion: 深度歪みの重み (デフォルト: 0)\n",
1014
+ " depth_ratio: 0=平均深度, 1=中央値深度 (デフォルト: 0)\n",
1015
+ " \"\"\"\n",
1016
+ " model_path = f\"{WORK_DIR}/output/video\"\n",
1017
+ " cmd = [\n",
1018
+ " sys.executable, 'train.py',\n",
1019
+ " '-s', data_dir,\n",
1020
+ " '-m', model_path,\n",
1021
+ " '--iterations', str(iterations),\n",
1022
+ " '--lambda_normal', str(lambda_normal),\n",
1023
+ " '--lambda_distortion', str(lambda_distortion),\n",
1024
+ " '--depth_ratio', str(depth_ratio),\n",
1025
+ " '--eval'\n",
1026
+ " ]\n",
1027
+ " subprocess.run(cmd, cwd=WORK_DIR, check=True)\n",
1028
+ " return model_path\n",
1029
+ "\n",
1030
+ "\n",
1031
+ "\n",
1032
+ "# 2DGSではメッシュ抽出オプションが追加されています\n",
1033
+ "def render_video_and_mesh(model_path, output_video_path, iteration=7000,\n",
1034
+ " extract_mesh=True, unbounded=False, mesh_res=1024):\n",
1035
+ " \"\"\"\n",
1036
+ " 2DGS用のレンダリングとメッシュ抽出\n",
1037
+ "\n",
1038
+ " Args:\n",
1039
+ " extract_mesh: メッシュを抽出するか\n",
1040
+ " unbounded: 境界なしメッシュ抽出を使用するか\n",
1041
+ " mesh_res: メッシュ解像度\n",
1042
+ " \"\"\"\n",
1043
+ " # 通常のレンダリング\n",
1044
+ " cmd = [\n",
1045
+ " sys.executable, 'render.py',\n",
1046
+ " '-m', model_path,\n",
1047
+ " '--iteration', str(iteration)\n",
1048
+ " ]\n",
1049
+ "\n",
1050
+ " # メッシュ抽出オプション追加\n",
1051
+ " if extract_mesh:\n",
1052
+ " if unbounded:\n",
1053
+ " cmd.extend(['--unbounded', '--mesh_res', str(mesh_res)])\n",
1054
+ " cmd.extend(['--skip_test', '--skip_train'])\n",
1055
+ "\n",
1056
+ " subprocess.run(cmd, cwd=WORK_DIR, check=True)\n",
1057
+ "\n",
1058
+ " # Find the rendering directory\n",
1059
+ " possible_dirs = [\n",
1060
+ " f\"{model_path}/test/ours_{iteration}/renders\",\n",
1061
+ " f\"{model_path}/train/ours_{iteration}/renders\",\n",
1062
+ " ]\n",
1063
+ "\n",
1064
+ " render_dir = None\n",
1065
+ " for test_dir in possible_dirs:\n",
1066
+ " if os.path.exists(test_dir):\n",
1067
+ " render_dir = test_dir\n",
1068
+ " print(f\"Rendering directory found: {render_dir}\")\n",
1069
+ " break\n",
1070
+ "\n",
1071
+ " if render_dir and os.path.exists(render_dir):\n",
1072
+ " render_imgs = sorted([f for f in os.listdir(render_dir) if f.endswith('.png')])\n",
1073
+ "\n",
1074
+ " if render_imgs:\n",
1075
+ " print(f\"Found {len(render_imgs)} rendered images\")\n",
1076
+ "\n",
1077
+ " # Create video with ffmpeg\n",
1078
+ " subprocess.run([\n",
1079
+ " 'ffmpeg', '-y',\n",
1080
+ " '-framerate', '30',\n",
1081
+ " '-pattern_type', 'glob',\n",
1082
+ " '-i', f\"{render_dir}/*.png\",\n",
1083
+ " '-c:v', 'libx264',\n",
1084
+ " '-pix_fmt', 'yuv420p',\n",
1085
+ " '-crf', '18',\n",
1086
+ " output_video_path\n",
1087
+ " ], check=True)\n",
1088
+ "\n",
1089
+ " print(f\"Video saved: {output_video_path}\")\n",
1090
+ " return True\n",
1091
+ "\n",
1092
+ " print(\"Error: Rendering directory not found\")\n",
1093
+ " return False\n",
1094
+ "\n",
1095
+ "###############################################################\n",
1096
+ "\n",
1097
+ "\n",
1098
+ "def create_gif(video_path, gif_path):\n",
1099
+ " \"\"\"Create GIF from MP4\"\"\"\n",
1100
+ " print(\"Creating animated GIF...\")\n",
1101
+ "\n",
1102
+ " subprocess.run([\n",
1103
+ " 'ffmpeg', '-y',\n",
1104
+ " '-i', video_path,\n",
1105
+ " '-vf', 'setpts=8*PTS,fps=10,scale=720:-1:flags=lanczos',\n",
1106
+ " '-loop', '0',\n",
1107
+ " gif_path\n",
1108
+ " ], check=True)\n",
1109
+ "\n",
1110
+ " if os.path.exists(gif_path):\n",
1111
+ " size_mb = os.path.getsize(gif_path) / (1024 * 1024)\n",
1112
+ " print(f\"GIF creation complete: {gif_path} ({size_mb:.2f} MB)\")\n",
1113
+ " return True\n",
1114
+ "\n",
1115
+ " return False"
1116
+ ]
1117
+ },
1118
+ {
1119
+ "cell_type": "code",
1120
+ "source": [],
1121
+ "metadata": {
1122
+ "id": "YtqhBP4T3jEH"
1123
+ },
1124
+ "id": "YtqhBP4T3jEH",
1125
+ "execution_count": 7,
1126
+ "outputs": []
1127
+ },
1128
+ {
1129
+ "cell_type": "code",
1130
+ "source": [
1131
+ "def main_pipeline(image_dir, output_dir, square_size=1024, max_images=100):\n",
1132
+ " \"\"\"Main execution function\"\"\"\n",
1133
+ " try:\n",
1134
+ " # Step 1: 画像の正規化と前処理\n",
1135
+ " print(\"=\"*60)\n",
1136
+ " print(\"Step 1: Normalizing and preprocessing images\")\n",
1137
+ " print(\"=\"*60)\n",
1138
+ "\n",
1139
+ " frame_dir = os.path.join(COLMAP_DIR, \"images\")\n",
1140
+ " os.makedirs(frame_dir, exist_ok=True)\n",
1141
+ "\n",
1142
+ " # 画像を正規化して直接COLMAPのディレクトリに保存\n",
1143
+ " num_processed = normalize_image_sizes_biplet(\n",
1144
+ " input_dir=image_dir,\n",
1145
+ " output_dir=frame_dir, # 直接colmap/imagesに保存\n",
1146
+ " size=square_size,\n",
1147
+ " max_images=max_images\n",
1148
+ " )\n",
1149
+ "\n",
1150
+ " print(f\"Processed {num_processed} images\")\n",
1151
+ "\n",
1152
+ " # Step 2: Estimate Camera Info with COLMAP\n",
1153
+ " print(\"=\"*60)\n",
1154
+ " print(\"Step 2: Running COLMAP reconstruction\")\n",
1155
+ " print(\"=\"*60)\n",
1156
+ " colmap_model_dir = run_colmap_reconstruction(frame_dir, COLMAP_DIR)\n",
1157
+ "\n",
1158
+ " # Step 3: Prepare Data for Gaussian Splatting\n",
1159
+ " print(\"=\"*60)\n",
1160
+ " print(\"Step 3: Preparing Gaussian Splatting data\")\n",
1161
+ " print(\"=\"*60)\n",
1162
+ " data_dir = prepare_gaussian_splatting_data(frame_dir, colmap_model_dir)\n",
1163
+ "\n",
1164
+ " # Step 4: Train Model\n",
1165
+ " print(\"=\"*60)\n",
1166
+ " print(\"Step 4: Training Gaussian Splatting model\")\n",
1167
+ " print(\"=\"*60)\n",
1168
+ " # 修正: frame_dir → data_dir\n",
1169
+ " model_path = train_gaussian_splatting(\n",
1170
+ " data_dir, # ← ここを修正!\n",
1171
+ " iterations=1000,\n",
1172
+ " lambda_normal=0.05,\n",
1173
+ " lambda_distortion=0,\n",
1174
+ " depth_ratio=0\n",
1175
+ " )\n",
1176
+ "\n",
1177
+ " print(f\"Model trained at: {model_path}\")\n",
1178
+ "\n",
1179
+ " # Step 5: Render Video\n",
1180
+ " print(\"=\"*60)\n",
1181
+ " print(\"Step 5: Rendering video\")\n",
1182
+ " print(\"=\"*60)\n",
1183
+ " os.makedirs(OUTPUT_DIR, exist_ok=True)\n",
1184
+ " output_video = os.path.join(OUTPUT_DIR, \"gaussian_splatting_video.mp4\")\n",
1185
+ "\n",
1186
+ " # 修正: output_video_path → output_video\n",
1187
+ " success = render_video_and_mesh(\n",
1188
+ " model_path,\n",
1189
+ " output_video, # ← ここを修正!\n",
1190
+ " iteration=1000,\n",
1191
+ " extract_mesh=True, # メッシュ抽出を有効化\n",
1192
+ " unbounded=True, # 境界なしメッシュ(推奨)\n",
1193
+ " mesh_res=1024\n",
1194
+ " )\n",
1195
+ "\n",
1196
+ " if success:\n",
1197
+ " print(\"=\"*60)\n",
1198
+ " print(f\"Success! Video generation complete: {output_video}\")\n",
1199
+ " print(\"=\"*60)\n",
1200
+ "\n",
1201
+ " # Create GIF\n",
1202
+ " output_gif = os.path.join(OUTPUT_DIR, \"gaussian_splatting_video.gif\")\n",
1203
+ " create_gif(output_video, output_gif)\n",
1204
+ "\n",
1205
+ " # Display result\n",
1206
+ " from IPython.display import Image, display\n",
1207
+ " display(Image(open(output_gif, 'rb').read()))\n",
1208
+ "\n",
1209
+ " return output_video, output_gif\n",
1210
+ " else:\n",
1211
+ " print(\"Warning: Rendering complete, but video was not generated\")\n",
1212
+ " return None, None\n",
1213
+ "\n",
1214
+ " except Exception as e:\n",
1215
+ " print(f\"Error: {str(e)}\")\n",
1216
+ " import traceback\n",
1217
+ " traceback.print_exc()\n",
1218
+ " return None, None\n",
1219
+ "\n",
1220
+ "\n",
1221
+ "if __name__ == \"__main__\":\n",
1222
+ " IMAGE_DIR = \"/content/drive/MyDrive/your_folder/fountain100\"\n",
1223
+ " OUTPUT_DIR = \"/content/output\"\n",
1224
+ " COLMAP_DIR = \"/content/colmap_workspace\"\n",
1225
+ "\n",
1226
+ " video_path, gif_path = main_pipeline(\n",
1227
+ " image_dir=IMAGE_DIR,\n",
1228
+ " output_dir=OUTPUT_DIR,\n",
1229
+ " square_size=1024,\n",
1230
+ " max_images=20\n",
1231
+ " )\n",
1232
+ "\n",
1233
+ " if video_path:\n",
1234
+ " print(f\"\\n✅ Success!\")\n",
1235
+ " print(f\"Video: {video_path}\")\n",
1236
+ " print(f\"GIF: {gif_path}\")\n",
1237
+ " else:\n",
1238
+ " print(\"\\n❌ Pipeline failed\")"
1239
+ ],
1240
+ "metadata": {
1241
+ "colab": {
1242
+ "base_uri": "https://localhost:8080/",
1243
+ "height": 1000
1244
+ },
1245
+ "id": "fya3kv62NXM-",
1246
+ "outputId": "4c60e0b2-e9fc-49df-d216-7d96fce737ff"
1247
+ },
1248
+ "id": "fya3kv62NXM-",
1249
+ "execution_count": 8,
1250
+ "outputs": [
1251
+ {
1252
+ "output_type": "stream",
1253
+ "name": "stdout",
1254
+ "text": [
1255
+ "============================================================\n",
1256
+ "Step 1: Normalizing and preprocessing images\n",
1257
+ "============================================================\n",
1258
+ "--- Step 1: Biplet-Square Normalization ---\n",
1259
+ "Generating 2 cropped squares (Left/Right or Top/Bottom) for each image...\n",
1260
+ "\n",
1261
+ "Processing limited to 20 source images (will generate 40 cropped images)\n",
1262
+ " ✓ image_101.jpeg: (1440, 1920) → 2 square images generated\n",
1263
+ " ✓ image_102.jpeg: (1440, 1920) → 2 square images generated\n",
1264
+ " ✓ image_103.jpeg: (1440, 1920) → 2 square images generated\n",
1265
+ " ✓ image_104.jpeg: (1440, 1920) → 2 square images generated\n",
1266
+ " ✓ image_105.jpeg: (1440, 1920) → 2 square images generated\n",
1267
+ " ✓ image_106.jpeg: (1440, 1920) → 2 square images generated\n",
1268
+ " ✓ image_107.jpeg: (1440, 1920) → 2 square images generated\n",
1269
+ " ✓ image_108.jpeg: (1440, 1920) → 2 square images generated\n",
1270
+ " ✓ image_109.jpeg: (1440, 1920) → 2 square images generated\n",
1271
+ " ✓ image_110.jpeg: (1440, 1920) → 2 square images generated\n",
1272
+ " ✓ image_111.jpeg: (1440, 1920) → 2 square images generated\n",
1273
+ " ✓ image_112.jpeg: (1440, 1920) → 2 square images generated\n",
1274
+ " ✓ image_113.jpeg: (1440, 1920) → 2 square images generated\n",
1275
+ " ✓ image_114.jpeg: (1440, 1920) → 2 square images generated\n",
1276
+ " ✓ image_115.jpeg: (1440, 1920) → 2 square images generated\n",
1277
+ " ✓ image_116.jpeg: (1440, 1920) → 2 square images generated\n",
1278
+ " ✓ image_117.jpeg: (1440, 1920) → 2 square images generated\n",
1279
+ " ✓ image_118.jpeg: (1440, 1920) → 2 square images generated\n",
1280
+ " ✓ image_119.jpeg: (1440, 1920) → 2 square images generated\n",
1281
+ " ✓ image_120.jpeg: (1440, 1920) → 2 square images generated\n",
1282
+ "\n",
1283
+ "Processing complete: 20 source images processed\n",
1284
+ "Total output images: 40\n",
1285
+ "Original size distribution: {'1440x1920': 20}\n",
1286
+ "Processed ('/content/colmap_workspace/images', ['/content/colmap_workspace/images/image_101_top.jpeg', '/content/colmap_workspace/images/image_101_bottom.jpeg', '/content/colmap_workspace/images/image_102_top.jpeg', '/content/colmap_workspace/images/image_102_bottom.jpeg', '/content/colmap_workspace/images/image_103_top.jpeg', '/content/colmap_workspace/images/image_103_bottom.jpeg', '/content/colmap_workspace/images/image_104_top.jpeg', '/content/colmap_workspace/images/image_104_bottom.jpeg', '/content/colmap_workspace/images/image_105_top.jpeg', '/content/colmap_workspace/images/image_105_bottom.jpeg', '/content/colmap_workspace/images/image_106_top.jpeg', '/content/colmap_workspace/images/image_106_bottom.jpeg', '/content/colmap_workspace/images/image_107_top.jpeg', '/content/colmap_workspace/images/image_107_bottom.jpeg', '/content/colmap_workspace/images/image_108_top.jpeg', '/content/colmap_workspace/images/image_108_bottom.jpeg', '/content/colmap_workspace/images/image_109_top.jpeg', '/content/colmap_workspace/images/image_109_bottom.jpeg', '/content/colmap_workspace/images/image_110_top.jpeg', '/content/colmap_workspace/images/image_110_bottom.jpeg', '/content/colmap_workspace/images/image_111_top.jpeg', '/content/colmap_workspace/images/image_111_bottom.jpeg', '/content/colmap_workspace/images/image_112_top.jpeg', '/content/colmap_workspace/images/image_112_bottom.jpeg', '/content/colmap_workspace/images/image_113_top.jpeg', '/content/colmap_workspace/images/image_113_bottom.jpeg', '/content/colmap_workspace/images/image_114_top.jpeg', '/content/colmap_workspace/images/image_114_bottom.jpeg', '/content/colmap_workspace/images/image_115_top.jpeg', '/content/colmap_workspace/images/image_115_bottom.jpeg', '/content/colmap_workspace/images/image_116_top.jpeg', '/content/colmap_workspace/images/image_116_bottom.jpeg', '/content/colmap_workspace/images/image_117_top.jpeg', '/content/colmap_workspace/images/image_117_bottom.jpeg', '/content/colmap_workspace/images/image_118_top.jpeg', '/content/colmap_workspace/images/image_118_bottom.jpeg', '/content/colmap_workspace/images/image_119_top.jpeg', '/content/colmap_workspace/images/image_119_bottom.jpeg', '/content/colmap_workspace/images/image_120_top.jpeg', '/content/colmap_workspace/images/image_120_bottom.jpeg']) images\n",
1287
+ "============================================================\n",
1288
+ "Step 2: Running COLMAP reconstruction\n",
1289
+ "============================================================\n",
1290
+ "Running SfM reconstruction with COLMAP...\n",
1291
+ "1/4: Extracting features...\n"
1292
+ ]
1293
+ },
1294
+ {
1295
+ "output_type": "error",
1296
+ "ename": "KeyboardInterrupt",
1297
+ "evalue": "",
1298
+ "traceback": [
1299
+ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
1300
+ "\u001b[0;31mKeyboardInterrupt\u001b[0m Traceback (most recent call last)",
1301
+ "\u001b[0;32m/tmp/ipython-input-3712511575.py\u001b[0m in \u001b[0;36m<cell line: 0>\u001b[0;34m()\u001b[0m\n\u001b[1;32m 94\u001b[0m \u001b[0mCOLMAP_DIR\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m\"/content/colmap_workspace\"\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 95\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 96\u001b[0;31m video_path, gif_path = main_pipeline(\n\u001b[0m\u001b[1;32m 97\u001b[0m \u001b[0mimage_dir\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mIMAGE_DIR\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 98\u001b[0m \u001b[0moutput_dir\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mOUTPUT_DIR\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
1302
+ "\u001b[0;32m/tmp/ipython-input-3712511575.py\u001b[0m in \u001b[0;36mmain_pipeline\u001b[0;34m(image_dir, output_dir, square_size, max_images)\u001b[0m\n\u001b[1;32m 24\u001b[0m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"Step 2: Running COLMAP reconstruction\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 25\u001b[0m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"=\"\u001b[0m\u001b[0;34m*\u001b[0m\u001b[0;36m60\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 26\u001b[0;31m \u001b[0mcolmap_model_dir\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mrun_colmap_reconstruction\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mframe_dir\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mCOLMAP_DIR\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 27\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 28\u001b[0m \u001b[0;31m# Step 3: Prepare Data for Gaussian Splatting\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
1303
+ "\u001b[0;32m/tmp/ipython-input-682645374.py\u001b[0m in \u001b[0;36mrun_colmap_reconstruction\u001b[0;34m(image_dir, colmap_dir)\u001b[0m\n\u001b[1;32m 162\u001b[0m \u001b[0;31m# Feature extraction\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 163\u001b[0m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"1/4: Extracting features...\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 164\u001b[0;31m subprocess.run([\n\u001b[0m\u001b[1;32m 165\u001b[0m \u001b[0;34m'colmap'\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m'feature_extractor'\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 166\u001b[0m \u001b[0;34m'--database_path'\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mdatabase_path\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
1304
+ "\u001b[0;32m/usr/lib/python3.12/subprocess.py\u001b[0m in \u001b[0;36mrun\u001b[0;34m(input, capture_output, timeout, check, *popenargs, **kwargs)\u001b[0m\n\u001b[1;32m 548\u001b[0m \u001b[0;32mwith\u001b[0m \u001b[0mPopen\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m*\u001b[0m\u001b[0mpopenargs\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;32mas\u001b[0m \u001b[0mprocess\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 549\u001b[0m \u001b[0;32mtry\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 550\u001b[0;31m \u001b[0mstdout\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mstderr\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mprocess\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mcommunicate\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0minput\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mtimeout\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mtimeout\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 551\u001b[0m \u001b[0;32mexcept\u001b[0m \u001b[0mTimeoutExpired\u001b[0m \u001b[0;32mas\u001b[0m \u001b[0mexc\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 552\u001b[0m \u001b[0mprocess\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mkill\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
1305
+ "\u001b[0;32m/usr/lib/python3.12/subprocess.py\u001b[0m in \u001b[0;36mcommunicate\u001b[0;34m(self, input, timeout)\u001b[0m\n\u001b[1;32m 1199\u001b[0m \u001b[0mstderr\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mstderr\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mread\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1200\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mstderr\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mclose\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 1201\u001b[0;31m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mwait\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 1202\u001b[0m \u001b[0;32melse\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1203\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mtimeout\u001b[0m \u001b[0;32mis\u001b[0m \u001b[0;32mnot\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
1306
+ "\u001b[0;32m/usr/lib/python3.12/subprocess.py\u001b[0m in \u001b[0;36mwait\u001b[0;34m(self, timeout)\u001b[0m\n\u001b[1;32m 1262\u001b[0m \u001b[0mendtime\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0m_time\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;34m+\u001b[0m \u001b[0mtimeout\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1263\u001b[0m \u001b[0;32mtry\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 1264\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_wait\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mtimeout\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mtimeout\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 1265\u001b[0m \u001b[0;32mexcept\u001b[0m \u001b[0mKeyboardInterrupt\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1266\u001b[0m \u001b[0;31m# https://bugs.python.org/issue25942\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
1307
+ "\u001b[0;32m/usr/lib/python3.12/subprocess.py\u001b[0m in \u001b[0;36m_wait\u001b[0;34m(self, timeout)\u001b[0m\n\u001b[1;32m 2051\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mreturncode\u001b[0m \u001b[0;32mis\u001b[0m \u001b[0;32mnot\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 2052\u001b[0m \u001b[0;32mbreak\u001b[0m \u001b[0;31m# Another thread waited.\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 2053\u001b[0;31m \u001b[0;34m(\u001b[0m\u001b[0mpid\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0msts\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_try_wait\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 2054\u001b[0m \u001b[0;31m# Check the pid and loop as waitpid has been known to\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 2055\u001b[0m \u001b[0;31m# return 0 even without WNOHANG in odd situations.\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
1308
+ "\u001b[0;32m/usr/lib/python3.12/subprocess.py\u001b[0m in \u001b[0;36m_try_wait\u001b[0;34m(self, wait_flags)\u001b[0m\n\u001b[1;32m 2009\u001b[0m \u001b[0;34m\"\"\"All callers to this function MUST hold self._waitpid_lock.\"\"\"\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 2010\u001b[0m \u001b[0;32mtry\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 2011\u001b[0;31m \u001b[0;34m(\u001b[0m\u001b[0mpid\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0msts\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mos\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mwaitpid\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mpid\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mwait_flags\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 2012\u001b[0m \u001b[0;32mexcept\u001b[0m \u001b[0mChildProcessError\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 2013\u001b[0m \u001b[0;31m# This happens if SIGCLD is set to be ignored or waiting\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
1309
+ "\u001b[0;31mKeyboardInterrupt\u001b[0m: "
1310
+ ]
1311
+ }
1312
+ ]
1313
+ },
1314
+ {
1315
+ "cell_type": "code",
1316
+ "execution_count": null,
1317
+ "id": "f75233a8",
1318
+ "metadata": {
1319
+ "execution": {
1320
+ "iopub.execute_input": "2026-01-10T18:22:43.807508Z",
1321
+ "iopub.status.busy": "2026-01-10T18:22:43.807294Z",
1322
+ "iopub.status.idle": "2026-01-11T00:00:17.030890Z",
1323
+ "shell.execute_reply": "2026-01-11T00:00:17.029927Z"
1324
+ },
1325
+ "papermill": {
1326
+ "duration": 20253.434865,
1327
+ "end_time": "2026-01-11T00:00:17.234174",
1328
+ "exception": false,
1329
+ "start_time": "2026-01-10T18:22:43.799309",
1330
+ "status": "completed"
1331
+ },
1332
+ "tags": [],
1333
+ "id": "f75233a8"
1334
+ },
1335
+ "outputs": [],
1336
+ "source": [
1337
+ "\n",
1338
+ "\n"
1339
+ ]
1340
+ },
1341
+ {
1342
+ "cell_type": "markdown",
1343
+ "id": "e17ec719",
1344
+ "metadata": {
1345
+ "papermill": {
1346
+ "duration": 0.49801,
1347
+ "end_time": "2026-01-11T00:00:18.165833",
1348
+ "exception": false,
1349
+ "start_time": "2026-01-11T00:00:17.667823",
1350
+ "status": "completed"
1351
+ },
1352
+ "tags": [],
1353
+ "id": "e17ec719"
1354
+ },
1355
+ "source": []
1356
+ },
1357
+ {
1358
+ "cell_type": "markdown",
1359
+ "id": "38b3974c",
1360
+ "metadata": {
1361
+ "papermill": {
1362
+ "duration": 0.427583,
1363
+ "end_time": "2026-01-11T00:00:19.008387",
1364
+ "exception": false,
1365
+ "start_time": "2026-01-11T00:00:18.580804",
1366
+ "status": "completed"
1367
+ },
1368
+ "tags": [],
1369
+ "id": "38b3974c"
1370
+ },
1371
+ "source": []
1372
+ }
1373
+ ],
1374
+ "metadata": {
1375
+ "kaggle": {
1376
+ "accelerator": "nvidiaTeslaT4",
1377
+ "dataSources": [
1378
+ {
1379
+ "databundleVersionId": 5447706,
1380
+ "sourceId": 49349,
1381
+ "sourceType": "competition"
1382
+ },
1383
+ {
1384
+ "datasetId": 1429416,
1385
+ "sourceId": 14451718,
1386
+ "sourceType": "datasetVersion"
1387
+ }
1388
+ ],
1389
+ "dockerImageVersionId": 31090,
1390
+ "isGpuEnabled": true,
1391
+ "isInternetEnabled": true,
1392
+ "language": "python",
1393
+ "sourceType": "notebook"
1394
+ },
1395
+ "kernelspec": {
1396
+ "display_name": "Python 3",
1397
+ "name": "python3"
1398
+ },
1399
+ "language_info": {
1400
+ "codemirror_mode": {
1401
+ "name": "ipython",
1402
+ "version": 3
1403
+ },
1404
+ "file_extension": ".py",
1405
+ "mimetype": "text/x-python",
1406
+ "name": "python",
1407
+ "nbconvert_exporter": "python",
1408
+ "pygments_lexer": "ipython3",
1409
+ "version": "3.11.13"
1410
+ },
1411
+ "papermill": {
1412
+ "default_parameters": {},
1413
+ "duration": 20573.990788,
1414
+ "end_time": "2026-01-11T00:00:22.081506",
1415
+ "environment_variables": {},
1416
+ "exception": null,
1417
+ "input_path": "__notebook__.ipynb",
1418
+ "output_path": "__notebook__.ipynb",
1419
+ "parameters": {},
1420
+ "start_time": "2026-01-10T18:17:28.090718",
1421
+ "version": "2.6.0"
1422
+ },
1423
+ "colab": {
1424
+ "provenance": [],
1425
+ "gpuType": "T4"
1426
+ },
1427
+ "accelerator": "GPU"
1428
+ },
1429
+ "nbformat": 4,
1430
+ "nbformat_minor": 5
1431
+ }