stpete2 commited on
Commit
1ba1936
ยท
verified ยท
1 Parent(s): 826b93d

Upload 2 files

Browse files
biplet_colmap_2dgs_colab_09.ipynb ADDED
@@ -0,0 +1,1521 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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": "markdown",
23
+ "source": [
24
+ "# ๆ–ฐใ—ใ„ใ‚ปใ‚ฏใ‚ทใƒงใƒณ"
25
+ ],
26
+ "metadata": {
27
+ "id": "jK0ja9PfddVA"
28
+ },
29
+ "id": "jK0ja9PfddVA"
30
+ },
31
+ {
32
+ "cell_type": "code",
33
+ "source": [
34
+ "#ใ‚ตใ‚คใ‚บใฎ็•ฐใชใ‚‹็”ปๅƒใ‚’ๆ‰ฑใ†\n",
35
+ "from google.colab import drive\n",
36
+ "drive.mount('/content/drive')"
37
+ ],
38
+ "metadata": {
39
+ "colab": {
40
+ "base_uri": "https://localhost:8080/"
41
+ },
42
+ "id": "JON4rYSEOzCg",
43
+ "outputId": "458cec38-282c-48a0-a836-832559e5acf1"
44
+ },
45
+ "id": "JON4rYSEOzCg",
46
+ "execution_count": 32,
47
+ "outputs": [
48
+ {
49
+ "output_type": "stream",
50
+ "name": "stdout",
51
+ "text": [
52
+ "Drive already mounted at /content/drive; to attempt to forcibly remount, call drive.mount(\"/content/drive\", force_remount=True).\n"
53
+ ]
54
+ }
55
+ ]
56
+ },
57
+ {
58
+ "cell_type": "code",
59
+ "execution_count": 33,
60
+ "id": "22353010",
61
+ "metadata": {
62
+ "execution": {
63
+ "iopub.execute_input": "2026-01-10T18:17:32.181455Z",
64
+ "iopub.status.busy": "2026-01-10T18:17:32.180969Z",
65
+ "iopub.status.idle": "2026-01-10T18:17:32.355942Z",
66
+ "shell.execute_reply": "2026-01-10T18:17:32.355229Z"
67
+ },
68
+ "papermill": {
69
+ "duration": 0.179454,
70
+ "end_time": "2026-01-10T18:17:32.357275",
71
+ "exception": false,
72
+ "start_time": "2026-01-10T18:17:32.177821",
73
+ "status": "completed"
74
+ },
75
+ "tags": [],
76
+ "id": "22353010"
77
+ },
78
+ "outputs": [],
79
+ "source": [
80
+ "import os\n",
81
+ "import sys\n",
82
+ "import subprocess\n",
83
+ "import shutil\n",
84
+ "from pathlib import Path\n",
85
+ "import cv2\n",
86
+ "from PIL import Image\n",
87
+ "import glob\n",
88
+ "\n",
89
+ "IMAGE_PATH=\"/content/drive/MyDrive/your_folder/fountain100\"\n",
90
+ "\n",
91
+ "#WORK_DIR = '/content/gaussian-splatting'\n",
92
+ "WORK_DIR = \"/content/2d-gaussian-splatting\"\n",
93
+ "\n",
94
+ "OUTPUT_DIR = '/content/output'\n",
95
+ "COLMAP_DIR = '/content/colmap_data'"
96
+ ]
97
+ },
98
+ {
99
+ "cell_type": "code",
100
+ "execution_count": null,
101
+ "id": "be6df249",
102
+ "metadata": {
103
+ "execution": {
104
+ "iopub.execute_input": "2026-01-10T18:17:32.363444Z",
105
+ "iopub.status.busy": "2026-01-10T18:17:32.363175Z",
106
+ "iopub.status.idle": "2026-01-10T18:22:43.720241Z",
107
+ "shell.execute_reply": "2026-01-10T18:22:43.719380Z"
108
+ },
109
+ "papermill": {
110
+ "duration": 311.361656,
111
+ "end_time": "2026-01-10T18:22:43.721610",
112
+ "exception": false,
113
+ "start_time": "2026-01-10T18:17:32.359954",
114
+ "status": "completed"
115
+ },
116
+ "tags": [],
117
+ "id": "be6df249",
118
+ "outputId": "4d17052f-2c01-4f3e-ebd6-cb864bc264a5",
119
+ "colab": {
120
+ "base_uri": "https://localhost:8080/"
121
+ }
122
+ },
123
+ "outputs": [
124
+ {
125
+ "output_type": "stream",
126
+ "name": "stdout",
127
+ "text": [
128
+ "๐Ÿš€ Setting up COLAB environment (v8 - Python 3.12 compatible)\n",
129
+ "\n",
130
+ "======================================================================\n",
131
+ "STEP 0: Fix NumPy (Python 3.12 compatible)\n",
132
+ "======================================================================\n",
133
+ "Running: /usr/bin/python3 -m pip uninstall -y numpy\n",
134
+ "Running: /usr/bin/python3 -m pip install numpy==1.26.4\n",
135
+ "Running: /usr/bin/python3 -c import numpy; print('NumPy:', numpy.__version__)\n",
136
+ "\n",
137
+ "======================================================================\n",
138
+ "STEP 1: System packages\n",
139
+ "======================================================================\n",
140
+ "Running: apt-get update -qq\n",
141
+ "Running: apt-get install -y -qq colmap build-essential cmake git libopenblas-dev xvfb\n",
142
+ "\n",
143
+ "======================================================================\n",
144
+ "STEP 2: Clone Gaussian Splatting\n",
145
+ "======================================================================\n",
146
+ "โœ“ Repository already exists\n",
147
+ "\n",
148
+ "======================================================================\n",
149
+ "STEP 3: Python packages (VERBOSE MODE)\n",
150
+ "======================================================================\n",
151
+ "\n",
152
+ "๐Ÿ“ฆ Installing PyTorch...\n",
153
+ "Running: /usr/bin/python3 -m pip install torch torchvision torchaudio\n",
154
+ "\n",
155
+ "๐Ÿ“ฆ Installing core utilities...\n",
156
+ "Running: /usr/bin/python3 -m pip install opencv-python pillow imageio imageio-ffmpeg plyfile tqdm tensorboard\n",
157
+ "\n",
158
+ "๐Ÿ“ฆ Installing transformers (NumPy 1.26 compatible)...\n",
159
+ "Running: /usr/bin/python3 -m pip install transformers==4.40.0\n",
160
+ "\n",
161
+ "๐Ÿ“ฆ Installing LightGlue stack...\n",
162
+ "Running: /usr/bin/python3 -m pip install kornia\n",
163
+ "Running: /usr/bin/python3 -m pip install h5py\n"
164
+ ]
165
+ }
166
+ ],
167
+ "source": [
168
+ "def run_cmd(cmd, check=True, capture=False, cwd=None): # โ† cwd=None ใ‚’่ฟฝๅŠ \n",
169
+ " \"\"\"Run command with better error handling\"\"\"\n",
170
+ " print(f\"Running: {' '.join(cmd)}\")\n",
171
+ " result = subprocess.run(\n",
172
+ " cmd,\n",
173
+ " capture_output=capture,\n",
174
+ " text=True,\n",
175
+ " check=False,\n",
176
+ " cwd=cwd # โ† ใ“ใ“ใซๆธกใ™\n",
177
+ " )\n",
178
+ " if check and result.returncode != 0:\n",
179
+ " print(f\"โŒ Command failed with code {result.returncode}\")\n",
180
+ " if capture:\n",
181
+ " print(f\"STDOUT: {result.stdout}\")\n",
182
+ " print(f\"STDERR: {result.stderr}\")\n",
183
+ " return result\n",
184
+ "\n",
185
+ "\n",
186
+ "def setup_environment():\n",
187
+ " \"\"\"\n",
188
+ " Colab environment setup for Gaussian Splatting + LightGlue + pycolmap\n",
189
+ " Python 3.12 compatible version (v8)\n",
190
+ " \"\"\"\n",
191
+ "\n",
192
+ " print(\"๐Ÿš€ Setting up COLAB environment (v8 - Python 3.12 compatible)\")\n",
193
+ "\n",
194
+ " WORK_DIR = \"2d-gaussian-splatting\"\n",
195
+ "\n",
196
+ " # =====================================================================\n",
197
+ " # STEP 0: NumPy FIX (Python 3.12 compatible)\n",
198
+ " # =====================================================================\n",
199
+ " print(\"\\n\" + \"=\"*70)\n",
200
+ " print(\"STEP 0: Fix NumPy (Python 3.12 compatible)\")\n",
201
+ " print(\"=\"*70)\n",
202
+ "\n",
203
+ " # Python 3.12 requires numpy >= 1.26\n",
204
+ " run_cmd([sys.executable, \"-m\", \"pip\", \"uninstall\", \"-y\", \"numpy\"])\n",
205
+ " run_cmd([sys.executable, \"-m\", \"pip\", \"install\", \"numpy==1.26.4\"])\n",
206
+ "\n",
207
+ " # sanity check\n",
208
+ " run_cmd([sys.executable, \"-c\", \"import numpy; print('NumPy:', numpy.__version__)\"])\n",
209
+ "\n",
210
+ " # =====================================================================\n",
211
+ " # STEP 1: System packages (Colab)\n",
212
+ " # =====================================================================\n",
213
+ " print(\"\\n\" + \"=\"*70)\n",
214
+ " print(\"STEP 1: System packages\")\n",
215
+ " print(\"=\"*70)\n",
216
+ "\n",
217
+ " run_cmd([\"apt-get\", \"update\", \"-qq\"])\n",
218
+ " run_cmd([\n",
219
+ " \"apt-get\", \"install\", \"-y\", \"-qq\",\n",
220
+ " \"colmap\",\n",
221
+ " \"build-essential\",\n",
222
+ " \"cmake\",\n",
223
+ " \"git\",\n",
224
+ " \"libopenblas-dev\",\n",
225
+ " \"xvfb\"\n",
226
+ " ])\n",
227
+ "\n",
228
+ " # virtual display (COLMAP / OpenCV safety)\n",
229
+ " os.environ[\"QT_QPA_PLATFORM\"] = \"offscreen\"\n",
230
+ " os.environ[\"DISPLAY\"] = \":99\"\n",
231
+ " subprocess.Popen(\n",
232
+ " [\"Xvfb\", \":99\", \"-screen\", \"0\", \"1024x768x24\"],\n",
233
+ " stdout=subprocess.DEVNULL,\n",
234
+ " stderr=subprocess.DEVNULL\n",
235
+ " )\n",
236
+ "\n",
237
+ " # =====================================================================\n",
238
+ " # STEP 2: Clone 2D Gaussian Splatting\n",
239
+ " # =====================================================================\n",
240
+ " print(\"\\n\" + \"=\"*70)\n",
241
+ " print(\"STEP 2: Clone Gaussian Splatting\")\n",
242
+ " print(\"=\"*70)\n",
243
+ "\n",
244
+ " if not os.path.exists(WORK_DIR):\n",
245
+ " run_cmd([\n",
246
+ " \"git\", \"clone\", \"--recursive\",\n",
247
+ " \"https://github.com/hbb1/2d-gaussian-splatting.git\",\n",
248
+ " WORK_DIR\n",
249
+ " ])\n",
250
+ " else:\n",
251
+ " print(\"โœ“ Repository already exists\")\n",
252
+ "\n",
253
+ " # =====================================================================\n",
254
+ " # STEP 3: Python packages (FIXED ORDER & VERSIONS)\n",
255
+ " # =====================================================================\n",
256
+ " print(\"\\n\" + \"=\"*70)\n",
257
+ " print(\"STEP 3: Python packages (VERBOSE MODE)\")\n",
258
+ " print(\"=\"*70)\n",
259
+ "\n",
260
+ " # ---- PyTorch (Colab CUDAๅฏพๅฟœ) ----\n",
261
+ " print(\"\\n๐Ÿ“ฆ Installing PyTorch...\")\n",
262
+ " run_cmd([\n",
263
+ " sys.executable, \"-m\", \"pip\", \"install\",\n",
264
+ " \"torch\", \"torchvision\", \"torchaudio\"\n",
265
+ " ])\n",
266
+ "\n",
267
+ " # ---- Core utils ----\n",
268
+ " print(\"\\n๐Ÿ“ฆ Installing core utilities...\")\n",
269
+ " run_cmd([\n",
270
+ " sys.executable, \"-m\", \"pip\", \"install\",\n",
271
+ " \"opencv-python\",\n",
272
+ " \"pillow\",\n",
273
+ " \"imageio\",\n",
274
+ " \"imageio-ffmpeg\",\n",
275
+ " \"plyfile\",\n",
276
+ " \"tqdm\",\n",
277
+ " \"tensorboard\"\n",
278
+ " ])\n",
279
+ "\n",
280
+ " # ---- transformers (NumPy 1.26 compatible) ----\n",
281
+ " print(\"\\n๐Ÿ“ฆ Installing transformers (NumPy 1.26 compatible)...\")\n",
282
+ " # Install transformers with proper dependencies\n",
283
+ " run_cmd([\n",
284
+ " sys.executable, \"-m\", \"pip\", \"install\",\n",
285
+ " \"transformers==4.40.0\"\n",
286
+ " ])\n",
287
+ "\n",
288
+ " # ---- LightGlue stack (GITHUB INSTALL) ----\n",
289
+ " print(\"\\n๐Ÿ“ฆ Installing LightGlue stack...\")\n",
290
+ "\n",
291
+ " # Install kornia first\n",
292
+ " run_cmd([sys.executable, \"-m\", \"pip\", \"install\", \"kornia\"])\n",
293
+ "\n",
294
+ " # Install h5py (sometimes needed)\n",
295
+ " run_cmd([sys.executable, \"-m\", \"pip\", \"install\", \"h5py\"])\n",
296
+ "\n",
297
+ " # Install matplotlib (LightGlue dependency)\n",
298
+ " run_cmd([sys.executable, \"-m\", \"pip\", \"install\", \"matplotlib\"])\n",
299
+ "\n",
300
+ " # Install pycolmap\n",
301
+ " run_cmd([sys.executable, \"-m\", \"pip\", \"install\", \"pycolmap\"])\n",
302
+ "\n",
303
+ "\n",
304
+ "\n",
305
+ " # =====================================================================\n",
306
+ " # STEP 4: Detailed Verification\n",
307
+ " # =====================================================================\n",
308
+ " print(\"\\n\" + \"=\"*70)\n",
309
+ " print(\"STEP 4: Detailed Verification\")\n",
310
+ " print(\"=\"*70)\n",
311
+ "\n",
312
+ " # NumPy (verify version first)\n",
313
+ " print(\"\\n๐Ÿ” Testing NumPy...\")\n",
314
+ " try:\n",
315
+ " import numpy as np\n",
316
+ " print(f\" โœ“ NumPy: {np.__version__}\")\n",
317
+ " except Exception as e:\n",
318
+ " print(f\" โŒ NumPy failed: {e}\")\n",
319
+ "\n",
320
+ " # PyTorch\n",
321
+ " print(\"\\n๐Ÿ” Testing PyTorch...\")\n",
322
+ " try:\n",
323
+ " import torch\n",
324
+ " print(f\" โœ“ PyTorch: {torch.__version__}\")\n",
325
+ " print(f\" โœ“ CUDA available: {torch.cuda.is_available()}\")\n",
326
+ " if torch.cuda.is_available():\n",
327
+ " print(f\" โœ“ CUDA version: {torch.version.cuda}\")\n",
328
+ " except Exception as e:\n",
329
+ " print(f\" โŒ PyTorch failed: {e}\")\n",
330
+ "\n",
331
+ " # transformers\n",
332
+ " print(\"\\n๐Ÿ” Testing transformers...\")\n",
333
+ " try:\n",
334
+ " import transformers\n",
335
+ " print(f\" โœ“ transformers version: {transformers.__version__}\")\n",
336
+ " from transformers import AutoModel\n",
337
+ " print(f\" โœ“ AutoModel import: OK\")\n",
338
+ " except Exception as e:\n",
339
+ " print(f\" โŒ transformers failed: {e}\")\n",
340
+ " print(f\" Attempting detailed diagnosis...\")\n",
341
+ " result = run_cmd([\n",
342
+ " sys.executable, \"-c\",\n",
343
+ " \"import transformers; print(transformers.__version__)\"\n",
344
+ " ], capture=True)\n",
345
+ " print(f\" Output: {result.stdout}\")\n",
346
+ " print(f\" Error: {result.stderr}\")\n",
347
+ "\n",
348
+ " # pycolmap\n",
349
+ " print(\"\\n๐Ÿ” Testing pycolmap...\")\n",
350
+ " try:\n",
351
+ " import pycolmap\n",
352
+ " print(f\" โœ“ pycolmap: OK\")\n",
353
+ " except Exception as e:\n",
354
+ " print(f\" โŒ pycolmap failed: {e}\")\n",
355
+ "\n",
356
+ " # kornia\n",
357
+ " print(\"\\n๐Ÿ” Testing kornia...\")\n",
358
+ " try:\n",
359
+ " import kornia\n",
360
+ " print(f\" โœ“ kornia: {kornia.__version__}\")\n",
361
+ " except Exception as e:\n",
362
+ " print(f\" โŒ kornia failed: {e}\")\n",
363
+ "\n",
364
+ " return WORK_DIR\n",
365
+ "\n",
366
+ "\n",
367
+ "if __name__ == \"__main__\":\n",
368
+ " setup_environment()"
369
+ ]
370
+ },
371
+ {
372
+ "cell_type": "code",
373
+ "source": [],
374
+ "metadata": {
375
+ "id": "3UEcAPBILz6Z"
376
+ },
377
+ "id": "3UEcAPBILz6Z",
378
+ "execution_count": null,
379
+ "outputs": []
380
+ },
381
+ {
382
+ "cell_type": "code",
383
+ "source": [
384
+ "# =====================================================================\n",
385
+ "# STEP 4: Build 2D GS submodules (็ขบๅฎŸใชๆ–นๆณ•)\n",
386
+ "# =====================================================================\n",
387
+ "print(\"\\n\" + \"=\"*70)\n",
388
+ "print(\"STEP 5: Build Gaussian Splatting submodules\")\n",
389
+ "print(\"=\"*70)\n",
390
+ "\n",
391
+ "# diff-surfel-rasterization\n",
392
+ "\n",
393
+ "path = os.path.join(WORK_DIR, \"submodules\", \"diff-surfel-rasterization\")\n",
394
+ "url = \"https://github.com/hbb1/diff-surfel-rasterization.git\"\n",
395
+ "name = os.path.basename(path)\n",
396
+ "print(f\"\\n๐Ÿ“ฆ Processing {name}...\")\n",
397
+ "if not os.path.exists(path):\n",
398
+ " print(f\" > Cloning {url}...\")\n",
399
+ " # ่ฆชใƒ‡ใ‚ฃใƒฌใ‚ฏใƒˆใƒชใŒๅญ˜ๅœจใ™ใ‚‹ใ“ใจใ‚’็ขบ่ช\n",
400
+ " os.makedirs(os.path.dirname(path), exist_ok=True)\n",
401
+ " run_cmd([\"git\", \"clone\", url, path])\n",
402
+ "else:\n",
403
+ " print(f\" โœ“ {name} already exists.\")\n",
404
+ "# 2. setup.py install (ใ‚ณใƒณใƒ‘ใ‚คใƒซ)\n",
405
+ "print(f\" > Compiling and Installing {name}...\")\n",
406
+ "result = run_cmd(\n",
407
+ " [sys.executable, \"setup.py\", \"install\"],\n",
408
+ " cwd=path,\n",
409
+ " check=False, # ใ‚จใƒฉใƒผใงใ‚‚ๆญขใ‚ใชใ„\n",
410
+ " capture=True\n",
411
+ ")\n",
412
+ "if result.returncode != 0:\n",
413
+ " print(f\"โŒ Failed to build {name}\")\n",
414
+ " print(\"--- STDERR ---\")\n",
415
+ " print(result.stderr)\n",
416
+ "else:\n",
417
+ " print(f\"โœ… Successfully built {name}\")"
418
+ ],
419
+ "metadata": {
420
+ "id": "kLdJ-FeT-kQc"
421
+ },
422
+ "id": "kLdJ-FeT-kQc",
423
+ "execution_count": null,
424
+ "outputs": []
425
+ },
426
+ {
427
+ "cell_type": "code",
428
+ "source": [
429
+ "import os\n",
430
+ "import sys\n",
431
+ "import shutil\n",
432
+ "import subprocess\n",
433
+ "\n",
434
+ "# --- ๅ‰ๆบ–ๅ‚™: ็’ฐๅขƒใฎๆ•ดๅ‚™ ---\n",
435
+ "print(\"Configuring build environment...\")\n",
436
+ "# 1. CUDAใ‚ณใƒณใƒ‘ใ‚คใƒฉใฎ็ขบ่ช\n",
437
+ "!nvcc --version\n",
438
+ "\n",
439
+ "# 2. ๅฟ…้ ˆใƒ„ใƒผใƒซใฎใ‚คใƒณใ‚นใƒˆใƒผใƒซ (ninjaใฏใƒ“ใƒซใƒ‰ใ‚’ๅฎ‰ๅฎšใƒป้ซ˜้€ŸๅŒ–ใ•ใ›ใพใ™)\n",
440
+ "!pip install setuptools wheel ninja\n",
441
+ "\n",
442
+ "# 3. ็’ฐๅขƒๅค‰ๆ•ฐใฎใ‚ปใƒƒใƒˆใ‚ขใƒƒใƒ— (CUDAใฎใƒ‘ใ‚นใ‚’ๆ˜Ž็คบ็š„ใซๆŒ‡ๅฎš)\n",
443
+ "os.environ[\"CUDA_HOME\"] = \"/usr/local/cuda\"\n",
444
+ "os.environ[\"PATH\"] = f'{os.environ[\"CUDA_HOME\"]}/bin:{os.environ[\"PATH\"]}'\n",
445
+ "os.environ[\"LD_LIBRARY_PATH\"] = f'{os.environ[\"CUDA_HOME\"]}/lib64:{os.environ[\"LD_LIBRARY_PATH\"]}'\n",
446
+ "# ใƒกใƒขใƒชไธ่ถณใซใ‚ˆใ‚‹ใ‚ฏใƒฉใƒƒใ‚ทใƒฅใ‚’้˜ฒใใŸใ‚ใ€ไธฆๅˆ—ใƒ“ใƒซใƒ‰ๆ•ฐใ‚’ๅˆถ้™\n",
447
+ "os.environ[\"MAX_JOBS\"] = \"2\"\n",
448
+ "\n",
449
+ "def run_cmd(cmd, cwd=None, check=True):\n",
450
+ " \"\"\"ใ‚ณใƒžใƒณใƒ‰ๅฎŸ่กŒ็”จใฎใƒ˜ใƒซใƒ‘ใƒผ้–ขๆ•ฐ\"\"\"\n",
451
+ " return subprocess.run(cmd, cwd=cwd, capture_output=True, text=True, check=check)\n",
452
+ "\n",
453
+ "def install_submodule(name, url, base_dir):\n",
454
+ " \"\"\"ๅ€‹ๅˆฅใฎใ‚ตใƒ–ใƒขใ‚ธใƒฅใƒผใƒซใ‚’ใ‚คใƒณใ‚นใƒˆใƒผใƒซ\"\"\"\n",
455
+ " print(f\"\\n{'='*70}\")\n",
456
+ " print(f\"Installing {name}\")\n",
457
+ " print(f\"{'='*70}\")\n",
458
+ "\n",
459
+ " # ็ตถๅฏพใƒ‘ใ‚นใ‚’ไฝฟ็”จ\n",
460
+ " path = os.path.abspath(os.path.join(base_dir, \"submodules\", name))\n",
461
+ " print(f\" > Target path: {path}\")\n",
462
+ "\n",
463
+ " # Step 1: ๆ—ขๅญ˜ใ‚’ๅ‰Š้™ค\n",
464
+ " if os.path.exists(path):\n",
465
+ " print(f\" > Removing old {name}...\")\n",
466
+ " shutil.rmtree(path)\n",
467
+ "\n",
468
+ " # Step 2: ใ‚ฏใƒญใƒผใƒณ\n",
469
+ " print(f\" > Cloning from {url}...\")\n",
470
+ " os.makedirs(os.path.dirname(path), exist_ok=True)\n",
471
+ " try:\n",
472
+ " run_cmd([\"git\", \"clone\", url, path])\n",
473
+ " except subprocess.CalledProcessError as e:\n",
474
+ " print(f\"โŒ Failed to clone {name}\")\n",
475
+ " print(e.stderr)\n",
476
+ " return False\n",
477
+ "\n",
478
+ " # Step 3: ใƒ•ใ‚กใ‚คใƒซ็ขบ่ช (spatial.cu ็ญ‰ใฎๅญ˜ๅœจใ‚’ใƒใ‚งใƒƒใ‚ฏ)\n",
479
+ " print(f\" > Checking cloned files...\")\n",
480
+ " files = os.listdir(path)\n",
481
+ " print(f\" > Files in {name}: {files[:10]}...\")\n",
482
+ "\n",
483
+ " # Step 4: ็‰นๅฎšใƒขใ‚ธใƒฅใƒผใƒซใฎใ‚ตใƒ–ใƒขใ‚ธใƒฅใƒผใƒซๅˆๆœŸๅŒ–\n",
484
+ " if name == \"diff-surfel-rasterization\":\n",
485
+ " print(f\" > Initializing GLM submodule...\")\n",
486
+ " run_cmd([\"git\", \"submodule\", \"update\", \"--init\", \"--recursive\"], cwd=path)\n",
487
+ "\n",
488
+ " # Step 5: ใƒ“ใƒซใƒ‰ใ‚ญใƒฃใƒƒใ‚ทใƒฅๅ‰Š้™ค\n",
489
+ " build_dir = os.path.join(path, \"build\")\n",
490
+ " if os.path.exists(build_dir):\n",
491
+ " print(f\" > Cleaning build cache...\")\n",
492
+ " shutil.rmtree(build_dir)\n",
493
+ "\n",
494
+ " # Step 6: ใ‚คใƒณใ‚นใƒˆใƒผใƒซ\n",
495
+ " print(f\" > Installing {name} (This may take a few minutes)...\")\n",
496
+ " # ็’ฐๅขƒๅค‰ๆ•ฐใ‚’ๆ˜Ž็คบ็š„ใซๅผ•ใ็ถ™ใ\n",
497
+ " current_env = os.environ.copy()\n",
498
+ "\n",
499
+ " result = subprocess.run(\n",
500
+ " [sys.executable, \"-m\", \"pip\", \"install\", \"-e\", \".\", \"--no-build-isolation\", \"-v\"],\n",
501
+ " cwd=path,\n",
502
+ " env=current_env,\n",
503
+ " capture_output=True,\n",
504
+ " text=True\n",
505
+ " )\n",
506
+ "\n",
507
+ " if result.returncode != 0:\n",
508
+ " print(f\"โŒ Failed to install {name}\")\n",
509
+ " # C++/CUDAใฎใƒ“ใƒซใƒ‰ใ‚จใƒฉใƒผใฏ stdout ใซๅ‡บใ‚‹ใ“ใจใŒๅคšใ„ใŸใ‚ใ€ไธกๆ–นๅ‡บๅŠ›\n",
510
+ " print(\"\\n--- STDOUT (Build Logs) ---\")\n",
511
+ " stdout_lines = result.stdout.split('\\n')\n",
512
+ " print('\\n'.join(stdout_lines[-60:])) # ๆœ€ๅพŒใฎ60่กŒใ‚’่กจ็คบ\n",
513
+ "\n",
514
+ " print(\"\\n--- STDERR (Error Details) ---\")\n",
515
+ " print(result.stderr)\n",
516
+ " return False\n",
517
+ "\n",
518
+ " print(f\"โœ… Successfully installed {name}\")\n",
519
+ " return True\n",
520
+ "\n",
521
+ "# =====================================================================\n",
522
+ "# STEP 4: Build 2D GS submodules\n",
523
+ "# =====================================================================\n",
524
+ "print(\"\\n\" + \"=\"*70)\n",
525
+ "print(\"STEP 4: Build Gaussian Splatting submodules\")\n",
526
+ "print(\"=\"*70)\n",
527
+ "\n",
528
+ "# Colabใฎๅ ดๅˆใฏ็ตถๅฏพใƒ‘ใ‚น\n",
529
+ "WORK_DIR = \"/content/2d-gaussian-splatting\"\n",
530
+ "\n",
531
+ "# ๅ„ใ‚ตใƒ–ใƒขใ‚ธใƒฅใƒผใƒซใฎใ‚คใƒณใ‚นใƒˆใƒผใƒซ\n",
532
+ "# simple-knn\n",
533
+ "success_knn = install_submodule(\n",
534
+ " \"simple-knn\",\n",
535
+ " \"https://github.com/tztechno/simple-knn.git\",\n",
536
+ " WORK_DIR\n",
537
+ ")\n",
538
+ "\n",
539
+ "\n",
540
+ "# ็ตๆžœ่กจ็คบ\n",
541
+ "print(\"\\n\" + \"=\"*70)\n",
542
+ "print(\"Installation Summary\")\n",
543
+ "print(\"=\"*70)\n",
544
+ "print(f\"simple-knn: {'โœ… Success' if success_knn else 'โŒ Failed'}\")"
545
+ ],
546
+ "metadata": {
547
+ "id": "qYgJl2Fw_Phk"
548
+ },
549
+ "id": "qYgJl2Fw_Phk",
550
+ "execution_count": null,
551
+ "outputs": []
552
+ },
553
+ {
554
+ "cell_type": "code",
555
+ "source": [
556
+ "def setup_2dgs_environment():\n",
557
+ " \"\"\"2DGS็’ฐๅขƒใฎใ‚ปใƒƒใƒˆใ‚ขใƒƒใƒ—๏ผˆๅฎŒๅ…จ็‰ˆ๏ผ‰\"\"\"\n",
558
+ " print(\"Setting up 2DGS environment...\")\n",
559
+ "\n",
560
+ " # ๅฟ…่ฆใชใƒ‘ใƒƒใ‚ฑใƒผใ‚ธใ‚’ใ™ในใฆใ‚คใƒณใ‚นใƒˆใƒผใƒซ\n",
561
+ " packages = [\n",
562
+ " 'plyfile',\n",
563
+ " 'mediapy',\n",
564
+ " 'open3d', # โ† ใ“ใ‚Œใ‚’่ฟฝๅŠ \n",
565
+ " ]\n",
566
+ "\n",
567
+ " for pkg in packages:\n",
568
+ " print(f\"Installing {pkg}...\")\n",
569
+ " subprocess.run(['pip', 'install', pkg], check=True)\n",
570
+ "\n",
571
+ " # 2DGSใƒชใƒใ‚ธใƒˆใƒชใฎใ‚ฏใƒญใƒผใƒณ\n",
572
+ " if not os.path.exists(WORK_DIR):\n",
573
+ " subprocess.run([\n",
574
+ " 'git', 'clone', '--recursive',\n",
575
+ " 'https://github.com/hbb1/2d-gaussian-splatting.git',\n",
576
+ " WORK_DIR\n",
577
+ " ], check=True)\n",
578
+ "\n",
579
+ " subprocess.run(['git', 'submodule', 'update', '--init', '--recursive'],\n",
580
+ " cwd=WORK_DIR, check=True)\n",
581
+ "\n",
582
+ " build_2dgs_submodules()\n",
583
+ "\n",
584
+ " print(\"โœ… 2DGS environment setup complete\")"
585
+ ],
586
+ "metadata": {
587
+ "id": "kXPLG7byqFlr"
588
+ },
589
+ "id": "kXPLG7byqFlr",
590
+ "execution_count": null,
591
+ "outputs": []
592
+ },
593
+ {
594
+ "cell_type": "code",
595
+ "source": [
596
+ "!pip install open3d"
597
+ ],
598
+ "metadata": {
599
+ "id": "55dtC6ByqJRY"
600
+ },
601
+ "id": "55dtC6ByqJRY",
602
+ "execution_count": null,
603
+ "outputs": []
604
+ },
605
+ {
606
+ "cell_type": "code",
607
+ "source": [
608
+ "\n",
609
+ "\n",
610
+ "\n",
611
+ "# ๅ†ๅบฆใƒฌใƒณใƒ€ใƒชใƒณใ‚ฐๅฎŸ่กŒ\n",
612
+ "import subprocess\n",
613
+ "result = subprocess.run(\n",
614
+ " ['/usr/bin/python3', 'render.py',\n",
615
+ " '-m', '/content/2d-gaussian-splatting/output/video',\n",
616
+ " '--iteration', '1000',\n",
617
+ " '--skip_test',\n",
618
+ " '--skip_train'],\n",
619
+ " cwd='/content/2d-gaussian-splatting',\n",
620
+ " capture_output=True,\n",
621
+ " text=True\n",
622
+ ")\n",
623
+ "\n",
624
+ "print(\"=== STDOUT ===\")\n",
625
+ "print(result.stdout)\n",
626
+ "print(\"\\n=== STDERR ===\")\n",
627
+ "print(result.stderr)\n",
628
+ "print(f\"\\n=== EXIT CODE: {result.returncode} ===\")"
629
+ ],
630
+ "metadata": {
631
+ "id": "vRxNgRnypv0l"
632
+ },
633
+ "id": "vRxNgRnypv0l",
634
+ "execution_count": null,
635
+ "outputs": []
636
+ },
637
+ {
638
+ "cell_type": "code",
639
+ "source": [],
640
+ "metadata": {
641
+ "id": "1W62vlfhe9TS"
642
+ },
643
+ "id": "1W62vlfhe9TS",
644
+ "execution_count": null,
645
+ "outputs": []
646
+ },
647
+ {
648
+ "cell_type": "code",
649
+ "source": [
650
+ "!nvcc --version\n",
651
+ "import torch\n",
652
+ "print(torch.__version__)\n",
653
+ "print(torch.version.cuda)"
654
+ ],
655
+ "metadata": {
656
+ "id": "Ev9PEUdtpEAx"
657
+ },
658
+ "id": "Ev9PEUdtpEAx",
659
+ "execution_count": null,
660
+ "outputs": []
661
+ },
662
+ {
663
+ "cell_type": "code",
664
+ "execution_count": null,
665
+ "id": "b8690389",
666
+ "metadata": {
667
+ "execution": {
668
+ "iopub.execute_input": "2026-01-10T18:22:43.739411Z",
669
+ "iopub.status.busy": "2026-01-10T18:22:43.738855Z",
670
+ "iopub.status.idle": "2026-01-10T18:22:43.755664Z",
671
+ "shell.execute_reply": "2026-01-10T18:22:43.754865Z"
672
+ },
673
+ "papermill": {
674
+ "duration": 0.027297,
675
+ "end_time": "2026-01-10T18:22:43.756758",
676
+ "exception": false,
677
+ "start_time": "2026-01-10T18:22:43.729461",
678
+ "status": "completed"
679
+ },
680
+ "tags": [],
681
+ "id": "b8690389"
682
+ },
683
+ "outputs": [],
684
+ "source": [
685
+ "import os\n",
686
+ "import glob\n",
687
+ "import cv2\n",
688
+ "import numpy as np\n",
689
+ "from PIL import Image\n",
690
+ "\n",
691
+ "# =========================================================\n",
692
+ "# Utility: aspect ratio preserved + black padding\n",
693
+ "# =========================================================\n",
694
+ "\n",
695
+ "def normalize_image_sizes_biplet(input_dir, output_dir=None, size=1024, max_images=None):\n",
696
+ " \"\"\"\n",
697
+ " Generates two square crops (Left & Right or Top & Bottom)\n",
698
+ " from each image in a directory and returns the output directory\n",
699
+ " and the list of generated file paths.\n",
700
+ "\n",
701
+ " Args:\n",
702
+ " input_dir: Input directory containing source images\n",
703
+ " output_dir: Output directory for processed images\n",
704
+ " size: Target square size (default: 1024)\n",
705
+ " max_images: Maximum number of SOURCE images to process (default: None = all images)\n",
706
+ " \"\"\"\n",
707
+ " if output_dir is None:\n",
708
+ " output_dir = 'output/images_biplet'\n",
709
+ " os.makedirs(output_dir, exist_ok=True)\n",
710
+ "\n",
711
+ " print(f\"--- Step 1: Biplet-Square Normalization ---\")\n",
712
+ " print(f\"Generating 2 cropped squares (Left/Right or Top/Bottom) for each image...\")\n",
713
+ " print()\n",
714
+ "\n",
715
+ " generated_paths = []\n",
716
+ " converted_count = 0\n",
717
+ " size_stats = {}\n",
718
+ "\n",
719
+ " # Sort for consistent processing order\n",
720
+ " image_files = sorted([f for f in os.listdir(input_dir)\n",
721
+ " if f.lower().endswith(('.jpg', '.jpeg', '.png'))])\n",
722
+ "\n",
723
+ " # โ˜… max_images ใงๅ…ƒ็”ปๅƒๆ•ฐใ‚’ๅˆถ้™\n",
724
+ " if max_images is not None:\n",
725
+ " image_files = image_files[:max_images]\n",
726
+ " print(f\"Processing limited to {max_images} source images (will generate {max_images * 2} cropped images)\")\n",
727
+ "\n",
728
+ " for img_file in image_files:\n",
729
+ " input_path = os.path.join(input_dir, img_file)\n",
730
+ " try:\n",
731
+ " img = Image.open(input_path)\n",
732
+ " original_size = img.size\n",
733
+ "\n",
734
+ " # Tracking original aspect ratios\n",
735
+ " size_key = f\"{original_size[0]}x{original_size[1]}\"\n",
736
+ " size_stats[size_key] = size_stats.get(size_key, 0) + 1\n",
737
+ "\n",
738
+ " # Generate 2 crops using the helper function\n",
739
+ " crops = generate_two_crops(img, size)\n",
740
+ " base_name, ext = os.path.splitext(img_file)\n",
741
+ "\n",
742
+ " for mode, cropped_img in crops.items():\n",
743
+ " output_path = os.path.join(output_dir, f\"{base_name}_{mode}{ext}\")\n",
744
+ " cropped_img.save(output_path, quality=95)\n",
745
+ " generated_paths.append(output_path)\n",
746
+ "\n",
747
+ " converted_count += 1\n",
748
+ " print(f\" โœ“ {img_file}: {original_size} โ†’ 2 square images generated\")\n",
749
+ "\n",
750
+ " except Exception as e:\n",
751
+ " print(f\" โœ— Error processing {img_file}: {e}\")\n",
752
+ "\n",
753
+ " print(f\"\\nProcessing complete: {converted_count} source images processed\")\n",
754
+ " print(f\"Total output images: {len(generated_paths)}\")\n",
755
+ " print(f\"Original size distribution: {size_stats}\")\n",
756
+ "\n",
757
+ " return output_dir, generated_paths\n",
758
+ "\n",
759
+ "\n",
760
+ "def generate_two_crops(img, size):\n",
761
+ " \"\"\"\n",
762
+ " Crops the image into a square and returns 2 variations\n",
763
+ " (Left/Right for landscape, Top/Bottom for portrait).\n",
764
+ " \"\"\"\n",
765
+ " width, height = img.size\n",
766
+ " crop_size = min(width, height)\n",
767
+ " crops = {}\n",
768
+ "\n",
769
+ " if width > height:\n",
770
+ " # Landscape โ†’ Left & Right\n",
771
+ " positions = {\n",
772
+ " 'left': 0,\n",
773
+ " 'right': width - crop_size\n",
774
+ " }\n",
775
+ " for mode, x_offset in positions.items():\n",
776
+ " box = (x_offset, 0, x_offset + crop_size, crop_size)\n",
777
+ " crops[mode] = img.crop(box).resize(\n",
778
+ " (size, size),\n",
779
+ " Image.Resampling.LANCZOS\n",
780
+ " )\n",
781
+ "\n",
782
+ " else:\n",
783
+ " # Portrait or Square โ†’ Top & Bottom\n",
784
+ " positions = {\n",
785
+ " 'top': 0,\n",
786
+ " 'bottom': height - crop_size\n",
787
+ " }\n",
788
+ " for mode, y_offset in positions.items():\n",
789
+ " box = (0, y_offset, crop_size, y_offset + crop_size)\n",
790
+ " crops[mode] = img.crop(box).resize(\n",
791
+ " (size, size),\n",
792
+ " Image.Resampling.LANCZOS\n",
793
+ " )\n",
794
+ "\n",
795
+ " return crops\n"
796
+ ]
797
+ },
798
+ {
799
+ "cell_type": "code",
800
+ "execution_count": null,
801
+ "id": "7acc20b6",
802
+ "metadata": {
803
+ "execution": {
804
+ "iopub.execute_input": "2026-01-10T18:22:43.772525Z",
805
+ "iopub.status.busy": "2026-01-10T18:22:43.772303Z",
806
+ "iopub.status.idle": "2026-01-10T18:22:43.790574Z",
807
+ "shell.execute_reply": "2026-01-10T18:22:43.789515Z"
808
+ },
809
+ "papermill": {
810
+ "duration": 0.027612,
811
+ "end_time": "2026-01-10T18:22:43.791681",
812
+ "exception": false,
813
+ "start_time": "2026-01-10T18:22:43.764069",
814
+ "status": "completed"
815
+ },
816
+ "tags": [],
817
+ "id": "7acc20b6"
818
+ },
819
+ "outputs": [],
820
+ "source": [
821
+ "def run_colmap_reconstruction(image_dir, colmap_dir):\n",
822
+ " \"\"\"Estimate camera poses and 3D point cloud with COLMAP\"\"\"\n",
823
+ " print(\"Running SfM reconstruction with COLMAP...\")\n",
824
+ "\n",
825
+ " database_path = os.path.join(colmap_dir, \"database.db\")\n",
826
+ " sparse_dir = os.path.join(colmap_dir, \"sparse\")\n",
827
+ " os.makedirs(sparse_dir, exist_ok=True)\n",
828
+ "\n",
829
+ " # Set environment variable\n",
830
+ " env = os.environ.copy()\n",
831
+ " env['QT_QPA_PLATFORM'] = 'offscreen'\n",
832
+ "\n",
833
+ " # Feature extraction\n",
834
+ " print(\"1/4: Extracting features...\")\n",
835
+ " subprocess.run([\n",
836
+ " 'colmap', 'feature_extractor',\n",
837
+ " '--database_path', database_path,\n",
838
+ " '--image_path', image_dir,\n",
839
+ " '--ImageReader.single_camera', '1',\n",
840
+ " '--ImageReader.camera_model', 'OPENCV',\n",
841
+ " '--SiftExtraction.use_gpu', '0' # Use CPU\n",
842
+ " ], check=True, env=env)\n",
843
+ "\n",
844
+ " # Feature matching\n",
845
+ " print(\"2/4: Matching features...\")\n",
846
+ " subprocess.run([\n",
847
+ " 'colmap', 'exhaustive_matcher', # Use sequential_matcher instead of exhaustive_matcher\n",
848
+ " '--database_path', database_path,\n",
849
+ " '--SiftMatching.use_gpu', '0' # Use CPU\n",
850
+ " ], check=True, env=env)\n",
851
+ "\n",
852
+ " # Sparse reconstruction\n",
853
+ " print(\"3/4: Sparse reconstruction...\")\n",
854
+ " subprocess.run([\n",
855
+ " 'colmap', 'mapper',\n",
856
+ " '--database_path', database_path,\n",
857
+ " '--image_path', image_dir,\n",
858
+ " '--output_path', sparse_dir,\n",
859
+ " '--Mapper.ba_global_max_num_iterations', '20', # Speed up\n",
860
+ " '--Mapper.ba_local_max_num_iterations', '10'\n",
861
+ " ], check=True, env=env)\n",
862
+ "\n",
863
+ " # Export to text format\n",
864
+ " print(\"4/4: Exporting to text format...\")\n",
865
+ " model_dir = os.path.join(sparse_dir, '0')\n",
866
+ " if not os.path.exists(model_dir):\n",
867
+ " # Use the first model found\n",
868
+ " subdirs = [d for d in os.listdir(sparse_dir) if os.path.isdir(os.path.join(sparse_dir, d))]\n",
869
+ " if subdirs:\n",
870
+ " model_dir = os.path.join(sparse_dir, subdirs[0])\n",
871
+ " else:\n",
872
+ " raise FileNotFoundError(\"COLMAP reconstruction failed\")\n",
873
+ "\n",
874
+ " subprocess.run([\n",
875
+ " 'colmap', 'model_converter',\n",
876
+ " '--input_path', model_dir,\n",
877
+ " '--output_path', model_dir,\n",
878
+ " '--output_type', 'TXT'\n",
879
+ " ], check=True, env=env)\n",
880
+ "\n",
881
+ " print(f\"COLMAP reconstruction complete: {model_dir}\")\n",
882
+ " return model_dir\n",
883
+ "\n",
884
+ "\n",
885
+ "def convert_cameras_to_pinhole(input_file, output_file):\n",
886
+ " \"\"\"Convert camera model to PINHOLE format\"\"\"\n",
887
+ " print(f\"Reading camera file: {input_file}\")\n",
888
+ "\n",
889
+ " with open(input_file, 'r') as f:\n",
890
+ " lines = f.readlines()\n",
891
+ "\n",
892
+ " converted_count = 0\n",
893
+ " with open(output_file, 'w') as f:\n",
894
+ " for line in lines:\n",
895
+ " if line.startswith('#') or line.strip() == '':\n",
896
+ " f.write(line)\n",
897
+ " else:\n",
898
+ " parts = line.strip().split()\n",
899
+ " if len(parts) >= 4:\n",
900
+ " cam_id = parts[0]\n",
901
+ " model = parts[1]\n",
902
+ " width = parts[2]\n",
903
+ " height = parts[3]\n",
904
+ " params = parts[4:]\n",
905
+ "\n",
906
+ " # Convert to PINHOLE format\n",
907
+ " if model == \"PINHOLE\":\n",
908
+ " f.write(line)\n",
909
+ " elif model == \"OPENCV\":\n",
910
+ " # OPENCV: fx, fy, cx, cy, k1, k2, p1, p2\n",
911
+ " fx = params[0]\n",
912
+ " fy = params[1]\n",
913
+ " cx = params[2]\n",
914
+ " cy = params[3]\n",
915
+ " f.write(f\"{cam_id} PINHOLE {width} {height} {fx} {fy} {cx} {cy}\\n\")\n",
916
+ " converted_count += 1\n",
917
+ " else:\n",
918
+ " # Convert other models too\n",
919
+ " fx = fy = max(float(width), float(height))\n",
920
+ " cx = float(width) / 2\n",
921
+ " cy = float(height) / 2\n",
922
+ " f.write(f\"{cam_id} PINHOLE {width} {height} {fx} {fy} {cx} {cy}\\n\")\n",
923
+ " converted_count += 1\n",
924
+ " else:\n",
925
+ " f.write(line)\n",
926
+ "\n",
927
+ " print(f\"Converted {converted_count} cameras to PINHOLE format\")\n",
928
+ "\n",
929
+ "\n",
930
+ "def prepare_gaussian_splatting_data(image_dir, colmap_model_dir):\n",
931
+ " \"\"\"Prepare data for Gaussian Splatting\"\"\"\n",
932
+ " print(\"Preparing data for Gaussian Splatting...\")\n",
933
+ "\n",
934
+ " data_dir = f\"{WORK_DIR}/data/video\"\n",
935
+ " os.makedirs(f\"{data_dir}/sparse/0\", exist_ok=True)\n",
936
+ " os.makedirs(f\"{data_dir}/images\", exist_ok=True)\n",
937
+ "\n",
938
+ " # Copy images\n",
939
+ " print(\"Copying images...\")\n",
940
+ " img_count = 0\n",
941
+ " for img_file in os.listdir(image_dir):\n",
942
+ " if img_file.lower().endswith(('.jpg', '.jpeg', '.png')):\n",
943
+ " shutil.copy(\n",
944
+ " os.path.join(image_dir, img_file),\n",
945
+ " f\"{data_dir}/images/{img_file}\"\n",
946
+ " )\n",
947
+ " img_count += 1\n",
948
+ " print(f\"Copied {img_count} images\")\n",
949
+ "\n",
950
+ " # Convert and copy camera file to PINHOLE format\n",
951
+ " print(\"Converting camera model to PINHOLE format...\")\n",
952
+ " convert_cameras_to_pinhole(\n",
953
+ " os.path.join(colmap_model_dir, 'cameras.txt'),\n",
954
+ " f\"{data_dir}/sparse/0/cameras.txt\"\n",
955
+ " )\n",
956
+ "\n",
957
+ " # Copy other files\n",
958
+ " for filename in ['images.txt', 'points3D.txt']:\n",
959
+ " src = os.path.join(colmap_model_dir, filename)\n",
960
+ " dst = f\"{data_dir}/sparse/0/{filename}\"\n",
961
+ " if os.path.exists(src):\n",
962
+ " shutil.copy(src, dst)\n",
963
+ " print(f\"Copied {filename}\")\n",
964
+ " else:\n",
965
+ " print(f\"Warning: {filename} not found\")\n",
966
+ "\n",
967
+ " print(f\"Data preparation complete: {data_dir}\")\n",
968
+ " return data_dir\n",
969
+ "\n",
970
+ "def run_colmap_reconstruction(image_dir, colmap_dir):\n",
971
+ " \"\"\"Estimate camera poses and 3D point cloud with COLMAP\"\"\"\n",
972
+ " print(\"Running SfM reconstruction with COLMAP...\")\n",
973
+ "\n",
974
+ " database_path = os.path.join(colmap_dir, \"database.db\")\n",
975
+ " sparse_dir = os.path.join(colmap_dir, \"sparse\")\n",
976
+ " os.makedirs(sparse_dir, exist_ok=True)\n",
977
+ "\n",
978
+ " # Set environment variable\n",
979
+ " env = os.environ.copy()\n",
980
+ " env['QT_QPA_PLATFORM'] = 'offscreen'\n",
981
+ "\n",
982
+ " # Feature extraction\n",
983
+ " print(\"1/4: Extracting features...\")\n",
984
+ " subprocess.run([\n",
985
+ " 'colmap', 'feature_extractor',\n",
986
+ " '--database_path', database_path,\n",
987
+ " '--image_path', image_dir,\n",
988
+ " '--ImageReader.single_camera', '1',\n",
989
+ " '--ImageReader.camera_model', 'OPENCV',\n",
990
+ " '--SiftExtraction.use_gpu', '0' # Use CPU\n",
991
+ " ], check=True, env=env)\n",
992
+ "\n",
993
+ " # Feature matching\n",
994
+ " print(\"2/4: Matching features...\")\n",
995
+ " subprocess.run([\n",
996
+ " 'colmap', 'exhaustive_matcher', # Use sequential_matcher instead of exhaustive_matcher\n",
997
+ " '--database_path', database_path,\n",
998
+ " '--SiftMatching.use_gpu', '0' # Use CPU\n",
999
+ " ], check=True, env=env)\n",
1000
+ "\n",
1001
+ " # Sparse reconstruction\n",
1002
+ " print(\"3/4: Sparse reconstruction...\")\n",
1003
+ " subprocess.run([\n",
1004
+ " 'colmap', 'mapper',\n",
1005
+ " '--database_path', database_path,\n",
1006
+ " '--image_path', image_dir,\n",
1007
+ " '--output_path', sparse_dir,\n",
1008
+ " '--Mapper.ba_global_max_num_iterations', '20', # Speed up\n",
1009
+ " '--Mapper.ba_local_max_num_iterations', '10'\n",
1010
+ " ], check=True, env=env)\n",
1011
+ "\n",
1012
+ " # Export to text format\n",
1013
+ " print(\"4/4: Exporting to text format...\")\n",
1014
+ " model_dir = os.path.join(sparse_dir, '0')\n",
1015
+ " if not os.path.exists(model_dir):\n",
1016
+ " # Use the first model found\n",
1017
+ " subdirs = [d for d in os.listdir(sparse_dir) if os.path.isdir(os.path.join(sparse_dir, d))]\n",
1018
+ " if subdirs:\n",
1019
+ " model_dir = os.path.join(sparse_dir, subdirs[0])\n",
1020
+ " else:\n",
1021
+ " raise FileNotFoundError(\"COLMAP reconstruction failed\")\n",
1022
+ "\n",
1023
+ " subprocess.run([\n",
1024
+ " 'colmap', 'model_converter',\n",
1025
+ " '--input_path', model_dir,\n",
1026
+ " '--output_path', model_dir,\n",
1027
+ " '--output_type', 'TXT'\n",
1028
+ " ], check=True, env=env)\n",
1029
+ "\n",
1030
+ " print(f\"COLMAP reconstruction complete: {model_dir}\")\n",
1031
+ " return model_dir\n",
1032
+ "\n",
1033
+ "\n",
1034
+ "def convert_cameras_to_pinhole(input_file, output_file):\n",
1035
+ " \"\"\"Convert camera model to PINHOLE format\"\"\"\n",
1036
+ " print(f\"Reading camera file: {input_file}\")\n",
1037
+ "\n",
1038
+ " with open(input_file, 'r') as f:\n",
1039
+ " lines = f.readlines()\n",
1040
+ "\n",
1041
+ " converted_count = 0\n",
1042
+ " with open(output_file, 'w') as f:\n",
1043
+ " for line in lines:\n",
1044
+ " if line.startswith('#') or line.strip() == '':\n",
1045
+ " f.write(line)\n",
1046
+ " else:\n",
1047
+ " parts = line.strip().split()\n",
1048
+ " if len(parts) >= 4:\n",
1049
+ " cam_id = parts[0]\n",
1050
+ " model = parts[1]\n",
1051
+ " width = parts[2]\n",
1052
+ " height = parts[3]\n",
1053
+ " params = parts[4:]\n",
1054
+ "\n",
1055
+ " # Convert to PINHOLE format\n",
1056
+ " if model == \"PINHOLE\":\n",
1057
+ " f.write(line)\n",
1058
+ " elif model == \"OPENCV\":\n",
1059
+ " # OPENCV: fx, fy, cx, cy, k1, k2, p1, p2\n",
1060
+ " fx = params[0]\n",
1061
+ " fy = params[1]\n",
1062
+ " cx = params[2]\n",
1063
+ " cy = params[3]\n",
1064
+ " f.write(f\"{cam_id} PINHOLE {width} {height} {fx} {fy} {cx} {cy}\\n\")\n",
1065
+ " converted_count += 1\n",
1066
+ " else:\n",
1067
+ " # Convert other models too\n",
1068
+ " fx = fy = max(float(width), float(height))\n",
1069
+ " cx = float(width) / 2\n",
1070
+ " cy = float(height) / 2\n",
1071
+ " f.write(f\"{cam_id} PINHOLE {width} {height} {fx} {fy} {cx} {cy}\\n\")\n",
1072
+ " converted_count += 1\n",
1073
+ " else:\n",
1074
+ " f.write(line)\n",
1075
+ "\n",
1076
+ " print(f\"Converted {converted_count} cameras to PINHOLE format\")\n",
1077
+ "\n",
1078
+ "\n",
1079
+ "def prepare_gaussian_splatting_data(image_dir, colmap_model_dir):\n",
1080
+ " \"\"\"Prepare data for Gaussian Splatting\"\"\"\n",
1081
+ " print(\"Preparing data for Gaussian Splatting...\")\n",
1082
+ "\n",
1083
+ " data_dir = f\"{WORK_DIR}/data/video\"\n",
1084
+ " os.makedirs(f\"{data_dir}/sparse/0\", exist_ok=True)\n",
1085
+ " os.makedirs(f\"{data_dir}/images\", exist_ok=True)\n",
1086
+ "\n",
1087
+ " # Copy images\n",
1088
+ " print(\"Copying images...\")\n",
1089
+ " img_count = 0\n",
1090
+ " for img_file in os.listdir(image_dir):\n",
1091
+ " if img_file.lower().endswith(('.jpg', '.jpeg', '.png')):\n",
1092
+ " shutil.copy(\n",
1093
+ " os.path.join(image_dir, img_file),\n",
1094
+ " f\"{data_dir}/images/{img_file}\"\n",
1095
+ " )\n",
1096
+ " img_count += 1\n",
1097
+ " print(f\"Copied {img_count} images\")\n",
1098
+ "\n",
1099
+ " # Convert and copy camera file to PINHOLE format\n",
1100
+ " print(\"Converting camera model to PINHOLE format...\")\n",
1101
+ " convert_cameras_to_pinhole(\n",
1102
+ " os.path.join(colmap_model_dir, 'cameras.txt'),\n",
1103
+ " f\"{data_dir}/sparse/0/cameras.txt\"\n",
1104
+ " )\n",
1105
+ "\n",
1106
+ " # Copy other files\n",
1107
+ " for filename in ['images.txt', 'points3D.txt']:\n",
1108
+ " src = os.path.join(colmap_model_dir, filename)\n",
1109
+ " dst = f\"{data_dir}/sparse/0/{filename}\"\n",
1110
+ " if os.path.exists(src):\n",
1111
+ " shutil.copy(src, dst)\n",
1112
+ " print(f\"Copied {filename}\")\n",
1113
+ " else:\n",
1114
+ " print(f\"Warning: {filename} not found\")\n",
1115
+ "\n",
1116
+ " print(f\"Data preparation complete: {data_dir}\")\n",
1117
+ " return data_dir\n",
1118
+ "\n",
1119
+ "\n",
1120
+ "\n",
1121
+ "###############################################################\n",
1122
+ "\n",
1123
+ "# ๅค‰ๆ›ดๅพŒ (2DGS) - ๆญฃๅ‰‡ๅŒ–ใƒ‘ใƒฉใƒกใƒผใ‚ฟใ‚’่ฟฝๅŠ \n",
1124
+ "def train_gaussian_splatting(data_dir, iterations=7000,\n",
1125
+ " lambda_normal=0.05,\n",
1126
+ " lambda_dist=0, # โ† distortion โ†’ dist ใซไฟฎๆญฃ\n",
1127
+ " depth_ratio=0):\n",
1128
+ " \"\"\"\n",
1129
+ " 2DGS็”จใฎใƒˆใƒฌใƒผใƒ‹ใƒณใ‚ฐ้–ขๆ•ฐ\n",
1130
+ " Args:\n",
1131
+ " lambda_normal: ๆณ•็ทšไธ€่ฒซๆ€งใฎ้‡ใฟ (ใƒ‡ใƒ•ใ‚ฉใƒซใƒˆ: 0.05)\n",
1132
+ " lambda_dist: ๆทฑๅบฆๆญชใฟใฎ้‡ใฟ (ใƒ‡ใƒ•ใ‚ฉใƒซใƒˆ: 0) # โ† ๅๅ‰ไฟฎๆญฃ\n",
1133
+ " depth_ratio: 0=ๅนณๅ‡ๆทฑๅบฆ, 1=ไธญๅคฎๅ€คๆทฑๅบฆ (ใƒ‡ใƒ•ใ‚ฉใƒซใƒˆ: 0)\n",
1134
+ " \"\"\"\n",
1135
+ " model_path = f\"{WORK_DIR}/output/video\"\n",
1136
+ " cmd = [\n",
1137
+ " sys.executable, 'train.py',\n",
1138
+ " '-s', data_dir,\n",
1139
+ " '-m', model_path,\n",
1140
+ " '--iterations', str(iterations),\n",
1141
+ " '--lambda_normal', str(lambda_normal),\n",
1142
+ " '--lambda_dist', str(lambda_dist), # โ† ใ“ใ“ใ‚’ไฟฎๆญฃ๏ผ\n",
1143
+ " '--depth_ratio', str(depth_ratio),\n",
1144
+ " '--eval'\n",
1145
+ " ]\n",
1146
+ " subprocess.run(cmd, cwd=WORK_DIR, check=True)\n",
1147
+ " return model_path\n",
1148
+ "\n",
1149
+ "\n",
1150
+ "\n",
1151
+ "# 2DGSใงใฏใƒกใƒƒใ‚ทใƒฅๆŠฝๅ‡บใ‚ชใƒ—ใ‚ทใƒงใƒณใŒ่ฟฝๅŠ ใ•ใ‚Œใฆใ„ใพใ™\n",
1152
+ "def render_video_and_mesh(model_path, output_video_path, iteration=1000,\n",
1153
+ " extract_mesh=False, unbounded=False, mesh_res=1024):\n",
1154
+ " \"\"\"\n",
1155
+ " 2DGS็”จใฎใƒฌใƒณใƒ€ใƒชใƒณใ‚ฐใจใƒกใƒƒใ‚ทใƒฅๆŠฝๅ‡บ\n",
1156
+ " Args:\n",
1157
+ " extract_mesh: ใƒกใƒƒใ‚ทใƒฅใ‚’ๆŠฝๅ‡บใ™ใ‚‹ใ‹ (ใƒ‡ใƒ•ใ‚ฉใƒซใƒˆ: Falseใ€ๅ‹•็”ปใฎใฟ)\n",
1158
+ " unbounded: ๅขƒ็•Œใชใ—ใƒกใƒƒใ‚ทใƒฅๆŠฝๅ‡บใ‚’ไฝฟ็”จใ™ใ‚‹ใ‹\n",
1159
+ " mesh_res: ใƒกใƒƒใ‚ทใƒฅ่งฃๅƒๅบฆ\n",
1160
+ " \"\"\"\n",
1161
+ " # ้€šๅธธใฎใƒฌใƒณใƒ€ใƒชใƒณใ‚ฐ\n",
1162
+ " cmd = [\n",
1163
+ " sys.executable, 'render.py',\n",
1164
+ " '-m', model_path,\n",
1165
+ " '--iteration', str(iteration),\n",
1166
+ " '--skip_test',\n",
1167
+ " '--skip_train'\n",
1168
+ " ]\n",
1169
+ "\n",
1170
+ " # ใƒกใƒƒใ‚ทใƒฅๆŠฝๅ‡บใ‚ชใƒ—ใ‚ทใƒงใƒณ๏ผˆๅฟ…่ฆ๏ฟฝ๏ฟฝ๏ฟฝๅ ดๅˆใฎใฟ๏ผ‰\n",
1171
+ " if extract_mesh:\n",
1172
+ " if unbounded:\n",
1173
+ " cmd.extend(['--unbounded'])\n",
1174
+ " cmd.extend(['--mesh_res', str(mesh_res)])\n",
1175
+ "\n",
1176
+ " # ใ‚จใƒฉใƒผ่ฉณ็ดฐใ‚’ใ‚ญใƒฃใƒ—ใƒใƒฃ\n",
1177
+ " result = subprocess.run(\n",
1178
+ " cmd,\n",
1179
+ " cwd=WORK_DIR,\n",
1180
+ " capture_output=True,\n",
1181
+ " text=True\n",
1182
+ " )\n",
1183
+ "\n",
1184
+ " if result.returncode != 0:\n",
1185
+ " print(\"โŒ STDOUT:\", result.stdout)\n",
1186
+ " print(\"โŒ STDERR:\", result.stderr)\n",
1187
+ " raise subprocess.CalledProcessError(\n",
1188
+ " result.returncode, cmd, result.stdout, result.stderr\n",
1189
+ " )\n",
1190
+ "\n",
1191
+ " # ใƒฌใƒณใƒ€ใƒชใƒณใ‚ฐ็ตๆžœใ‹ใ‚‰ใƒ“ใƒ‡ใ‚ชไฝœๆˆ\n",
1192
+ " possible_dirs = [\n",
1193
+ " f\"{model_path}/test/ours_{iteration}/renders\",\n",
1194
+ " f\"{model_path}/train/ours_{iteration}/renders\",\n",
1195
+ " ]\n",
1196
+ "\n",
1197
+ " render_dir = None\n",
1198
+ " for test_dir in possible_dirs:\n",
1199
+ " if os.path.exists(test_dir):\n",
1200
+ " render_dir = test_dir\n",
1201
+ " print(f\"โœ… Rendering directory found: {render_dir}\")\n",
1202
+ " break\n",
1203
+ "\n",
1204
+ " if render_dir and os.path.exists(render_dir):\n",
1205
+ " render_imgs = sorted([f for f in os.listdir(render_dir)\n",
1206
+ " if f.endswith('.png')])\n",
1207
+ " if render_imgs:\n",
1208
+ " print(f\"Found {len(render_imgs)} rendered images\")\n",
1209
+ " # ffmpegใงใƒ“ใƒ‡ใ‚ชไฝœๆˆ\n",
1210
+ " subprocess.run([\n",
1211
+ " 'ffmpeg', '-y',\n",
1212
+ " '-framerate', '30',\n",
1213
+ " '-pattern_type', 'glob',\n",
1214
+ " '-i', f\"{render_dir}/*.png\",\n",
1215
+ " '-c:v', 'libx264',\n",
1216
+ " '-pix_fmt', 'yuv420p',\n",
1217
+ " '-crf', '18',\n",
1218
+ " output_video_path\n",
1219
+ " ], check=True)\n",
1220
+ " print(f\"โœ… Video saved: {output_video_path}\")\n",
1221
+ " return True\n",
1222
+ "\n",
1223
+ " print(\"โŒ Error: Rendering directory not found\")\n",
1224
+ " return False\n",
1225
+ "\n",
1226
+ "\n",
1227
+ "\n",
1228
+ "###############################################################\n",
1229
+ "\n",
1230
+ "\n",
1231
+ "def create_gif(video_path, gif_path):\n",
1232
+ " \"\"\"Create GIF from MP4\"\"\"\n",
1233
+ " print(\"Creating animated GIF...\")\n",
1234
+ "\n",
1235
+ " subprocess.run([\n",
1236
+ " 'ffmpeg', '-y',\n",
1237
+ " '-i', video_path,\n",
1238
+ " '-vf', 'setpts=8*PTS,fps=10,scale=720:-1:flags=lanczos',\n",
1239
+ " '-loop', '0',\n",
1240
+ " gif_path\n",
1241
+ " ], check=True)\n",
1242
+ "\n",
1243
+ " if os.path.exists(gif_path):\n",
1244
+ " size_mb = os.path.getsize(gif_path) / (1024 * 1024)\n",
1245
+ " print(f\"GIF creation complete: {gif_path} ({size_mb:.2f} MB)\")\n",
1246
+ " return True\n",
1247
+ "\n",
1248
+ " return False"
1249
+ ]
1250
+ },
1251
+ {
1252
+ "cell_type": "code",
1253
+ "source": [],
1254
+ "metadata": {
1255
+ "id": "YtqhBP4T3jEH"
1256
+ },
1257
+ "id": "YtqhBP4T3jEH",
1258
+ "execution_count": null,
1259
+ "outputs": []
1260
+ },
1261
+ {
1262
+ "cell_type": "code",
1263
+ "source": [
1264
+ "def main_pipeline(image_dir, output_dir, square_size=1024, max_images=100):\n",
1265
+ " \"\"\"Main execution function\"\"\"\n",
1266
+ " try:\n",
1267
+ " # Step 1: ็”ปๅƒใฎๆญฃ่ฆๅŒ–ใจๅ‰ๅ‡ฆ็†\n",
1268
+ " print(\"=\"*60)\n",
1269
+ " print(\"Step 1: Normalizing and preprocessing images\")\n",
1270
+ " print(\"=\"*60)\n",
1271
+ "\n",
1272
+ " frame_dir = os.path.join(COLMAP_DIR, \"images\")\n",
1273
+ " os.makedirs(frame_dir, exist_ok=True)\n",
1274
+ "\n",
1275
+ " # ็”ปๅƒใ‚’ๆญฃ่ฆๅŒ–ใ—ใฆ็›ดๆŽฅCOLMAPใฎใƒ‡ใ‚ฃใƒฌใ‚ฏใƒˆใƒชใซไฟๅญ˜\n",
1276
+ " num_processed = normalize_image_sizes_biplet(\n",
1277
+ " input_dir=image_dir,\n",
1278
+ " output_dir=frame_dir, # ็›ดๆŽฅcolmap/imagesใซไฟๅญ˜\n",
1279
+ " size=square_size,\n",
1280
+ " max_images=max_images\n",
1281
+ " )\n",
1282
+ "\n",
1283
+ " print(f\"Processed {num_processed} images\")\n",
1284
+ "\n",
1285
+ " # Step 2: Estimate Camera Info with COLMAP\n",
1286
+ " print(\"=\"*60)\n",
1287
+ " print(\"Step 2: Running COLMAP reconstruction\")\n",
1288
+ " print(\"=\"*60)\n",
1289
+ " colmap_model_dir = run_colmap_reconstruction(frame_dir, COLMAP_DIR)\n",
1290
+ "\n",
1291
+ " # Step 3: Prepare Data for Gaussian Splatting\n",
1292
+ " print(\"=\"*60)\n",
1293
+ " print(\"Step 3: Preparing Gaussian Splatting data\")\n",
1294
+ " print(\"=\"*60)\n",
1295
+ " data_dir = prepare_gaussian_splatting_data(frame_dir, colmap_model_dir)\n",
1296
+ "\n",
1297
+ " # Step 4: Train Model\n",
1298
+ " print(\"=\"*60)\n",
1299
+ " print(\"Step 4: Training Gaussian Splatting model\")\n",
1300
+ " print(\"=\"*60)\n",
1301
+ " # ไฟฎๆญฃ: frame_dir โ†’ data_dir\n",
1302
+ "\n",
1303
+ " # main_pipelineๅ†…ใงๅ‘ผใณๅ‡บใ™้ƒจๅˆ†\n",
1304
+ " model_path = train_gaussian_splatting(\n",
1305
+ " data_dir,\n",
1306
+ " iterations=1000,\n",
1307
+ " lambda_normal=0.05,\n",
1308
+ " lambda_dist=0, # โ† distortion โ†’ dist ใซไฟฎๆญฃ\n",
1309
+ " depth_ratio=0\n",
1310
+ " )\n",
1311
+ "\n",
1312
+ " print(f\"Model trained at: {model_path}\")\n",
1313
+ "\n",
1314
+ " # Step 5: Render Video\n",
1315
+ " print(\"=\"*60)\n",
1316
+ " print(\"Step 5: Rendering video\")\n",
1317
+ " print(\"=\"*60)\n",
1318
+ " os.makedirs(OUTPUT_DIR, exist_ok=True)\n",
1319
+ " output_video_path = os.path.join(OUTPUT_DIR, \"gaussian_splatting_video.mp4\")\n",
1320
+ "\n",
1321
+ "\n",
1322
+ "\n",
1323
+ " # ไฟฎๆญฃ: output_video_path โ†’ output_video\n",
1324
+ " success = render_video_and_mesh(\n",
1325
+ " model_path,\n",
1326
+ " output_video_path,\n",
1327
+ " iteration=1000,\n",
1328
+ " extract_mesh=False, # ใพใšใฏๅ‹•็”ปใฎใฟใ€ใƒกใƒƒใ‚ทใƒฅใฏๅพŒใง\n",
1329
+ " unbounded=False,\n",
1330
+ " mesh_res=1024\n",
1331
+ " )\n",
1332
+ "\n",
1333
+ "\n",
1334
+ " if success:\n",
1335
+ " print(\"=\"*60)\n",
1336
+ " print(f\"Success! Video generation complete: {output_video}\")\n",
1337
+ " print(\"=\"*60)\n",
1338
+ "\n",
1339
+ " # Create GIF\n",
1340
+ " output_gif = os.path.join(OUTPUT_DIR, \"gaussian_splatting_video.gif\")\n",
1341
+ " create_gif(output_video, output_gif)\n",
1342
+ "\n",
1343
+ " # Display result\n",
1344
+ " from IPython.display import Image, display\n",
1345
+ " display(Image(open(output_gif, 'rb').read()))\n",
1346
+ "\n",
1347
+ " return output_video, output_gif\n",
1348
+ " else:\n",
1349
+ " print(\"Warning: Rendering complete, but video was not generated\")\n",
1350
+ " return None, None\n",
1351
+ "\n",
1352
+ " except Exception as e:\n",
1353
+ " print(f\"Error: {str(e)}\")\n",
1354
+ " import traceback\n",
1355
+ " traceback.print_exc()\n",
1356
+ " return None, None\n",
1357
+ "\n",
1358
+ "\n",
1359
+ "if __name__ == \"__main__\":\n",
1360
+ " IMAGE_DIR = \"/content/drive/MyDrive/your_folder/fountain100\"\n",
1361
+ " OUTPUT_DIR = \"/content/output\"\n",
1362
+ " COLMAP_DIR = \"/content/colmap_workspace\"\n",
1363
+ "\n",
1364
+ " video_path, gif_path = main_pipeline(\n",
1365
+ " image_dir=IMAGE_DIR,\n",
1366
+ " output_dir=OUTPUT_DIR,\n",
1367
+ " square_size=1024,\n",
1368
+ " max_images=20\n",
1369
+ " )\n",
1370
+ "\n",
1371
+ " if video_path:\n",
1372
+ " print(f\"\\nโœ… Success!\")\n",
1373
+ " print(f\"Video: {video_path}\")\n",
1374
+ " print(f\"GIF: {gif_path}\")\n",
1375
+ " else:\n",
1376
+ " print(\"\\nโŒ Pipeline failed\")"
1377
+ ],
1378
+ "metadata": {
1379
+ "id": "fya3kv62NXM-"
1380
+ },
1381
+ "id": "fya3kv62NXM-",
1382
+ "execution_count": null,
1383
+ "outputs": []
1384
+ },
1385
+ {
1386
+ "cell_type": "code",
1387
+ "source": [],
1388
+ "metadata": {
1389
+ "id": "9GN6Eny2XsAd"
1390
+ },
1391
+ "id": "9GN6Eny2XsAd",
1392
+ "execution_count": null,
1393
+ "outputs": []
1394
+ },
1395
+ {
1396
+ "cell_type": "code",
1397
+ "source": [
1398
+ "# 1. ใƒˆใƒฌใƒผใƒ‹ใƒณใ‚ฐ็ตๆžœใฎ็ขบ่ช\n",
1399
+ "!ls -lh /content/2d-gaussian-splatting/output/video/point_cloud/\n",
1400
+ "!ls -lh /content/2d-gaussian-splatting/output/video/point_cloud/iteration_1000/\n",
1401
+ "\n",
1402
+ "# 2. COLMAPใƒ‡ใƒผใ‚ฟใฎ็ขบ่ช\n",
1403
+ "!wc -l /content/2d-gaussian-splatting/data/video/sparse/0/points3D.txt\n",
1404
+ "!wc -l /content/2d-gaussian-splatting/data/video/sparse/0/images.txt\n",
1405
+ "\n",
1406
+ "# 3. ใƒฌใƒณใƒ€ใƒชใƒณใ‚ฐใ‚’่ฉณ็ดฐใƒขใƒผใƒ‰ใงๅฎŸ่กŒ\n",
1407
+ "import subprocess\n",
1408
+ "result = subprocess.run(\n",
1409
+ " ['/usr/bin/python3', 'render.py',\n",
1410
+ " '-m', '/content/2d-gaussian-splatting/output/video',\n",
1411
+ " '--iteration', '1000',\n",
1412
+ " '--skip_test',\n",
1413
+ " '--skip_train'],\n",
1414
+ " cwd='/content/2d-gaussian-splatting',\n",
1415
+ " capture_output=True,\n",
1416
+ " text=True\n",
1417
+ ")\n",
1418
+ "print(\"=== STDOUT ===\")\n",
1419
+ "print(result.stdout)\n",
1420
+ "print(\"\\n=== STDERR ===\")\n",
1421
+ "print(result.stderr)\n",
1422
+ "print(f\"\\n=== EXIT CODE: {result.returncode} ===\")"
1423
+ ],
1424
+ "metadata": {
1425
+ "id": "_CgMfCqOoBKI"
1426
+ },
1427
+ "id": "_CgMfCqOoBKI",
1428
+ "execution_count": null,
1429
+ "outputs": []
1430
+ },
1431
+ {
1432
+ "cell_type": "markdown",
1433
+ "id": "e17ec719",
1434
+ "metadata": {
1435
+ "papermill": {
1436
+ "duration": 0.49801,
1437
+ "end_time": "2026-01-11T00:00:18.165833",
1438
+ "exception": false,
1439
+ "start_time": "2026-01-11T00:00:17.667823",
1440
+ "status": "completed"
1441
+ },
1442
+ "tags": [],
1443
+ "id": "e17ec719"
1444
+ },
1445
+ "source": []
1446
+ },
1447
+ {
1448
+ "cell_type": "markdown",
1449
+ "id": "38b3974c",
1450
+ "metadata": {
1451
+ "papermill": {
1452
+ "duration": 0.427583,
1453
+ "end_time": "2026-01-11T00:00:19.008387",
1454
+ "exception": false,
1455
+ "start_time": "2026-01-11T00:00:18.580804",
1456
+ "status": "completed"
1457
+ },
1458
+ "tags": [],
1459
+ "id": "38b3974c"
1460
+ },
1461
+ "source": []
1462
+ }
1463
+ ],
1464
+ "metadata": {
1465
+ "kaggle": {
1466
+ "accelerator": "nvidiaTeslaT4",
1467
+ "dataSources": [
1468
+ {
1469
+ "databundleVersionId": 5447706,
1470
+ "sourceId": 49349,
1471
+ "sourceType": "competition"
1472
+ },
1473
+ {
1474
+ "datasetId": 1429416,
1475
+ "sourceId": 14451718,
1476
+ "sourceType": "datasetVersion"
1477
+ }
1478
+ ],
1479
+ "dockerImageVersionId": 31090,
1480
+ "isGpuEnabled": true,
1481
+ "isInternetEnabled": true,
1482
+ "language": "python",
1483
+ "sourceType": "notebook"
1484
+ },
1485
+ "kernelspec": {
1486
+ "display_name": "Python 3",
1487
+ "name": "python3"
1488
+ },
1489
+ "language_info": {
1490
+ "codemirror_mode": {
1491
+ "name": "ipython",
1492
+ "version": 3
1493
+ },
1494
+ "file_extension": ".py",
1495
+ "mimetype": "text/x-python",
1496
+ "name": "python",
1497
+ "nbconvert_exporter": "python",
1498
+ "pygments_lexer": "ipython3",
1499
+ "version": "3.11.13"
1500
+ },
1501
+ "papermill": {
1502
+ "default_parameters": {},
1503
+ "duration": 20573.990788,
1504
+ "end_time": "2026-01-11T00:00:22.081506",
1505
+ "environment_variables": {},
1506
+ "exception": null,
1507
+ "input_path": "__notebook__.ipynb",
1508
+ "output_path": "__notebook__.ipynb",
1509
+ "parameters": {},
1510
+ "start_time": "2026-01-10T18:17:28.090718",
1511
+ "version": "2.6.0"
1512
+ },
1513
+ "colab": {
1514
+ "provenance": [],
1515
+ "gpuType": "T4"
1516
+ },
1517
+ "accelerator": "GPU"
1518
+ },
1519
+ "nbformat": 4,
1520
+ "nbformat_minor": 5
1521
+ }
biplet_colmap_2dgs_colab_10oo.ipynb ADDED
@@ -0,0 +1,1756 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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": "markdown",
23
+ "source": [
24
+ "# ๆ–ฐใ—ใ„ใ‚ปใ‚ฏใ‚ทใƒงใƒณ"
25
+ ],
26
+ "metadata": {
27
+ "id": "jK0ja9PfddVA"
28
+ },
29
+ "id": "jK0ja9PfddVA"
30
+ },
31
+ {
32
+ "cell_type": "code",
33
+ "source": [
34
+ "#ใ‚ตใ‚คใ‚บใฎ็•ฐใชใ‚‹็”ปๅƒใ‚’ๆ‰ฑใ†\n",
35
+ "from google.colab import drive\n",
36
+ "drive.mount('/content/drive')"
37
+ ],
38
+ "metadata": {
39
+ "colab": {
40
+ "base_uri": "https://localhost:8080/"
41
+ },
42
+ "id": "JON4rYSEOzCg",
43
+ "outputId": "458cec38-282c-48a0-a836-832559e5acf1"
44
+ },
45
+ "id": "JON4rYSEOzCg",
46
+ "execution_count": 32,
47
+ "outputs": [
48
+ {
49
+ "output_type": "stream",
50
+ "name": "stdout",
51
+ "text": [
52
+ "Drive already mounted at /content/drive; to attempt to forcibly remount, call drive.mount(\"/content/drive\", force_remount=True).\n"
53
+ ]
54
+ }
55
+ ]
56
+ },
57
+ {
58
+ "cell_type": "code",
59
+ "execution_count": 33,
60
+ "id": "22353010",
61
+ "metadata": {
62
+ "execution": {
63
+ "iopub.execute_input": "2026-01-10T18:17:32.181455Z",
64
+ "iopub.status.busy": "2026-01-10T18:17:32.180969Z",
65
+ "iopub.status.idle": "2026-01-10T18:17:32.355942Z",
66
+ "shell.execute_reply": "2026-01-10T18:17:32.355229Z"
67
+ },
68
+ "papermill": {
69
+ "duration": 0.179454,
70
+ "end_time": "2026-01-10T18:17:32.357275",
71
+ "exception": false,
72
+ "start_time": "2026-01-10T18:17:32.177821",
73
+ "status": "completed"
74
+ },
75
+ "tags": [],
76
+ "id": "22353010"
77
+ },
78
+ "outputs": [],
79
+ "source": [
80
+ "import os\n",
81
+ "import sys\n",
82
+ "import subprocess\n",
83
+ "import shutil\n",
84
+ "from pathlib import Path\n",
85
+ "import cv2\n",
86
+ "from PIL import Image\n",
87
+ "import glob\n",
88
+ "\n",
89
+ "IMAGE_PATH=\"/content/drive/MyDrive/your_folder/fountain100\"\n",
90
+ "\n",
91
+ "#WORK_DIR = '/content/gaussian-splatting'\n",
92
+ "WORK_DIR = \"/content/2d-gaussian-splatting\"\n",
93
+ "\n",
94
+ "OUTPUT_DIR = '/content/output'\n",
95
+ "COLMAP_DIR = '/content/colmap_data'"
96
+ ]
97
+ },
98
+ {
99
+ "cell_type": "code",
100
+ "execution_count": 34,
101
+ "id": "be6df249",
102
+ "metadata": {
103
+ "execution": {
104
+ "iopub.execute_input": "2026-01-10T18:17:32.363444Z",
105
+ "iopub.status.busy": "2026-01-10T18:17:32.363175Z",
106
+ "iopub.status.idle": "2026-01-10T18:22:43.720241Z",
107
+ "shell.execute_reply": "2026-01-10T18:22:43.719380Z"
108
+ },
109
+ "papermill": {
110
+ "duration": 311.361656,
111
+ "end_time": "2026-01-10T18:22:43.721610",
112
+ "exception": false,
113
+ "start_time": "2026-01-10T18:17:32.359954",
114
+ "status": "completed"
115
+ },
116
+ "tags": [],
117
+ "id": "be6df249",
118
+ "outputId": "4d17052f-2c01-4f3e-ebd6-cb864bc264a5",
119
+ "colab": {
120
+ "base_uri": "https://localhost:8080/"
121
+ }
122
+ },
123
+ "outputs": [
124
+ {
125
+ "output_type": "stream",
126
+ "name": "stdout",
127
+ "text": [
128
+ "๐Ÿš€ Setting up COLAB environment (v8 - Python 3.12 compatible)\n",
129
+ "\n",
130
+ "======================================================================\n",
131
+ "STEP 0: Fix NumPy (Python 3.12 compatible)\n",
132
+ "======================================================================\n",
133
+ "Running: /usr/bin/python3 -m pip uninstall -y numpy\n",
134
+ "Running: /usr/bin/python3 -m pip install numpy==1.26.4\n",
135
+ "Running: /usr/bin/python3 -c import numpy; print('NumPy:', numpy.__version__)\n",
136
+ "\n",
137
+ "======================================================================\n",
138
+ "STEP 1: System packages\n",
139
+ "======================================================================\n",
140
+ "Running: apt-get update -qq\n",
141
+ "Running: apt-get install -y -qq colmap build-essential cmake git libopenblas-dev xvfb\n",
142
+ "\n",
143
+ "======================================================================\n",
144
+ "STEP 2: Clone Gaussian Splatting\n",
145
+ "======================================================================\n",
146
+ "โœ“ Repository already exists\n",
147
+ "\n",
148
+ "======================================================================\n",
149
+ "STEP 3: Python packages (VERBOSE MODE)\n",
150
+ "======================================================================\n",
151
+ "\n",
152
+ "๐Ÿ“ฆ Installing PyTorch...\n",
153
+ "Running: /usr/bin/python3 -m pip install torch torchvision torchaudio\n",
154
+ "\n",
155
+ "๐Ÿ“ฆ Installing core utilities...\n",
156
+ "Running: /usr/bin/python3 -m pip install opencv-python pillow imageio imageio-ffmpeg plyfile tqdm tensorboard\n",
157
+ "\n",
158
+ "๐Ÿ“ฆ Installing transformers (NumPy 1.26 compatible)...\n",
159
+ "Running: /usr/bin/python3 -m pip install transformers==4.40.0\n",
160
+ "\n",
161
+ "๐Ÿ“ฆ Installing LightGlue stack...\n",
162
+ "Running: /usr/bin/python3 -m pip install kornia\n",
163
+ "Running: /usr/bin/python3 -m pip install h5py\n",
164
+ "Running: /usr/bin/python3 -m pip install matplotlib\n",
165
+ "Running: /usr/bin/python3 -m pip install pycolmap\n",
166
+ "\n",
167
+ "======================================================================\n",
168
+ "STEP 4: Detailed Verification\n",
169
+ "======================================================================\n",
170
+ "\n",
171
+ "๐Ÿ” Testing NumPy...\n",
172
+ " โœ“ NumPy: 2.0.2\n",
173
+ "\n",
174
+ "๐Ÿ” Testing PyTorch...\n",
175
+ " โœ“ PyTorch: 2.9.0+cu128\n",
176
+ " โœ“ CUDA available: True\n",
177
+ " โœ“ CUDA version: 12.8\n",
178
+ "\n",
179
+ "๐Ÿ” Testing transformers...\n",
180
+ " โœ“ transformers version: 4.40.0\n",
181
+ " โœ“ AutoModel import: OK\n",
182
+ "\n",
183
+ "๐Ÿ” Testing pycolmap...\n",
184
+ " โœ“ pycolmap: OK\n",
185
+ "\n",
186
+ "๐Ÿ” Testing kornia...\n",
187
+ " โœ“ kornia: 0.8.2\n"
188
+ ]
189
+ }
190
+ ],
191
+ "source": [
192
+ "def run_cmd(cmd, check=True, capture=False, cwd=None): # โ† cwd=None ใ‚’่ฟฝๅŠ \n",
193
+ " \"\"\"Run command with better error handling\"\"\"\n",
194
+ " print(f\"Running: {' '.join(cmd)}\")\n",
195
+ " result = subprocess.run(\n",
196
+ " cmd,\n",
197
+ " capture_output=capture,\n",
198
+ " text=True,\n",
199
+ " check=False,\n",
200
+ " cwd=cwd # โ† ใ“ใ“ใซๆธกใ™\n",
201
+ " )\n",
202
+ " if check and result.returncode != 0:\n",
203
+ " print(f\"โŒ Command failed with code {result.returncode}\")\n",
204
+ " if capture:\n",
205
+ " print(f\"STDOUT: {result.stdout}\")\n",
206
+ " print(f\"STDERR: {result.stderr}\")\n",
207
+ " return result\n",
208
+ "\n",
209
+ "\n",
210
+ "def setup_environment():\n",
211
+ " \"\"\"\n",
212
+ " Colab environment setup for Gaussian Splatting + LightGlue + pycolmap\n",
213
+ " Python 3.12 compatible version (v8)\n",
214
+ " \"\"\"\n",
215
+ "\n",
216
+ " print(\"๐Ÿš€ Setting up COLAB environment (v8 - Python 3.12 compatible)\")\n",
217
+ "\n",
218
+ " WORK_DIR = \"2d-gaussian-splatting\"\n",
219
+ "\n",
220
+ " # =====================================================================\n",
221
+ " # STEP 0: NumPy FIX (Python 3.12 compatible)\n",
222
+ " # =====================================================================\n",
223
+ " print(\"\\n\" + \"=\"*70)\n",
224
+ " print(\"STEP 0: Fix NumPy (Python 3.12 compatible)\")\n",
225
+ " print(\"=\"*70)\n",
226
+ "\n",
227
+ " # Python 3.12 requires numpy >= 1.26\n",
228
+ " run_cmd([sys.executable, \"-m\", \"pip\", \"uninstall\", \"-y\", \"numpy\"])\n",
229
+ " run_cmd([sys.executable, \"-m\", \"pip\", \"install\", \"numpy==1.26.4\"])\n",
230
+ "\n",
231
+ " # sanity check\n",
232
+ " run_cmd([sys.executable, \"-c\", \"import numpy; print('NumPy:', numpy.__version__)\"])\n",
233
+ "\n",
234
+ " # =====================================================================\n",
235
+ " # STEP 1: System packages (Colab)\n",
236
+ " # =====================================================================\n",
237
+ " print(\"\\n\" + \"=\"*70)\n",
238
+ " print(\"STEP 1: System packages\")\n",
239
+ " print(\"=\"*70)\n",
240
+ "\n",
241
+ " run_cmd([\"apt-get\", \"update\", \"-qq\"])\n",
242
+ " run_cmd([\n",
243
+ " \"apt-get\", \"install\", \"-y\", \"-qq\",\n",
244
+ " \"colmap\",\n",
245
+ " \"build-essential\",\n",
246
+ " \"cmake\",\n",
247
+ " \"git\",\n",
248
+ " \"libopenblas-dev\",\n",
249
+ " \"xvfb\"\n",
250
+ " ])\n",
251
+ "\n",
252
+ " # virtual display (COLMAP / OpenCV safety)\n",
253
+ " os.environ[\"QT_QPA_PLATFORM\"] = \"offscreen\"\n",
254
+ " os.environ[\"DISPLAY\"] = \":99\"\n",
255
+ " subprocess.Popen(\n",
256
+ " [\"Xvfb\", \":99\", \"-screen\", \"0\", \"1024x768x24\"],\n",
257
+ " stdout=subprocess.DEVNULL,\n",
258
+ " stderr=subprocess.DEVNULL\n",
259
+ " )\n",
260
+ "\n",
261
+ " # =====================================================================\n",
262
+ " # STEP 2: Clone 2D Gaussian Splatting\n",
263
+ " # =====================================================================\n",
264
+ " print(\"\\n\" + \"=\"*70)\n",
265
+ " print(\"STEP 2: Clone Gaussian Splatting\")\n",
266
+ " print(\"=\"*70)\n",
267
+ "\n",
268
+ " if not os.path.exists(WORK_DIR):\n",
269
+ " run_cmd([\n",
270
+ " \"git\", \"clone\", \"--recursive\",\n",
271
+ " \"https://github.com/hbb1/2d-gaussian-splatting.git\",\n",
272
+ " WORK_DIR\n",
273
+ " ])\n",
274
+ " else:\n",
275
+ " print(\"โœ“ Repository already exists\")\n",
276
+ "\n",
277
+ " # =====================================================================\n",
278
+ " # STEP 3: Python packages (FIXED ORDER & VERSIONS)\n",
279
+ " # =====================================================================\n",
280
+ " print(\"\\n\" + \"=\"*70)\n",
281
+ " print(\"STEP 3: Python packages (VERBOSE MODE)\")\n",
282
+ " print(\"=\"*70)\n",
283
+ "\n",
284
+ " # ---- PyTorch (Colab CUDAๅฏพๅฟœ) ----\n",
285
+ " print(\"\\n๐Ÿ“ฆ Installing PyTorch...\")\n",
286
+ " run_cmd([\n",
287
+ " sys.executable, \"-m\", \"pip\", \"install\",\n",
288
+ " \"torch\", \"torchvision\", \"torchaudio\"\n",
289
+ " ])\n",
290
+ "\n",
291
+ " # ---- Core utils ----\n",
292
+ " print(\"\\n๐Ÿ“ฆ Installing core utilities...\")\n",
293
+ " run_cmd([\n",
294
+ " sys.executable, \"-m\", \"pip\", \"install\",\n",
295
+ " \"opencv-python\",\n",
296
+ " \"pillow\",\n",
297
+ " \"imageio\",\n",
298
+ " \"imageio-ffmpeg\",\n",
299
+ " \"plyfile\",\n",
300
+ " \"tqdm\",\n",
301
+ " \"tensorboard\"\n",
302
+ " ])\n",
303
+ "\n",
304
+ " # ---- transformers (NumPy 1.26 compatible) ----\n",
305
+ " print(\"\\n๐Ÿ“ฆ Installing transformers (NumPy 1.26 compatible)...\")\n",
306
+ " # Install transformers with proper dependencies\n",
307
+ " run_cmd([\n",
308
+ " sys.executable, \"-m\", \"pip\", \"install\",\n",
309
+ " \"transformers==4.40.0\"\n",
310
+ " ])\n",
311
+ "\n",
312
+ " # ---- LightGlue stack (GITHUB INSTALL) ----\n",
313
+ " print(\"\\n๐Ÿ“ฆ Installing LightGlue stack...\")\n",
314
+ "\n",
315
+ " # Install kornia first\n",
316
+ " run_cmd([sys.executable, \"-m\", \"pip\", \"install\", \"kornia\"])\n",
317
+ "\n",
318
+ " # Install h5py (sometimes needed)\n",
319
+ " run_cmd([sys.executable, \"-m\", \"pip\", \"install\", \"h5py\"])\n",
320
+ "\n",
321
+ " # Install matplotlib (LightGlue dependency)\n",
322
+ " run_cmd([sys.executable, \"-m\", \"pip\", \"install\", \"matplotlib\"])\n",
323
+ "\n",
324
+ " # Install pycolmap\n",
325
+ " run_cmd([sys.executable, \"-m\", \"pip\", \"install\", \"pycolmap\"])\n",
326
+ "\n",
327
+ "\n",
328
+ "\n",
329
+ " # =====================================================================\n",
330
+ " # STEP 4: Detailed Verification\n",
331
+ " # =====================================================================\n",
332
+ " print(\"\\n\" + \"=\"*70)\n",
333
+ " print(\"STEP 4: Detailed Verification\")\n",
334
+ " print(\"=\"*70)\n",
335
+ "\n",
336
+ " # NumPy (verify version first)\n",
337
+ " print(\"\\n๐Ÿ” Testing NumPy...\")\n",
338
+ " try:\n",
339
+ " import numpy as np\n",
340
+ " print(f\" โœ“ NumPy: {np.__version__}\")\n",
341
+ " except Exception as e:\n",
342
+ " print(f\" โŒ NumPy failed: {e}\")\n",
343
+ "\n",
344
+ " # PyTorch\n",
345
+ " print(\"\\n๐Ÿ” Testing PyTorch...\")\n",
346
+ " try:\n",
347
+ " import torch\n",
348
+ " print(f\" โœ“ PyTorch: {torch.__version__}\")\n",
349
+ " print(f\" โœ“ CUDA available: {torch.cuda.is_available()}\")\n",
350
+ " if torch.cuda.is_available():\n",
351
+ " print(f\" โœ“ CUDA version: {torch.version.cuda}\")\n",
352
+ " except Exception as e:\n",
353
+ " print(f\" โŒ PyTorch failed: {e}\")\n",
354
+ "\n",
355
+ " # transformers\n",
356
+ " print(\"\\n๐Ÿ” Testing transformers...\")\n",
357
+ " try:\n",
358
+ " import transformers\n",
359
+ " print(f\" โœ“ transformers version: {transformers.__version__}\")\n",
360
+ " from transformers import AutoModel\n",
361
+ " print(f\" โœ“ AutoModel import: OK\")\n",
362
+ " except Exception as e:\n",
363
+ " print(f\" โŒ transformers failed: {e}\")\n",
364
+ " print(f\" Attempting detailed diagnosis...\")\n",
365
+ " result = run_cmd([\n",
366
+ " sys.executable, \"-c\",\n",
367
+ " \"import transformers; print(transformers.__version__)\"\n",
368
+ " ], capture=True)\n",
369
+ " print(f\" Output: {result.stdout}\")\n",
370
+ " print(f\" Error: {result.stderr}\")\n",
371
+ "\n",
372
+ " # pycolmap\n",
373
+ " print(\"\\n๐Ÿ” Testing pycolmap...\")\n",
374
+ " try:\n",
375
+ " import pycolmap\n",
376
+ " print(f\" โœ“ pycolmap: OK\")\n",
377
+ " except Exception as e:\n",
378
+ " print(f\" โŒ pycolmap failed: {e}\")\n",
379
+ "\n",
380
+ " # kornia\n",
381
+ " print(\"\\n๐Ÿ” Testing kornia...\")\n",
382
+ " try:\n",
383
+ " import kornia\n",
384
+ " print(f\" โœ“ kornia: {kornia.__version__}\")\n",
385
+ " except Exception as e:\n",
386
+ " print(f\" โŒ kornia failed: {e}\")\n",
387
+ "\n",
388
+ " return WORK_DIR\n",
389
+ "\n",
390
+ "\n",
391
+ "if __name__ == \"__main__\":\n",
392
+ " setup_environment()"
393
+ ]
394
+ },
395
+ {
396
+ "cell_type": "code",
397
+ "source": [],
398
+ "metadata": {
399
+ "id": "3UEcAPBILz6Z"
400
+ },
401
+ "id": "3UEcAPBILz6Z",
402
+ "execution_count": 34,
403
+ "outputs": []
404
+ },
405
+ {
406
+ "cell_type": "code",
407
+ "source": [
408
+ "# =====================================================================\n",
409
+ "# STEP 4: Build 2D GS submodules (็ขบๅฎŸใชๆ–นๆณ•)\n",
410
+ "# =====================================================================\n",
411
+ "print(\"\\n\" + \"=\"*70)\n",
412
+ "print(\"STEP 5: Build Gaussian Splatting submodules\")\n",
413
+ "print(\"=\"*70)\n",
414
+ "\n",
415
+ "# diff-surfel-rasterization\n",
416
+ "\n",
417
+ "path = os.path.join(WORK_DIR, \"submodules\", \"diff-surfel-rasterization\")\n",
418
+ "url = \"https://github.com/hbb1/diff-surfel-rasterization.git\"\n",
419
+ "name = os.path.basename(path)\n",
420
+ "print(f\"\\n๐Ÿ“ฆ Processing {name}...\")\n",
421
+ "if not os.path.exists(path):\n",
422
+ " print(f\" > Cloning {url}...\")\n",
423
+ " # ่ฆชใƒ‡ใ‚ฃใƒฌใ‚ฏใƒˆใƒชใŒๅญ˜ๅœจใ™ใ‚‹ใ“ใจใ‚’็ขบ่ช\n",
424
+ " os.makedirs(os.path.dirname(path), exist_ok=True)\n",
425
+ " run_cmd([\"git\", \"clone\", url, path])\n",
426
+ "else:\n",
427
+ " print(f\" โœ“ {name} already exists.\")\n",
428
+ "# 2. setup.py install (ใ‚ณใƒณใƒ‘ใ‚คใƒซ)\n",
429
+ "print(f\" > Compiling and Installing {name}...\")\n",
430
+ "result = run_cmd(\n",
431
+ " [sys.executable, \"setup.py\", \"install\"],\n",
432
+ " cwd=path,\n",
433
+ " check=False, # ใ‚จใƒฉใƒผใงใ‚‚ๆญขใ‚ใชใ„\n",
434
+ " capture=True\n",
435
+ ")\n",
436
+ "if result.returncode != 0:\n",
437
+ " print(f\"โŒ Failed to build {name}\")\n",
438
+ " print(\"--- STDERR ---\")\n",
439
+ " print(result.stderr)\n",
440
+ "else:\n",
441
+ " print(f\"โœ… Successfully built {name}\")"
442
+ ],
443
+ "metadata": {
444
+ "colab": {
445
+ "base_uri": "https://localhost:8080/"
446
+ },
447
+ "id": "kLdJ-FeT-kQc",
448
+ "outputId": "1366deca-2c20-49f1-a540-6528b2827efd"
449
+ },
450
+ "id": "kLdJ-FeT-kQc",
451
+ "execution_count": 35,
452
+ "outputs": [
453
+ {
454
+ "output_type": "stream",
455
+ "name": "stdout",
456
+ "text": [
457
+ "\n",
458
+ "======================================================================\n",
459
+ "STEP 5: Build Gaussian Splatting submodules\n",
460
+ "======================================================================\n",
461
+ "\n",
462
+ "๐Ÿ“ฆ Processing diff-surfel-rasterization...\n",
463
+ " โœ“ diff-surfel-rasterization already exists.\n",
464
+ " > Compiling and Installing diff-surfel-rasterization...\n",
465
+ "Running: /usr/bin/python3 setup.py install\n",
466
+ "โœ… Successfully built diff-surfel-rasterization\n"
467
+ ]
468
+ }
469
+ ]
470
+ },
471
+ {
472
+ "cell_type": "code",
473
+ "source": [
474
+ "import os\n",
475
+ "import sys\n",
476
+ "import shutil\n",
477
+ "import subprocess\n",
478
+ "\n",
479
+ "# --- ๅ‰ๆบ–ๅ‚™: ็’ฐๅขƒใฎๆ•ดๅ‚™ ---\n",
480
+ "print(\"Configuring build environment...\")\n",
481
+ "# 1. CUDAใ‚ณใƒณใƒ‘ใ‚คใƒฉใฎ็ขบ่ช\n",
482
+ "!nvcc --version\n",
483
+ "\n",
484
+ "# 2. ๅฟ…้ ˆใƒ„ใƒผใƒซใฎใ‚คใƒณใ‚นใƒˆใƒผใƒซ (ninjaใฏใƒ“ใƒซใƒ‰ใ‚’ๅฎ‰ๅฎšใƒป้ซ˜้€ŸๅŒ–ใ•ใ›ใพใ™)\n",
485
+ "!pip install setuptools wheel ninja\n",
486
+ "\n",
487
+ "# 3. ็’ฐๅขƒๅค‰ๆ•ฐใฎใ‚ปใƒƒใƒˆใ‚ขใƒƒใƒ— (CUDAใฎใƒ‘ใ‚นใ‚’ๆ˜Ž็คบ็š„ใซๆŒ‡ๅฎš)\n",
488
+ "os.environ[\"CUDA_HOME\"] = \"/usr/local/cuda\"\n",
489
+ "os.environ[\"PATH\"] = f'{os.environ[\"CUDA_HOME\"]}/bin:{os.environ[\"PATH\"]}'\n",
490
+ "os.environ[\"LD_LIBRARY_PATH\"] = f'{os.environ[\"CUDA_HOME\"]}/lib64:{os.environ[\"LD_LIBRARY_PATH\"]}'\n",
491
+ "# ใƒกใƒขใƒชไธ่ถณใซใ‚ˆใ‚‹ใ‚ฏใƒฉใƒƒใ‚ทใƒฅใ‚’้˜ฒใใŸ๏ฟฝ๏ฟฝ๏ฟฝใ€ไธฆๅˆ—ใƒ“ใƒซใƒ‰ๆ•ฐใ‚’ๅˆถ้™\n",
492
+ "os.environ[\"MAX_JOBS\"] = \"2\"\n",
493
+ "\n",
494
+ "def run_cmd(cmd, cwd=None, check=True):\n",
495
+ " \"\"\"ใ‚ณใƒžใƒณใƒ‰ๅฎŸ่กŒ็”จใฎใƒ˜ใƒซใƒ‘ใƒผ้–ขๆ•ฐ\"\"\"\n",
496
+ " return subprocess.run(cmd, cwd=cwd, capture_output=True, text=True, check=check)\n",
497
+ "\n",
498
+ "def install_submodule(name, url, base_dir):\n",
499
+ " \"\"\"ๅ€‹ๅˆฅใฎใ‚ตใƒ–ใƒขใ‚ธใƒฅใƒผใƒซใ‚’ใ‚คใƒณใ‚นใƒˆใƒผใƒซ\"\"\"\n",
500
+ " print(f\"\\n{'='*70}\")\n",
501
+ " print(f\"Installing {name}\")\n",
502
+ " print(f\"{'='*70}\")\n",
503
+ "\n",
504
+ " # ็ตถๅฏพใƒ‘ใ‚นใ‚’ไฝฟ็”จ\n",
505
+ " path = os.path.abspath(os.path.join(base_dir, \"submodules\", name))\n",
506
+ " print(f\" > Target path: {path}\")\n",
507
+ "\n",
508
+ " # Step 1: ๆ—ขๅญ˜ใ‚’ๅ‰Š้™ค\n",
509
+ " if os.path.exists(path):\n",
510
+ " print(f\" > Removing old {name}...\")\n",
511
+ " shutil.rmtree(path)\n",
512
+ "\n",
513
+ " # Step 2: ใ‚ฏใƒญใƒผใƒณ\n",
514
+ " print(f\" > Cloning from {url}...\")\n",
515
+ " os.makedirs(os.path.dirname(path), exist_ok=True)\n",
516
+ " try:\n",
517
+ " run_cmd([\"git\", \"clone\", url, path])\n",
518
+ " except subprocess.CalledProcessError as e:\n",
519
+ " print(f\"โŒ Failed to clone {name}\")\n",
520
+ " print(e.stderr)\n",
521
+ " return False\n",
522
+ "\n",
523
+ " # Step 3: ใƒ•ใ‚กใ‚คใƒซ็ขบ่ช (spatial.cu ็ญ‰ใฎๅญ˜ๅœจใ‚’ใƒใ‚งใƒƒใ‚ฏ)\n",
524
+ " print(f\" > Checking cloned files...\")\n",
525
+ " files = os.listdir(path)\n",
526
+ " print(f\" > Files in {name}: {files[:10]}...\")\n",
527
+ "\n",
528
+ " # Step 4: ็‰นๅฎšใƒขใ‚ธใƒฅใƒผใƒซใฎใ‚ตใƒ–ใƒขใ‚ธใƒฅใƒผใƒซๅˆๆœŸๅŒ–\n",
529
+ " if name == \"diff-surfel-rasterization\":\n",
530
+ " print(f\" > Initializing GLM submodule...\")\n",
531
+ " run_cmd([\"git\", \"submodule\", \"update\", \"--init\", \"--recursive\"], cwd=path)\n",
532
+ "\n",
533
+ " # Step 5: ใƒ“ใƒซใƒ‰ใ‚ญใƒฃใƒƒใ‚ทใƒฅๅ‰Š้™ค\n",
534
+ " build_dir = os.path.join(path, \"build\")\n",
535
+ " if os.path.exists(build_dir):\n",
536
+ " print(f\" > Cleaning build cache...\")\n",
537
+ " shutil.rmtree(build_dir)\n",
538
+ "\n",
539
+ " # Step 6: ใ‚คใƒณใ‚นใƒˆใƒผใƒซ\n",
540
+ " print(f\" > Installing {name} (This may take a few minutes)...\")\n",
541
+ " # ็’ฐๅขƒๅค‰ๆ•ฐใ‚’ๆ˜Ž็คบ็š„ใซๅผ•ใ็ถ™ใ\n",
542
+ " current_env = os.environ.copy()\n",
543
+ "\n",
544
+ " result = subprocess.run(\n",
545
+ " [sys.executable, \"-m\", \"pip\", \"install\", \"-e\", \".\", \"--no-build-isolation\", \"-v\"],\n",
546
+ " cwd=path,\n",
547
+ " env=current_env,\n",
548
+ " capture_output=True,\n",
549
+ " text=True\n",
550
+ " )\n",
551
+ "\n",
552
+ " if result.returncode != 0:\n",
553
+ " print(f\"โŒ Failed to install {name}\")\n",
554
+ " # C++/CUDAใฎใƒ“ใƒซใƒ‰ใ‚จใƒฉใƒผใฏ stdout ใซๅ‡บใ‚‹ใ“ใจใŒๅคšใ„ใŸใ‚ใ€ไธกๆ–นๅ‡บๅŠ›\n",
555
+ " print(\"\\n--- STDOUT (Build Logs) ---\")\n",
556
+ " stdout_lines = result.stdout.split('\\n')\n",
557
+ " print('\\n'.join(stdout_lines[-60:])) # ๆœ€ๅพŒใฎ60่กŒใ‚’่กจ็คบ\n",
558
+ "\n",
559
+ " print(\"\\n--- STDERR (Error Details) ---\")\n",
560
+ " print(result.stderr)\n",
561
+ " return False\n",
562
+ "\n",
563
+ " print(f\"โœ… Successfully installed {name}\")\n",
564
+ " return True\n",
565
+ "\n",
566
+ "# =====================================================================\n",
567
+ "# STEP 4: Build 2D GS submodules\n",
568
+ "# =====================================================================\n",
569
+ "print(\"\\n\" + \"=\"*70)\n",
570
+ "print(\"STEP 4: Build Gaussian Splatting submodules\")\n",
571
+ "print(\"=\"*70)\n",
572
+ "\n",
573
+ "# Colabใฎๅ ดๅˆใฏ็ตถๅฏพใƒ‘ใ‚น\n",
574
+ "WORK_DIR = \"/content/2d-gaussian-splatting\"\n",
575
+ "\n",
576
+ "# ๅ„ใ‚ตใƒ–ใƒขใ‚ธใƒฅใƒผใƒซใฎใ‚คใƒณใ‚นใƒˆใƒผใƒซ\n",
577
+ "# simple-knn\n",
578
+ "success_knn = install_submodule(\n",
579
+ " \"simple-knn\",\n",
580
+ " \"https://github.com/tztechno/simple-knn.git\",\n",
581
+ " WORK_DIR\n",
582
+ ")\n",
583
+ "\n",
584
+ "\n",
585
+ "# ็ตๆžœ่กจ็คบ\n",
586
+ "print(\"\\n\" + \"=\"*70)\n",
587
+ "print(\"Installation Summary\")\n",
588
+ "print(\"=\"*70)\n",
589
+ "print(f\"simple-knn: {'โœ… Success' if success_knn else 'โŒ Failed'}\")"
590
+ ],
591
+ "metadata": {
592
+ "colab": {
593
+ "base_uri": "https://localhost:8080/"
594
+ },
595
+ "id": "qYgJl2Fw_Phk",
596
+ "outputId": "58d7c749-fe3c-44b5-a64a-214f57dda063"
597
+ },
598
+ "id": "qYgJl2Fw_Phk",
599
+ "execution_count": 36,
600
+ "outputs": [
601
+ {
602
+ "output_type": "stream",
603
+ "name": "stdout",
604
+ "text": [
605
+ "Configuring build environment...\n",
606
+ "nvcc: NVIDIA (R) Cuda compiler driver\n",
607
+ "Copyright (c) 2005-2025 NVIDIA Corporation\n",
608
+ "Built on Fri_Feb_21_20:23:50_PST_2025\n",
609
+ "Cuda compilation tools, release 12.8, V12.8.93\n",
610
+ "Build cuda_12.8.r12.8/compiler.35583870_0\n",
611
+ "\u001b[33mDEPRECATION: Loading egg at /usr/local/lib/python3.12/dist-packages/diff_surfel_rasterization-0.0.1-py3.12-linux-x86_64.egg is deprecated. pip 24.3 will enforce this behaviour change. A possible replacement is to use pip for package installation. Discussion can be found at https://github.com/pypa/pip/issues/12330\u001b[0m\u001b[33m\n",
612
+ "\u001b[0mRequirement already satisfied: setuptools in /usr/local/lib/python3.12/dist-packages (75.2.0)\n",
613
+ "Requirement already satisfied: wheel in /usr/local/lib/python3.12/dist-packages (0.46.3)\n",
614
+ "Requirement already satisfied: ninja in /usr/local/lib/python3.12/dist-packages (1.13.0)\n",
615
+ "Requirement already satisfied: packaging>=24.0 in /usr/local/lib/python3.12/dist-packages (from wheel) (26.0)\n",
616
+ "\n",
617
+ "======================================================================\n",
618
+ "STEP 4: Build Gaussian Splatting submodules\n",
619
+ "======================================================================\n",
620
+ "\n",
621
+ "======================================================================\n",
622
+ "Installing simple-knn\n",
623
+ "======================================================================\n",
624
+ " > Target path: /content/2d-gaussian-splatting/submodules/simple-knn\n",
625
+ " > Removing old simple-knn...\n",
626
+ " > Cloning from https://github.com/tztechno/simple-knn.git...\n",
627
+ " > Checking cloned files...\n",
628
+ " > Files in simple-knn: ['.git', 'setup.py', 'simple_knn.h', 'simple_knn', 'README.md', 'spatial.h', 'simple_knn0.cu', 'spatial.cu', '.gitignore', 'ext.cpp']...\n",
629
+ " > Installing simple-knn (This may take a few minutes)...\n",
630
+ "โœ… Successfully installed simple-knn\n",
631
+ "\n",
632
+ "======================================================================\n",
633
+ "Installation Summary\n",
634
+ "======================================================================\n",
635
+ "simple-knn: โœ… Success\n"
636
+ ]
637
+ }
638
+ ]
639
+ },
640
+ {
641
+ "cell_type": "code",
642
+ "source": [
643
+ "!pip install trimesh"
644
+ ],
645
+ "metadata": {
646
+ "colab": {
647
+ "base_uri": "https://localhost:8080/"
648
+ },
649
+ "id": "-ZfMABILvydS",
650
+ "outputId": "07356f72-9a60-4103-ee76-ee2da6f3d542"
651
+ },
652
+ "id": "-ZfMABILvydS",
653
+ "execution_count": 45,
654
+ "outputs": [
655
+ {
656
+ "output_type": "stream",
657
+ "name": "stdout",
658
+ "text": [
659
+ "\u001b[33mDEPRECATION: Loading egg at /usr/local/lib/python3.12/dist-packages/diff_surfel_rasterization-0.0.1-py3.12-linux-x86_64.egg is deprecated. pip 24.3 will enforce this behaviour change. A possible replacement is to use pip for package installation. Discussion can be found at https://github.com/pypa/pip/issues/12330\u001b[0m\u001b[33m\n",
660
+ "\u001b[0mCollecting trimesh\n",
661
+ " Downloading trimesh-4.11.2-py3-none-any.whl.metadata (13 kB)\n",
662
+ "Requirement already satisfied: numpy>=1.20 in /usr/local/lib/python3.12/dist-packages (from trimesh) (2.4.2)\n",
663
+ "Downloading trimesh-4.11.2-py3-none-any.whl (740 kB)\n",
664
+ "\u001b[2K \u001b[90mโ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”\u001b[0m \u001b[32m740.3/740.3 kB\u001b[0m \u001b[31m39.3 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
665
+ "\u001b[?25hInstalling collected packages: trimesh\n",
666
+ "Successfully installed trimesh-4.11.2\n"
667
+ ]
668
+ }
669
+ ]
670
+ },
671
+ {
672
+ "cell_type": "code",
673
+ "source": [
674
+ "def setup_2dgs_environment():\n",
675
+ " \"\"\"2DGS็’ฐๅขƒใฎใ‚ปใƒƒใƒˆใ‚ขใƒƒใƒ—๏ผˆๅฎŒๅ…จ็‰ˆ๏ผ‰\"\"\"\n",
676
+ " print(\"Setting up 2DGS environment...\")\n",
677
+ "\n",
678
+ " # ๅฟ…่ฆใชใƒ‘ใƒƒใ‚ฑใƒผใ‚ธใ‚’ใ™ในใฆใ‚คใƒณใ‚นใƒˆใƒผใƒซ\n",
679
+ " packages = [\n",
680
+ " 'plyfile',\n",
681
+ " 'mediapy',\n",
682
+ " 'open3d', # โ† ใ“ใ‚Œใ‚’่ฟฝๅŠ \n",
683
+ " ]\n",
684
+ "\n",
685
+ " for pkg in packages:\n",
686
+ " print(f\"Installing {pkg}...\")\n",
687
+ " subprocess.run(['pip', 'install', pkg], check=True)\n",
688
+ "\n",
689
+ " # 2DGSใƒชใƒใ‚ธใƒˆใƒชใฎใ‚ฏใƒญใƒผใƒณ\n",
690
+ " if not os.path.exists(WORK_DIR):\n",
691
+ " subprocess.run([\n",
692
+ " 'git', 'clone', '--recursive',\n",
693
+ " 'https://github.com/hbb1/2d-gaussian-splatting.git',\n",
694
+ " WORK_DIR\n",
695
+ " ], check=True)\n",
696
+ "\n",
697
+ " subprocess.run(['git', 'submodule', 'update', '--init', '--recursive'],\n",
698
+ " cwd=WORK_DIR, check=True)\n",
699
+ "\n",
700
+ " build_2dgs_submodules()\n",
701
+ "\n",
702
+ " print(\"โœ… 2DGS environment setup complete\")"
703
+ ],
704
+ "metadata": {
705
+ "id": "kXPLG7byqFlr"
706
+ },
707
+ "id": "kXPLG7byqFlr",
708
+ "execution_count": 37,
709
+ "outputs": []
710
+ },
711
+ {
712
+ "cell_type": "code",
713
+ "source": [
714
+ "!pip install open3d"
715
+ ],
716
+ "metadata": {
717
+ "colab": {
718
+ "base_uri": "https://localhost:8080/"
719
+ },
720
+ "id": "55dtC6ByqJRY",
721
+ "outputId": "11171aa0-0dc5-4235-c39b-6e19985a5632"
722
+ },
723
+ "id": "55dtC6ByqJRY",
724
+ "execution_count": 38,
725
+ "outputs": [
726
+ {
727
+ "output_type": "stream",
728
+ "name": "stdout",
729
+ "text": [
730
+ "\u001b[33mDEPRECATION: Loading egg at /usr/local/lib/python3.12/dist-packages/diff_surfel_rasterization-0.0.1-py3.12-linux-x86_64.egg is deprecated. pip 24.3 will enforce this behaviour change. A possible replacement is to use pip for package installation. Discussion can be found at https://github.com/pypa/pip/issues/12330\u001b[0m\u001b[33m\n",
731
+ "\u001b[0mRequirement already satisfied: open3d in /usr/local/lib/python3.12/dist-packages (0.19.0)\n",
732
+ "Requirement already satisfied: numpy>=1.18.0 in /usr/local/lib/python3.12/dist-packages (from open3d) (2.4.2)\n",
733
+ "Requirement already satisfied: dash>=2.6.0 in /usr/local/lib/python3.12/dist-packages (from open3d) (4.0.0)\n",
734
+ "Requirement already satisfied: werkzeug>=3.0.0 in /usr/local/lib/python3.12/dist-packages (from open3d) (3.1.5)\n",
735
+ "Requirement already satisfied: flask>=3.0.0 in /usr/local/lib/python3.12/dist-packages (from open3d) (3.1.2)\n",
736
+ "Requirement already satisfied: nbformat>=5.7.0 in /usr/local/lib/python3.12/dist-packages (from open3d) (5.10.4)\n",
737
+ "Requirement already satisfied: configargparse in /usr/local/lib/python3.12/dist-packages (from open3d) (1.7.1)\n",
738
+ "Requirement already satisfied: ipywidgets>=8.0.4 in /usr/local/lib/python3.12/dist-packages (from open3d) (8.1.8)\n",
739
+ "Requirement already satisfied: addict in /usr/local/lib/python3.12/dist-packages (from open3d) (2.4.0)\n",
740
+ "Requirement already satisfied: pillow>=9.3.0 in /usr/local/lib/python3.12/dist-packages (from open3d) (11.3.0)\n",
741
+ "Requirement already satisfied: matplotlib>=3 in /usr/local/lib/python3.12/dist-packages (from open3d) (3.10.0)\n",
742
+ "Requirement already satisfied: pandas>=1.0 in /usr/local/lib/python3.12/dist-packages (from open3d) (2.2.2)\n",
743
+ "Requirement already satisfied: pyyaml>=5.4.1 in /usr/local/lib/python3.12/dist-packages (from open3d) (6.0.3)\n",
744
+ "Requirement already satisfied: scikit-learn>=0.21 in /usr/local/lib/python3.12/dist-packages (from open3d) (1.6.1)\n",
745
+ "Requirement already satisfied: tqdm in /usr/local/lib/python3.12/dist-packages (from open3d) (4.67.3)\n",
746
+ "Requirement already satisfied: pyquaternion in /usr/local/lib/python3.12/dist-packages (from open3d) (0.9.9)\n",
747
+ "Requirement already satisfied: plotly>=5.0.0 in /usr/local/lib/python3.12/dist-packages (from dash>=2.6.0->open3d) (5.24.1)\n",
748
+ "Requirement already satisfied: importlib-metadata in /usr/local/lib/python3.12/dist-packages (from dash>=2.6.0->open3d) (8.7.1)\n",
749
+ "Requirement already satisfied: typing_extensions>=4.1.1 in /usr/local/lib/python3.12/dist-packages (from dash>=2.6.0->open3d) (4.15.0)\n",
750
+ "Requirement already satisfied: requests in /usr/local/lib/python3.12/dist-packages (from dash>=2.6.0->open3d) (2.32.4)\n",
751
+ "Requirement already satisfied: retrying in /usr/local/lib/python3.12/dist-packages (from dash>=2.6.0->open3d) (1.4.2)\n",
752
+ "Requirement already satisfied: nest-asyncio in /usr/local/lib/python3.12/dist-packages (from dash>=2.6.0->open3d) (1.6.0)\n",
753
+ "Requirement already satisfied: setuptools in /usr/local/lib/python3.12/dist-packages (from dash>=2.6.0->open3d) (75.2.0)\n",
754
+ "Requirement already satisfied: blinker>=1.9.0 in /usr/local/lib/python3.12/dist-packages (from flask>=3.0.0->open3d) (1.9.0)\n",
755
+ "Requirement already satisfied: click>=8.1.3 in /usr/local/lib/python3.12/dist-packages (from flask>=3.0.0->open3d) (8.3.1)\n",
756
+ "Requirement already satisfied: itsdangerous>=2.2.0 in /usr/local/lib/python3.12/dist-packages (from flask>=3.0.0->open3d) (2.2.0)\n",
757
+ "Requirement already satisfied: jinja2>=3.1.2 in /usr/local/lib/python3.12/dist-packages (from flask>=3.0.0->open3d) (3.1.6)\n",
758
+ "Requirement already satisfied: markupsafe>=2.1.1 in /usr/local/lib/python3.12/dist-packages (from flask>=3.0.0->open3d) (3.0.3)\n",
759
+ "Requirement already satisfied: comm>=0.1.3 in /usr/local/lib/python3.12/dist-packages (from ipywidgets>=8.0.4->open3d) (0.2.3)\n",
760
+ "Requirement already satisfied: ipython>=6.1.0 in /usr/local/lib/python3.12/dist-packages (from ipywidgets>=8.0.4->open3d) (7.34.0)\n",
761
+ "Requirement already satisfied: traitlets>=4.3.1 in /usr/local/lib/python3.12/dist-packages (from ipywidgets>=8.0.4->open3d) (5.7.1)\n",
762
+ "Requirement already satisfied: widgetsnbextension~=4.0.14 in /usr/local/lib/python3.12/dist-packages (from ipywidgets>=8.0.4->open3d) (4.0.15)\n",
763
+ "Requirement already satisfied: jupyterlab_widgets~=3.0.15 in /usr/local/lib/python3.12/dist-packages (from ipywidgets>=8.0.4->open3d) (3.0.16)\n",
764
+ "Requirement already satisfied: contourpy>=1.0.1 in /usr/local/lib/python3.12/dist-packages (from matplotlib>=3->open3d) (1.3.3)\n",
765
+ "Requirement already satisfied: cycler>=0.10 in /usr/local/lib/python3.12/dist-packages (from matplotlib>=3->open3d) (0.12.1)\n",
766
+ "Requirement already satisfied: fonttools>=4.22.0 in /usr/local/lib/python3.12/dist-packages (from matplotlib>=3->open3d) (4.61.1)\n",
767
+ "Requirement already satisfied: kiwisolver>=1.3.1 in /usr/local/lib/python3.12/dist-packages (from matplotlib>=3->open3d) (1.4.9)\n",
768
+ "Requirement already satisfied: packaging>=20.0 in /usr/local/lib/python3.12/dist-packages (from matplotlib>=3->open3d) (26.0)\n",
769
+ "Requirement already satisfied: pyparsing>=2.3.1 in /usr/local/lib/python3.12/dist-packages (from matplotlib>=3->open3d) (3.3.2)\n",
770
+ "Requirement already satisfied: python-dateutil>=2.7 in /usr/local/lib/python3.12/dist-packages (from matplotlib>=3->open3d) (2.9.0.post0)\n",
771
+ "Requirement already satisfied: fastjsonschema>=2.15 in /usr/local/lib/python3.12/dist-packages (from nbformat>=5.7.0->open3d) (2.21.2)\n",
772
+ "Requirement already satisfied: jsonschema>=2.6 in /usr/local/lib/python3.12/dist-packages (from nbformat>=5.7.0->open3d) (4.26.0)\n",
773
+ "Requirement already satisfied: jupyter-core!=5.0.*,>=4.12 in /usr/local/lib/python3.12/dist-packages (from nbformat>=5.7.0->open3d) (5.9.1)\n",
774
+ "Requirement already satisfied: pytz>=2020.1 in /usr/local/lib/python3.12/dist-packages (from pandas>=1.0->open3d) (2025.2)\n",
775
+ "Requirement already satisfied: tzdata>=2022.7 in /usr/local/lib/python3.12/dist-packages (from pandas>=1.0->open3d) (2025.3)\n",
776
+ "Requirement already satisfied: scipy>=1.6.0 in /usr/local/lib/python3.12/dist-packages (from scikit-learn>=0.21->open3d) (1.16.3)\n",
777
+ "Requirement already satisfied: joblib>=1.2.0 in /usr/local/lib/python3.12/dist-packages (from scikit-learn>=0.21->open3d) (1.5.3)\n",
778
+ "Requirement already satisfied: threadpoolctl>=3.1.0 in /usr/local/lib/python3.12/dist-packages (from scikit-learn>=0.21->open3d) (3.6.0)\n",
779
+ "Requirement already satisfied: jedi>=0.16 in /usr/local/lib/python3.12/dist-packages (from ipython>=6.1.0->ipywidgets>=8.0.4->open3d) (0.19.2)\n",
780
+ "Requirement already satisfied: decorator in /usr/local/lib/python3.12/dist-packages (from ipython>=6.1.0->ipywidgets>=8.0.4->open3d) (4.4.2)\n",
781
+ "Requirement already satisfied: pickleshare in /usr/local/lib/python3.12/dist-packages (from ipython>=6.1.0->ipywidgets>=8.0.4->open3d) (0.7.5)\n",
782
+ "Requirement already satisfied: prompt-toolkit!=3.0.0,!=3.0.1,<3.1.0,>=2.0.0 in /usr/local/lib/python3.12/dist-packages (from ipython>=6.1.0->ipywidgets>=8.0.4->open3d) (3.0.52)\n",
783
+ "Requirement already satisfied: pygments in /usr/local/lib/python3.12/dist-packages (from ipython>=6.1.0->ipywidgets>=8.0.4->open3d) (2.19.2)\n",
784
+ "Requirement already satisfied: backcall in /usr/local/lib/python3.12/dist-packages (from ipython>=6.1.0->ipywidgets>=8.0.4->open3d) (0.2.0)\n",
785
+ "Requirement already satisfied: matplotlib-inline in /usr/local/lib/python3.12/dist-packages (from ipython>=6.1.0->ipywidgets>=8.0.4->open3d) (0.2.1)\n",
786
+ "Requirement already satisfied: pexpect>4.3 in /usr/local/lib/python3.12/dist-packages (from ipython>=6.1.0->ipywidgets>=8.0.4->open3d) (4.9.0)\n",
787
+ "Requirement already satisfied: attrs>=22.2.0 in /usr/local/lib/python3.12/dist-packages (from jsonschema>=2.6->nbformat>=5.7.0->open3d) (25.4.0)\n",
788
+ "Requirement already satisfied: jsonschema-specifications>=2023.03.6 in /usr/local/lib/python3.12/dist-packages (from jsonschema>=2.6->nbformat>=5.7.0->open3d) (2025.9.1)\n",
789
+ "Requirement already satisfied: referencing>=0.28.4 in /usr/local/lib/python3.12/dist-packages (from jsonschema>=2.6->nbformat>=5.7.0->open3d) (0.37.0)\n",
790
+ "Requirement already satisfied: rpds-py>=0.25.0 in /usr/local/lib/python3.12/dist-packages (from jsonschema>=2.6->nbformat>=5.7.0->open3d) (0.30.0)\n",
791
+ "Requirement already satisfied: platformdirs>=2.5 in /usr/local/lib/python3.12/dist-packages (from jupyter-core!=5.0.*,>=4.12->nbformat>=5.7.0->open3d) (4.5.1)\n",
792
+ "Requirement already satisfied: tenacity>=6.2.0 in /usr/local/lib/python3.12/dist-packages (from plotly>=5.0.0->dash>=2.6.0->open3d) (9.1.3)\n",
793
+ "Requirement already satisfied: six>=1.5 in /usr/local/lib/python3.12/dist-packages (from python-dateutil>=2.7->matplotlib>=3->open3d) (1.17.0)\n",
794
+ "Requirement already satisfied: zipp>=3.20 in /usr/local/lib/python3.12/dist-packages (from importlib-metadata->dash>=2.6.0->open3d) (3.23.0)\n",
795
+ "Requirement already satisfied: charset_normalizer<4,>=2 in /usr/local/lib/python3.12/dist-packages (from requests->dash>=2.6.0->open3d) (3.4.4)\n",
796
+ "Requirement already satisfied: idna<4,>=2.5 in /usr/local/lib/python3.12/dist-packages (from requests->dash>=2.6.0->open3d) (3.11)\n",
797
+ "Requirement already satisfied: urllib3<3,>=1.21.1 in /usr/local/lib/python3.12/dist-packages (from requests->dash>=2.6.0->open3d) (2.5.0)\n",
798
+ "Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.12/dist-packages (from requests->dash>=2.6.0->open3d) (2026.1.4)\n",
799
+ "Requirement already satisfied: parso<0.9.0,>=0.8.4 in /usr/local/lib/python3.12/dist-packages (from jedi>=0.16->ipython>=6.1.0->ipywidgets>=8.0.4->open3d) (0.8.5)\n",
800
+ "Requirement already satisfied: ptyprocess>=0.5 in /usr/local/lib/python3.12/dist-packages (from pexpect>4.3->ipython>=6.1.0->ipywidgets>=8.0.4->open3d) (0.7.0)\n",
801
+ "Requirement already satisfied: wcwidth in /usr/local/lib/python3.12/dist-packages (from prompt-toolkit!=3.0.0,!=3.0.1,<3.1.0,>=2.0.0->ipython>=6.1.0->ipywidgets>=8.0.4->open3d) (0.5.3)\n"
802
+ ]
803
+ }
804
+ ]
805
+ },
806
+ {
807
+ "cell_type": "code",
808
+ "source": [
809
+ "\n",
810
+ "\n",
811
+ "\n",
812
+ "# ๅ†ๅบฆใƒฌใƒณใƒ€ใƒชใƒณใ‚ฐๅฎŸ่กŒ\n",
813
+ "import subprocess\n",
814
+ "result = subprocess.run(\n",
815
+ " ['/usr/bin/python3', 'render.py',\n",
816
+ " '-m', '/content/2d-gaussian-splatting/output/video',\n",
817
+ " '--iteration', '1000',\n",
818
+ " '--skip_test',\n",
819
+ " '--skip_train'],\n",
820
+ " cwd='/content/2d-gaussian-splatting',\n",
821
+ " capture_output=True,\n",
822
+ " text=True\n",
823
+ ")\n",
824
+ "\n",
825
+ "print(\"=== STDOUT ===\")\n",
826
+ "print(result.stdout)\n",
827
+ "print(\"\\n=== STDERR ===\")\n",
828
+ "print(result.stderr)\n",
829
+ "print(f\"\\n=== EXIT CODE: {result.returncode} ===\")"
830
+ ],
831
+ "metadata": {
832
+ "colab": {
833
+ "base_uri": "https://localhost:8080/"
834
+ },
835
+ "id": "vRxNgRnypv0l",
836
+ "outputId": "80d48d2c-7fe5-42af-932c-10ef9e9dffb2"
837
+ },
838
+ "id": "vRxNgRnypv0l",
839
+ "execution_count": 39,
840
+ "outputs": [
841
+ {
842
+ "output_type": "stream",
843
+ "name": "stdout",
844
+ "text": [
845
+ "=== STDOUT ===\n",
846
+ "\n",
847
+ "\n",
848
+ "=== STDERR ===\n",
849
+ "Traceback (most recent call last):\n",
850
+ " File \"/content/2d-gaussian-splatting/render.py\", line 23, in <module>\n",
851
+ " from utils.mesh_utils import GaussianExtractor, to_cam_open3d, post_process_mesh\n",
852
+ " File \"/content/2d-gaussian-splatting/utils/mesh_utils.py\", line 20, in <module>\n",
853
+ " import trimesh\n",
854
+ "ModuleNotFoundError: No module named 'trimesh'\n",
855
+ "\n",
856
+ "\n",
857
+ "=== EXIT CODE: 1 ===\n"
858
+ ]
859
+ }
860
+ ]
861
+ },
862
+ {
863
+ "cell_type": "code",
864
+ "source": [],
865
+ "metadata": {
866
+ "id": "1W62vlfhe9TS"
867
+ },
868
+ "id": "1W62vlfhe9TS",
869
+ "execution_count": 39,
870
+ "outputs": []
871
+ },
872
+ {
873
+ "cell_type": "code",
874
+ "source": [
875
+ "!nvcc --version\n",
876
+ "import torch\n",
877
+ "print(torch.__version__)\n",
878
+ "print(torch.version.cuda)"
879
+ ],
880
+ "metadata": {
881
+ "id": "Ev9PEUdtpEAx",
882
+ "colab": {
883
+ "base_uri": "https://localhost:8080/"
884
+ },
885
+ "outputId": "e858fa2e-eb9a-4814-f5f5-de8173bf8cdb"
886
+ },
887
+ "id": "Ev9PEUdtpEAx",
888
+ "execution_count": 40,
889
+ "outputs": [
890
+ {
891
+ "output_type": "stream",
892
+ "name": "stdout",
893
+ "text": [
894
+ "nvcc: NVIDIA (R) Cuda compiler driver\n",
895
+ "Copyright (c) 2005-2025 NVIDIA Corporation\n",
896
+ "Built on Fri_Feb_21_20:23:50_PST_2025\n",
897
+ "Cuda compilation tools, release 12.8, V12.8.93\n",
898
+ "Build cuda_12.8.r12.8/compiler.35583870_0\n",
899
+ "2.9.0+cu128\n",
900
+ "12.8\n"
901
+ ]
902
+ }
903
+ ]
904
+ },
905
+ {
906
+ "cell_type": "code",
907
+ "execution_count": 41,
908
+ "id": "b8690389",
909
+ "metadata": {
910
+ "execution": {
911
+ "iopub.execute_input": "2026-01-10T18:22:43.739411Z",
912
+ "iopub.status.busy": "2026-01-10T18:22:43.738855Z",
913
+ "iopub.status.idle": "2026-01-10T18:22:43.755664Z",
914
+ "shell.execute_reply": "2026-01-10T18:22:43.754865Z"
915
+ },
916
+ "papermill": {
917
+ "duration": 0.027297,
918
+ "end_time": "2026-01-10T18:22:43.756758",
919
+ "exception": false,
920
+ "start_time": "2026-01-10T18:22:43.729461",
921
+ "status": "completed"
922
+ },
923
+ "tags": [],
924
+ "id": "b8690389"
925
+ },
926
+ "outputs": [],
927
+ "source": [
928
+ "import os\n",
929
+ "import glob\n",
930
+ "import cv2\n",
931
+ "import numpy as np\n",
932
+ "from PIL import Image\n",
933
+ "\n",
934
+ "# =========================================================\n",
935
+ "# Utility: aspect ratio preserved + black padding\n",
936
+ "# =========================================================\n",
937
+ "\n",
938
+ "def normalize_image_sizes_biplet(input_dir, output_dir=None, size=1024, max_images=None):\n",
939
+ " \"\"\"\n",
940
+ " Generates two square crops (Left & Right or Top & Bottom)\n",
941
+ " from each image in a directory and returns the output directory\n",
942
+ " and the list of generated file paths.\n",
943
+ "\n",
944
+ " Args:\n",
945
+ " input_dir: Input directory containing source images\n",
946
+ " output_dir: Output directory for processed images\n",
947
+ " size: Target square size (default: 1024)\n",
948
+ " max_images: Maximum number of SOURCE images to process (default: None = all images)\n",
949
+ " \"\"\"\n",
950
+ " if output_dir is None:\n",
951
+ " output_dir = 'output/images_biplet'\n",
952
+ " os.makedirs(output_dir, exist_ok=True)\n",
953
+ "\n",
954
+ " print(f\"--- Step 1: Biplet-Square Normalization ---\")\n",
955
+ " print(f\"Generating 2 cropped squares (Left/Right or Top/Bottom) for each image...\")\n",
956
+ " print()\n",
957
+ "\n",
958
+ " generated_paths = []\n",
959
+ " converted_count = 0\n",
960
+ " size_stats = {}\n",
961
+ "\n",
962
+ " # Sort for consistent processing order\n",
963
+ " image_files = sorted([f for f in os.listdir(input_dir)\n",
964
+ " if f.lower().endswith(('.jpg', '.jpeg', '.png'))])\n",
965
+ "\n",
966
+ " # โ˜… max_images ใงๅ…ƒ็”ปๅƒๆ•ฐใ‚’ๅˆถ้™\n",
967
+ " if max_images is not None:\n",
968
+ " image_files = image_files[:max_images]\n",
969
+ " print(f\"Processing limited to {max_images} source images (will generate {max_images * 2} cropped images)\")\n",
970
+ "\n",
971
+ " for img_file in image_files:\n",
972
+ " input_path = os.path.join(input_dir, img_file)\n",
973
+ " try:\n",
974
+ " img = Image.open(input_path)\n",
975
+ " original_size = img.size\n",
976
+ "\n",
977
+ " # Tracking original aspect ratios\n",
978
+ " size_key = f\"{original_size[0]}x{original_size[1]}\"\n",
979
+ " size_stats[size_key] = size_stats.get(size_key, 0) + 1\n",
980
+ "\n",
981
+ " # Generate 2 crops using the helper function\n",
982
+ " crops = generate_two_crops(img, size)\n",
983
+ " base_name, ext = os.path.splitext(img_file)\n",
984
+ "\n",
985
+ " for mode, cropped_img in crops.items():\n",
986
+ " output_path = os.path.join(output_dir, f\"{base_name}_{mode}{ext}\")\n",
987
+ " cropped_img.save(output_path, quality=95)\n",
988
+ " generated_paths.append(output_path)\n",
989
+ "\n",
990
+ " converted_count += 1\n",
991
+ " print(f\" โœ“ {img_file}: {original_size} โ†’ 2 square images generated\")\n",
992
+ "\n",
993
+ " except Exception as e:\n",
994
+ " print(f\" โœ— Error processing {img_file}: {e}\")\n",
995
+ "\n",
996
+ " print(f\"\\nProcessing complete: {converted_count} source images processed\")\n",
997
+ " print(f\"Total output images: {len(generated_paths)}\")\n",
998
+ " print(f\"Original size distribution: {size_stats}\")\n",
999
+ "\n",
1000
+ " return output_dir, generated_paths\n",
1001
+ "\n",
1002
+ "\n",
1003
+ "def generate_two_crops(img, size):\n",
1004
+ " \"\"\"\n",
1005
+ " Crops the image into a square and returns 2 variations\n",
1006
+ " (Left/Right for landscape, Top/Bottom for portrait).\n",
1007
+ " \"\"\"\n",
1008
+ " width, height = img.size\n",
1009
+ " crop_size = min(width, height)\n",
1010
+ " crops = {}\n",
1011
+ "\n",
1012
+ " if width > height:\n",
1013
+ " # Landscape โ†’ Left & Right\n",
1014
+ " positions = {\n",
1015
+ " 'left': 0,\n",
1016
+ " 'right': width - crop_size\n",
1017
+ " }\n",
1018
+ " for mode, x_offset in positions.items():\n",
1019
+ " box = (x_offset, 0, x_offset + crop_size, crop_size)\n",
1020
+ " crops[mode] = img.crop(box).resize(\n",
1021
+ " (size, size),\n",
1022
+ " Image.Resampling.LANCZOS\n",
1023
+ " )\n",
1024
+ "\n",
1025
+ " else:\n",
1026
+ " # Portrait or Square โ†’ Top & Bottom\n",
1027
+ " positions = {\n",
1028
+ " 'top': 0,\n",
1029
+ " 'bottom': height - crop_size\n",
1030
+ " }\n",
1031
+ " for mode, y_offset in positions.items():\n",
1032
+ " box = (0, y_offset, crop_size, y_offset + crop_size)\n",
1033
+ " crops[mode] = img.crop(box).resize(\n",
1034
+ " (size, size),\n",
1035
+ " Image.Resampling.LANCZOS\n",
1036
+ " )\n",
1037
+ "\n",
1038
+ " return crops\n"
1039
+ ]
1040
+ },
1041
+ {
1042
+ "cell_type": "code",
1043
+ "execution_count": 42,
1044
+ "id": "7acc20b6",
1045
+ "metadata": {
1046
+ "execution": {
1047
+ "iopub.execute_input": "2026-01-10T18:22:43.772525Z",
1048
+ "iopub.status.busy": "2026-01-10T18:22:43.772303Z",
1049
+ "iopub.status.idle": "2026-01-10T18:22:43.790574Z",
1050
+ "shell.execute_reply": "2026-01-10T18:22:43.789515Z"
1051
+ },
1052
+ "papermill": {
1053
+ "duration": 0.027612,
1054
+ "end_time": "2026-01-10T18:22:43.791681",
1055
+ "exception": false,
1056
+ "start_time": "2026-01-10T18:22:43.764069",
1057
+ "status": "completed"
1058
+ },
1059
+ "tags": [],
1060
+ "id": "7acc20b6"
1061
+ },
1062
+ "outputs": [],
1063
+ "source": [
1064
+ "def run_colmap_reconstruction(image_dir, colmap_dir):\n",
1065
+ " \"\"\"Estimate camera poses and 3D point cloud with COLMAP\"\"\"\n",
1066
+ " print(\"Running SfM reconstruction with COLMAP...\")\n",
1067
+ "\n",
1068
+ " database_path = os.path.join(colmap_dir, \"database.db\")\n",
1069
+ " sparse_dir = os.path.join(colmap_dir, \"sparse\")\n",
1070
+ " os.makedirs(sparse_dir, exist_ok=True)\n",
1071
+ "\n",
1072
+ " # Set environment variable\n",
1073
+ " env = os.environ.copy()\n",
1074
+ " env['QT_QPA_PLATFORM'] = 'offscreen'\n",
1075
+ "\n",
1076
+ " # Feature extraction\n",
1077
+ " print(\"1/4: Extracting features...\")\n",
1078
+ " subprocess.run([\n",
1079
+ " 'colmap', 'feature_extractor',\n",
1080
+ " '--database_path', database_path,\n",
1081
+ " '--image_path', image_dir,\n",
1082
+ " '--ImageReader.single_camera', '1',\n",
1083
+ " '--ImageReader.camera_model', 'OPENCV',\n",
1084
+ " '--SiftExtraction.use_gpu', '0' # Use CPU\n",
1085
+ " ], check=True, env=env)\n",
1086
+ "\n",
1087
+ " # Feature matching\n",
1088
+ " print(\"2/4: Matching features...\")\n",
1089
+ " subprocess.run([\n",
1090
+ " 'colmap', 'exhaustive_matcher', # Use sequential_matcher instead of exhaustive_matcher\n",
1091
+ " '--database_path', database_path,\n",
1092
+ " '--SiftMatching.use_gpu', '0' # Use CPU\n",
1093
+ " ], check=True, env=env)\n",
1094
+ "\n",
1095
+ " # Sparse reconstruction\n",
1096
+ " print(\"3/4: Sparse reconstruction...\")\n",
1097
+ " subprocess.run([\n",
1098
+ " 'colmap', 'mapper',\n",
1099
+ " '--database_path', database_path,\n",
1100
+ " '--image_path', image_dir,\n",
1101
+ " '--output_path', sparse_dir,\n",
1102
+ " '--Mapper.ba_global_max_num_iterations', '20', # Speed up\n",
1103
+ " '--Mapper.ba_local_max_num_iterations', '10'\n",
1104
+ " ], check=True, env=env)\n",
1105
+ "\n",
1106
+ " # Export to text format\n",
1107
+ " print(\"4/4: Exporting to text format...\")\n",
1108
+ " model_dir = os.path.join(sparse_dir, '0')\n",
1109
+ " if not os.path.exists(model_dir):\n",
1110
+ " # Use the first model found\n",
1111
+ " subdirs = [d for d in os.listdir(sparse_dir) if os.path.isdir(os.path.join(sparse_dir, d))]\n",
1112
+ " if subdirs:\n",
1113
+ " model_dir = os.path.join(sparse_dir, subdirs[0])\n",
1114
+ " else:\n",
1115
+ " raise FileNotFoundError(\"COLMAP reconstruction failed\")\n",
1116
+ "\n",
1117
+ " subprocess.run([\n",
1118
+ " 'colmap', 'model_converter',\n",
1119
+ " '--input_path', model_dir,\n",
1120
+ " '--output_path', model_dir,\n",
1121
+ " '--output_type', 'TXT'\n",
1122
+ " ], check=True, env=env)\n",
1123
+ "\n",
1124
+ " print(f\"COLMAP reconstruction complete: {model_dir}\")\n",
1125
+ " return model_dir\n",
1126
+ "\n",
1127
+ "\n",
1128
+ "def convert_cameras_to_pinhole(input_file, output_file):\n",
1129
+ " \"\"\"Convert camera model to PINHOLE format\"\"\"\n",
1130
+ " print(f\"Reading camera file: {input_file}\")\n",
1131
+ "\n",
1132
+ " with open(input_file, 'r') as f:\n",
1133
+ " lines = f.readlines()\n",
1134
+ "\n",
1135
+ " converted_count = 0\n",
1136
+ " with open(output_file, 'w') as f:\n",
1137
+ " for line in lines:\n",
1138
+ " if line.startswith('#') or line.strip() == '':\n",
1139
+ " f.write(line)\n",
1140
+ " else:\n",
1141
+ " parts = line.strip().split()\n",
1142
+ " if len(parts) >= 4:\n",
1143
+ " cam_id = parts[0]\n",
1144
+ " model = parts[1]\n",
1145
+ " width = parts[2]\n",
1146
+ " height = parts[3]\n",
1147
+ " params = parts[4:]\n",
1148
+ "\n",
1149
+ " # Convert to PINHOLE format\n",
1150
+ " if model == \"PINHOLE\":\n",
1151
+ " f.write(line)\n",
1152
+ " elif model == \"OPENCV\":\n",
1153
+ " # OPENCV: fx, fy, cx, cy, k1, k2, p1, p2\n",
1154
+ " fx = params[0]\n",
1155
+ " fy = params[1]\n",
1156
+ " cx = params[2]\n",
1157
+ " cy = params[3]\n",
1158
+ " f.write(f\"{cam_id} PINHOLE {width} {height} {fx} {fy} {cx} {cy}\\n\")\n",
1159
+ " converted_count += 1\n",
1160
+ " else:\n",
1161
+ " # Convert other models too\n",
1162
+ " fx = fy = max(float(width), float(height))\n",
1163
+ " cx = float(width) / 2\n",
1164
+ " cy = float(height) / 2\n",
1165
+ " f.write(f\"{cam_id} PINHOLE {width} {height} {fx} {fy} {cx} {cy}\\n\")\n",
1166
+ " converted_count += 1\n",
1167
+ " else:\n",
1168
+ " f.write(line)\n",
1169
+ "\n",
1170
+ " print(f\"Converted {converted_count} cameras to PINHOLE format\")\n",
1171
+ "\n",
1172
+ "\n",
1173
+ "def prepare_gaussian_splatting_data(image_dir, colmap_model_dir):\n",
1174
+ " \"\"\"Prepare data for Gaussian Splatting\"\"\"\n",
1175
+ " print(\"Preparing data for Gaussian Splatting...\")\n",
1176
+ "\n",
1177
+ " data_dir = f\"{WORK_DIR}/data/video\"\n",
1178
+ " os.makedirs(f\"{data_dir}/sparse/0\", exist_ok=True)\n",
1179
+ " os.makedirs(f\"{data_dir}/images\", exist_ok=True)\n",
1180
+ "\n",
1181
+ " # Copy images\n",
1182
+ " print(\"Copying images...\")\n",
1183
+ " img_count = 0\n",
1184
+ " for img_file in os.listdir(image_dir):\n",
1185
+ " if img_file.lower().endswith(('.jpg', '.jpeg', '.png')):\n",
1186
+ " shutil.copy(\n",
1187
+ " os.path.join(image_dir, img_file),\n",
1188
+ " f\"{data_dir}/images/{img_file}\"\n",
1189
+ " )\n",
1190
+ " img_count += 1\n",
1191
+ " print(f\"Copied {img_count} images\")\n",
1192
+ "\n",
1193
+ " # Convert and copy camera file to PINHOLE format\n",
1194
+ " print(\"Converting camera model to PINHOLE format...\")\n",
1195
+ " convert_cameras_to_pinhole(\n",
1196
+ " os.path.join(colmap_model_dir, 'cameras.txt'),\n",
1197
+ " f\"{data_dir}/sparse/0/cameras.txt\"\n",
1198
+ " )\n",
1199
+ "\n",
1200
+ " # Copy other files\n",
1201
+ " for filename in ['images.txt', 'points3D.txt']:\n",
1202
+ " src = os.path.join(colmap_model_dir, filename)\n",
1203
+ " dst = f\"{data_dir}/sparse/0/{filename}\"\n",
1204
+ " if os.path.exists(src):\n",
1205
+ " shutil.copy(src, dst)\n",
1206
+ " print(f\"Copied {filename}\")\n",
1207
+ " else:\n",
1208
+ " print(f\"Warning: {filename} not found\")\n",
1209
+ "\n",
1210
+ " print(f\"Data preparation complete: {data_dir}\")\n",
1211
+ " return data_dir\n",
1212
+ "\n",
1213
+ "def run_colmap_reconstruction(image_dir, colmap_dir):\n",
1214
+ " \"\"\"Estimate camera poses and 3D point cloud with COLMAP\"\"\"\n",
1215
+ " print(\"Running SfM reconstruction with COLMAP...\")\n",
1216
+ "\n",
1217
+ " database_path = os.path.join(colmap_dir, \"database.db\")\n",
1218
+ " sparse_dir = os.path.join(colmap_dir, \"sparse\")\n",
1219
+ " os.makedirs(sparse_dir, exist_ok=True)\n",
1220
+ "\n",
1221
+ " # Set environment variable\n",
1222
+ " env = os.environ.copy()\n",
1223
+ " env['QT_QPA_PLATFORM'] = 'offscreen'\n",
1224
+ "\n",
1225
+ " # Feature extraction\n",
1226
+ " print(\"1/4: Extracting features...\")\n",
1227
+ " subprocess.run([\n",
1228
+ " 'colmap', 'feature_extractor',\n",
1229
+ " '--database_path', database_path,\n",
1230
+ " '--image_path', image_dir,\n",
1231
+ " '--ImageReader.single_camera', '1',\n",
1232
+ " '--ImageReader.camera_model', 'OPENCV',\n",
1233
+ " '--SiftExtraction.use_gpu', '0' # Use CPU\n",
1234
+ " ], check=True, env=env)\n",
1235
+ "\n",
1236
+ " # Feature matching\n",
1237
+ " print(\"2/4: Matching features...\")\n",
1238
+ " subprocess.run([\n",
1239
+ " 'colmap', 'exhaustive_matcher', # Use sequential_matcher instead of exhaustive_matcher\n",
1240
+ " '--database_path', database_path,\n",
1241
+ " '--SiftMatching.use_gpu', '0' # Use CPU\n",
1242
+ " ], check=True, env=env)\n",
1243
+ "\n",
1244
+ " # Sparse reconstruction\n",
1245
+ " print(\"3/4: Sparse reconstruction...\")\n",
1246
+ " subprocess.run([\n",
1247
+ " 'colmap', 'mapper',\n",
1248
+ " '--database_path', database_path,\n",
1249
+ " '--image_path', image_dir,\n",
1250
+ " '--output_path', sparse_dir,\n",
1251
+ " '--Mapper.ba_global_max_num_iterations', '20', # Speed up\n",
1252
+ " '--Mapper.ba_local_max_num_iterations', '10'\n",
1253
+ " ], check=True, env=env)\n",
1254
+ "\n",
1255
+ " # Export to text format\n",
1256
+ " print(\"4/4: Exporting to text format...\")\n",
1257
+ " model_dir = os.path.join(sparse_dir, '0')\n",
1258
+ " if not os.path.exists(model_dir):\n",
1259
+ " # Use the first model found\n",
1260
+ " subdirs = [d for d in os.listdir(sparse_dir) if os.path.isdir(os.path.join(sparse_dir, d))]\n",
1261
+ " if subdirs:\n",
1262
+ " model_dir = os.path.join(sparse_dir, subdirs[0])\n",
1263
+ " else:\n",
1264
+ " raise FileNotFoundError(\"COLMAP reconstruction failed\")\n",
1265
+ "\n",
1266
+ " subprocess.run([\n",
1267
+ " 'colmap', 'model_converter',\n",
1268
+ " '--input_path', model_dir,\n",
1269
+ " '--output_path', model_dir,\n",
1270
+ " '--output_type', 'TXT'\n",
1271
+ " ], check=True, env=env)\n",
1272
+ "\n",
1273
+ " print(f\"COLMAP reconstruction complete: {model_dir}\")\n",
1274
+ " return model_dir\n",
1275
+ "\n",
1276
+ "\n",
1277
+ "def convert_cameras_to_pinhole(input_file, output_file):\n",
1278
+ " \"\"\"Convert camera model to PINHOLE format\"\"\"\n",
1279
+ " print(f\"Reading camera file: {input_file}\")\n",
1280
+ "\n",
1281
+ " with open(input_file, 'r') as f:\n",
1282
+ " lines = f.readlines()\n",
1283
+ "\n",
1284
+ " converted_count = 0\n",
1285
+ " with open(output_file, 'w') as f:\n",
1286
+ " for line in lines:\n",
1287
+ " if line.startswith('#') or line.strip() == '':\n",
1288
+ " f.write(line)\n",
1289
+ " else:\n",
1290
+ " parts = line.strip().split()\n",
1291
+ " if len(parts) >= 4:\n",
1292
+ " cam_id = parts[0]\n",
1293
+ " model = parts[1]\n",
1294
+ " width = parts[2]\n",
1295
+ " height = parts[3]\n",
1296
+ " params = parts[4:]\n",
1297
+ "\n",
1298
+ " # Convert to PINHOLE format\n",
1299
+ " if model == \"PINHOLE\":\n",
1300
+ " f.write(line)\n",
1301
+ " elif model == \"OPENCV\":\n",
1302
+ " # OPENCV: fx, fy, cx, cy, k1, k2, p1, p2\n",
1303
+ " fx = params[0]\n",
1304
+ " fy = params[1]\n",
1305
+ " cx = params[2]\n",
1306
+ " cy = params[3]\n",
1307
+ " f.write(f\"{cam_id} PINHOLE {width} {height} {fx} {fy} {cx} {cy}\\n\")\n",
1308
+ " converted_count += 1\n",
1309
+ " else:\n",
1310
+ " # Convert other models too\n",
1311
+ " fx = fy = max(float(width), float(height))\n",
1312
+ " cx = float(width) / 2\n",
1313
+ " cy = float(height) / 2\n",
1314
+ " f.write(f\"{cam_id} PINHOLE {width} {height} {fx} {fy} {cx} {cy}\\n\")\n",
1315
+ " converted_count += 1\n",
1316
+ " else:\n",
1317
+ " f.write(line)\n",
1318
+ "\n",
1319
+ " print(f\"Converted {converted_count} cameras to PINHOLE format\")\n",
1320
+ "\n",
1321
+ "\n",
1322
+ "def prepare_gaussian_splatting_data(image_dir, colmap_model_dir):\n",
1323
+ " \"\"\"Prepare data for Gaussian Splatting\"\"\"\n",
1324
+ " print(\"Preparing data for Gaussian Splatting...\")\n",
1325
+ "\n",
1326
+ " data_dir = f\"{WORK_DIR}/data/video\"\n",
1327
+ " os.makedirs(f\"{data_dir}/sparse/0\", exist_ok=True)\n",
1328
+ " os.makedirs(f\"{data_dir}/images\", exist_ok=True)\n",
1329
+ "\n",
1330
+ " # Copy images\n",
1331
+ " print(\"Copying images...\")\n",
1332
+ " img_count = 0\n",
1333
+ " for img_file in os.listdir(image_dir):\n",
1334
+ " if img_file.lower().endswith(('.jpg', '.jpeg', '.png')):\n",
1335
+ " shutil.copy(\n",
1336
+ " os.path.join(image_dir, img_file),\n",
1337
+ " f\"{data_dir}/images/{img_file}\"\n",
1338
+ " )\n",
1339
+ " img_count += 1\n",
1340
+ " print(f\"Copied {img_count} images\")\n",
1341
+ "\n",
1342
+ " # Convert and copy camera file to PINHOLE format\n",
1343
+ " print(\"Converting camera model to PINHOLE format...\")\n",
1344
+ " convert_cameras_to_pinhole(\n",
1345
+ " os.path.join(colmap_model_dir, 'cameras.txt'),\n",
1346
+ " f\"{data_dir}/sparse/0/cameras.txt\"\n",
1347
+ " )\n",
1348
+ "\n",
1349
+ " # Copy other files\n",
1350
+ " for filename in ['images.txt', 'points3D.txt']:\n",
1351
+ " src = os.path.join(colmap_model_dir, filename)\n",
1352
+ " dst = f\"{data_dir}/sparse/0/{filename}\"\n",
1353
+ " if os.path.exists(src):\n",
1354
+ " shutil.copy(src, dst)\n",
1355
+ " print(f\"Copied {filename}\")\n",
1356
+ " else:\n",
1357
+ " print(f\"Warning: {filename} not found\")\n",
1358
+ "\n",
1359
+ " print(f\"Data preparation complete: {data_dir}\")\n",
1360
+ " return data_dir\n",
1361
+ "\n",
1362
+ "\n",
1363
+ "\n",
1364
+ "###############################################################\n",
1365
+ "\n",
1366
+ "# ๅค‰ๆ›ดๅพŒ (2DGS) - ๆญฃๅ‰‡ๅŒ–ใƒ‘ใƒฉใƒกใƒผใ‚ฟใ‚’่ฟฝๅŠ \n",
1367
+ "def train_gaussian_splatting(data_dir, iterations=7000,\n",
1368
+ " lambda_normal=0.05,\n",
1369
+ " lambda_dist=0, # โ† distortion โ†’ dist ใซไฟฎๆญฃ\n",
1370
+ " depth_ratio=0):\n",
1371
+ " \"\"\"\n",
1372
+ " 2DGS็”จใฎใƒˆใƒฌใƒผใƒ‹ใƒณใ‚ฐ้–ขๆ•ฐ\n",
1373
+ " Args:\n",
1374
+ " lambda_normal: ๆณ•็ทšไธ€่ฒซๆ€งใฎ้‡ใฟ (ใƒ‡ใƒ•ใ‚ฉใƒซใƒˆ: 0.05)\n",
1375
+ " lambda_dist: ๆทฑๅบฆๆญชใฟใฎ้‡ใฟ (ใƒ‡ใƒ•ใ‚ฉใƒซใƒˆ: 0) # โ† ๅๅ‰ไฟฎๆญฃ\n",
1376
+ " depth_ratio: 0=ๅนณๅ‡ๆทฑๅบฆ, 1=ไธญๅคฎๅ€คๆทฑๅบฆ (ใƒ‡ใƒ•ใ‚ฉใƒซใƒˆ: 0)\n",
1377
+ " \"\"\"\n",
1378
+ " model_path = f\"{WORK_DIR}/output/video\"\n",
1379
+ " cmd = [\n",
1380
+ " sys.executable, 'train.py',\n",
1381
+ " '-s', data_dir,\n",
1382
+ " '-m', model_path,\n",
1383
+ " '--iterations', str(iterations),\n",
1384
+ " '--lambda_normal', str(lambda_normal),\n",
1385
+ " '--lambda_dist', str(lambda_dist), # โ† ใ“ใ“ใ‚’ไฟฎๆญฃ๏ผ\n",
1386
+ " '--depth_ratio', str(depth_ratio),\n",
1387
+ " '--eval'\n",
1388
+ " ]\n",
1389
+ " subprocess.run(cmd, cwd=WORK_DIR, check=True)\n",
1390
+ " return model_path\n",
1391
+ "\n",
1392
+ "\n",
1393
+ "\n",
1394
+ "# 2DGSใงใฏใƒกใƒƒใ‚ทใƒฅๆŠฝๅ‡บใ‚ชใƒ—ใ‚ทใƒงใƒณใŒ่ฟฝๅŠ ใ•ใ‚Œใฆใ„ใพใ™\n",
1395
+ "def render_video_and_mesh(model_path, output_video_path, iteration=1000,\n",
1396
+ " extract_mesh=False, unbounded=False, mesh_res=1024):\n",
1397
+ " \"\"\"\n",
1398
+ " 2DGS็”จใฎใƒฌใƒณใƒ€ใƒชใƒณใ‚ฐใจใƒกใƒƒใ‚ทใƒฅๆŠฝๅ‡บ\n",
1399
+ " Args:\n",
1400
+ " extract_mesh: ใƒกใƒƒใ‚ทใƒฅใ‚’ๆŠฝๅ‡บใ™ใ‚‹ใ‹ (ใƒ‡ใƒ•ใ‚ฉใƒซใƒˆ: Falseใ€ๅ‹•็”ปใฎใฟ)\n",
1401
+ " unbounded: ๅขƒ็•Œใชใ—ใƒกใƒƒใ‚ทใƒฅๆŠฝๅ‡บใ‚’ไฝฟ็”จใ™ใ‚‹ใ‹\n",
1402
+ " mesh_res: ใƒกใƒƒใ‚ทใƒฅ่งฃๅƒๅบฆ\n",
1403
+ " \"\"\"\n",
1404
+ " # ้€šๅธธใฎใƒฌใƒณใƒ€ใƒชใƒณใ‚ฐ\n",
1405
+ " cmd = [\n",
1406
+ " sys.executable, 'render.py',\n",
1407
+ " '-m', model_path,\n",
1408
+ " '--iteration', str(iteration),\n",
1409
+ " '--skip_test',\n",
1410
+ " '--skip_train'\n",
1411
+ " ]\n",
1412
+ "\n",
1413
+ " # ใƒกใƒƒใ‚ทใƒฅๆŠฝๅ‡บใ‚ชใƒ—ใ‚ทใƒงใƒณ๏ผˆๅฟ…่ฆใชๅ ดๅˆใฎใฟ๏ผ‰\n",
1414
+ " if extract_mesh:\n",
1415
+ " if unbounded:\n",
1416
+ " cmd.extend(['--unbounded'])\n",
1417
+ " cmd.extend(['--mesh_res', str(mesh_res)])\n",
1418
+ "\n",
1419
+ " # ใ‚จใƒฉใƒผ่ฉณ็ดฐใ‚’ใ‚ญใƒฃใƒ—ใƒใƒฃ\n",
1420
+ " result = subprocess.run(\n",
1421
+ " cmd,\n",
1422
+ " cwd=WORK_DIR,\n",
1423
+ " capture_output=True,\n",
1424
+ " text=True\n",
1425
+ " )\n",
1426
+ "\n",
1427
+ " if result.returncode != 0:\n",
1428
+ " print(\"โŒ STDOUT:\", result.stdout)\n",
1429
+ " print(\"โŒ STDERR:\", result.stderr)\n",
1430
+ " raise subprocess.CalledProcessError(\n",
1431
+ " result.returncode, cmd, result.stdout, result.stderr\n",
1432
+ " )\n",
1433
+ "\n",
1434
+ " # ใƒฌใƒณใƒ€ใƒชใƒณใ‚ฐ็ตๆžœใ‹ใ‚‰ใƒ“ใƒ‡ใ‚ชไฝœๆˆ\n",
1435
+ " possible_dirs = [\n",
1436
+ " f\"{model_path}/test/ours_{iteration}/renders\",\n",
1437
+ " f\"{model_path}/train/ours_{iteration}/renders\",\n",
1438
+ " ]\n",
1439
+ "\n",
1440
+ " render_dir = None\n",
1441
+ " for test_dir in possible_dirs:\n",
1442
+ " if os.path.exists(test_dir):\n",
1443
+ " render_dir = test_dir\n",
1444
+ " print(f\"โœ… Rendering directory found: {render_dir}\")\n",
1445
+ " break\n",
1446
+ "\n",
1447
+ " if render_dir and os.path.exists(render_dir):\n",
1448
+ " render_imgs = sorted([f for f in os.listdir(render_dir)\n",
1449
+ " if f.endswith('.png')])\n",
1450
+ " if render_imgs:\n",
1451
+ " print(f\"Found {len(render_imgs)} rendered images\")\n",
1452
+ " # ffmpegใงใƒ“ใƒ‡ใ‚ชไฝœๆˆ\n",
1453
+ " subprocess.run([\n",
1454
+ " 'ffmpeg', '-y',\n",
1455
+ " '-framerate', '30',\n",
1456
+ " '-pattern_type', 'glob',\n",
1457
+ " '-i', f\"{render_dir}/*.png\",\n",
1458
+ " '-c:v', 'libx264',\n",
1459
+ " '-pix_fmt', 'yuv420p',\n",
1460
+ " '-crf', '18',\n",
1461
+ " output_video_path\n",
1462
+ " ], check=True)\n",
1463
+ " print(f\"โœ… Video saved: {output_video_path}\")\n",
1464
+ " return True\n",
1465
+ "\n",
1466
+ " print(\"โŒ Error: Rendering directory not found\")\n",
1467
+ " return False\n",
1468
+ "\n",
1469
+ "\n",
1470
+ "\n",
1471
+ "###############################################################\n",
1472
+ "\n",
1473
+ "\n",
1474
+ "def create_gif(video_path, gif_path):\n",
1475
+ " \"\"\"Create GIF from MP4\"\"\"\n",
1476
+ " print(\"Creating animated GIF...\")\n",
1477
+ "\n",
1478
+ " subprocess.run([\n",
1479
+ " 'ffmpeg', '-y',\n",
1480
+ " '-i', video_path,\n",
1481
+ " '-vf', 'setpts=8*PTS,fps=10,scale=720:-1:flags=lanczos',\n",
1482
+ " '-loop', '0',\n",
1483
+ " gif_path\n",
1484
+ " ], check=True)\n",
1485
+ "\n",
1486
+ " if os.path.exists(gif_path):\n",
1487
+ " size_mb = os.path.getsize(gif_path) / (1024 * 1024)\n",
1488
+ " print(f\"GIF creation complete: {gif_path} ({size_mb:.2f} MB)\")\n",
1489
+ " return True\n",
1490
+ "\n",
1491
+ " return False"
1492
+ ]
1493
+ },
1494
+ {
1495
+ "cell_type": "code",
1496
+ "source": [],
1497
+ "metadata": {
1498
+ "id": "YtqhBP4T3jEH"
1499
+ },
1500
+ "id": "YtqhBP4T3jEH",
1501
+ "execution_count": 42,
1502
+ "outputs": []
1503
+ },
1504
+ {
1505
+ "cell_type": "code",
1506
+ "source": [
1507
+ "def main_pipeline(image_dir, output_dir, square_size=1024, max_images=100):\n",
1508
+ " \"\"\"Main execution function\"\"\"\n",
1509
+ " try:\n",
1510
+ " # Step 1: ็”ปๅƒใฎๆญฃ่ฆๅŒ–ใจๅ‰ๅ‡ฆ็†\n",
1511
+ " print(\"=\"*60)\n",
1512
+ " print(\"Step 1: Normalizing and preprocessing images\")\n",
1513
+ " print(\"=\"*60)\n",
1514
+ "\n",
1515
+ " frame_dir = os.path.join(COLMAP_DIR, \"images\")\n",
1516
+ " os.makedirs(frame_dir, exist_ok=True)\n",
1517
+ "\n",
1518
+ " # ็”ปๅƒใ‚’ๆญฃ่ฆๅŒ–ใ—ใฆ็›ดๆŽฅCOLMAPใฎใƒ‡ใ‚ฃใƒฌใ‚ฏใƒˆใƒชใซไฟๅญ˜\n",
1519
+ " num_processed = normalize_image_sizes_biplet(\n",
1520
+ " input_dir=image_dir,\n",
1521
+ " output_dir=frame_dir, # ็›ดๆŽฅcolmap/imagesใซไฟๅญ˜\n",
1522
+ " size=square_size,\n",
1523
+ " max_images=max_images\n",
1524
+ " )\n",
1525
+ "\n",
1526
+ " print(f\"Processed {num_processed} images\")\n",
1527
+ "\n",
1528
+ " # Step 2: Estimate Camera Info with COLMAP\n",
1529
+ " print(\"=\"*60)\n",
1530
+ " print(\"Step 2: Running COLMAP reconstruction\")\n",
1531
+ " print(\"=\"*60)\n",
1532
+ " colmap_model_dir = run_colmap_reconstruction(frame_dir, COLMAP_DIR)\n",
1533
+ "\n",
1534
+ " # Step 3: Prepare Data for Gaussian Splatting\n",
1535
+ " print(\"=\"*60)\n",
1536
+ " print(\"Step 3: Preparing Gaussian Splatting data\")\n",
1537
+ " print(\"=\"*60)\n",
1538
+ " data_dir = prepare_gaussian_splatting_data(frame_dir, colmap_model_dir)\n",
1539
+ "\n",
1540
+ " # Step 4: Train Model\n",
1541
+ " print(\"=\"*60)\n",
1542
+ " print(\"Step 4: Training Gaussian Splatting model\")\n",
1543
+ " print(\"=\"*60)\n",
1544
+ " # ไฟฎๆญฃ: frame_dir โ†’ data_dir\n",
1545
+ "\n",
1546
+ " # main_pipelineๅ†…ใงๅ‘ผใณๅ‡บใ™้ƒจๅˆ†\n",
1547
+ " model_path = train_gaussian_splatting(\n",
1548
+ " data_dir,\n",
1549
+ " iterations=1000,\n",
1550
+ " lambda_normal=0.05,\n",
1551
+ " lambda_dist=0, # โ† distortion โ†’ dist ใซไฟฎๆญฃ\n",
1552
+ " depth_ratio=0\n",
1553
+ " )\n",
1554
+ "\n",
1555
+ " print(f\"Model trained at: {model_path}\")\n",
1556
+ "\n",
1557
+ " ############################################\n",
1558
+ "\n",
1559
+ " except Exception as e: # โ† ใ“ใ‚Œใ‚’่ฟฝๅŠ \n",
1560
+ " print(f\"โŒ Pipeline failed: {e}\")\n",
1561
+ " import traceback\n",
1562
+ " traceback.print_exc()\n",
1563
+ " return None\n",
1564
+ "\n",
1565
+ "\n",
1566
+ "if __name__ == \"__main__\":\n",
1567
+ " IMAGE_DIR = \"/content/drive/MyDrive/your_folder/fountain100\"\n",
1568
+ " OUTPUT_DIR = \"/content/output\"\n",
1569
+ " COLMAP_DIR = \"/content/colmap_workspace\"\n",
1570
+ "\n",
1571
+ " # ใ‚ทใƒณใƒ—ใƒซใซ1ใคใฎๆˆปใ‚Šๅ€คใ ใ‘\n",
1572
+ " ply_path = main_pipeline(\n",
1573
+ " image_dir=IMAGE_DIR,\n",
1574
+ " output_dir=OUTPUT_DIR,\n",
1575
+ " square_size=1024,\n",
1576
+ " max_images=20\n",
1577
+ " )\n",
1578
+ "\n",
1579
+ "\n"
1580
+ ],
1581
+ "metadata": {
1582
+ "id": "fya3kv62NXM-",
1583
+ "colab": {
1584
+ "base_uri": "https://localhost:8080/"
1585
+ },
1586
+ "outputId": "5f562d50-ffba-43df-b33d-c9a92d0383e7"
1587
+ },
1588
+ "id": "fya3kv62NXM-",
1589
+ "execution_count": 54,
1590
+ "outputs": [
1591
+ {
1592
+ "output_type": "stream",
1593
+ "name": "stdout",
1594
+ "text": [
1595
+ "============================================================\n",
1596
+ "Step 1: Normalizing and preprocessing images\n",
1597
+ "============================================================\n",
1598
+ "--- Step 1: Biplet-Square Normalization ---\n",
1599
+ "Generating 2 cropped squares (Left/Right or Top/Bottom) for each image...\n",
1600
+ "\n",
1601
+ "Processing limited to 20 source images (will generate 40 cropped images)\n",
1602
+ " โœ“ image_101.jpeg: (1440, 1920) โ†’ 2 square images generated\n",
1603
+ " โœ“ image_102.jpeg: (1440, 1920) โ†’ 2 square images generated\n",
1604
+ " โœ“ image_103.jpeg: (1440, 1920) โ†’ 2 square images generated\n",
1605
+ " โœ“ image_104.jpeg: (1440, 1920) โ†’ 2 square images generated\n",
1606
+ " โœ“ image_105.jpeg: (1440, 1920) โ†’ 2 square images generated\n",
1607
+ " โœ“ image_106.jpeg: (1440, 1920) โ†’ 2 square images generated\n",
1608
+ " โœ“ image_107.jpeg: (1440, 1920) โ†’ 2 square images generated\n",
1609
+ " โœ“ image_108.jpeg: (1440, 1920) โ†’ 2 square images generated\n",
1610
+ " โœ“ image_109.jpeg: (1440, 1920) โ†’ 2 square images generated\n",
1611
+ " โœ“ image_110.jpeg: (1440, 1920) โ†’ 2 square images generated\n",
1612
+ " โœ“ image_111.jpeg: (1440, 1920) โ†’ 2 square images generated\n",
1613
+ " โœ“ image_112.jpeg: (1440, 1920) โ†’ 2 square images generated\n",
1614
+ " โœ“ image_113.jpeg: (1440, 1920) โ†’ 2 square images generated\n",
1615
+ " โœ“ image_114.jpeg: (1440, 1920) โ†’ 2 square images generated\n",
1616
+ " โœ“ image_115.jpeg: (1440, 1920) โ†’ 2 square images generated\n",
1617
+ " โœ“ image_116.jpeg: (1440, 1920) โ†’ 2 square images generated\n",
1618
+ " โœ“ image_117.jpeg: (1440, 1920) โ†’ 2 square images generated\n",
1619
+ " โœ“ image_118.jpeg: (1440, 1920) โ†’ 2 square images generated\n",
1620
+ " โœ“ image_119.jpeg: (1440, 1920) โ†’ 2 square images generated\n",
1621
+ " โœ“ image_120.jpeg: (1440, 1920) โ†’ 2 square images generated\n",
1622
+ "\n",
1623
+ "Processing complete: 20 source images processed\n",
1624
+ "Total output images: 40\n",
1625
+ "Original size distribution: {'1440x1920': 20}\n",
1626
+ "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",
1627
+ "============================================================\n",
1628
+ "Step 2: Running COLMAP reconstruction\n",
1629
+ "============================================================\n",
1630
+ "Running SfM reconstruction with COLMAP...\n",
1631
+ "1/4: Extracting features...\n",
1632
+ "2/4: Matching features...\n",
1633
+ "3/4: Sparse reconstruction...\n",
1634
+ "4/4: Exporting to text format...\n",
1635
+ "COLMAP reconstruction complete: /content/colmap_workspace/sparse/0\n",
1636
+ "============================================================\n",
1637
+ "Step 3: Preparing Gaussian Splatting data\n",
1638
+ "============================================================\n",
1639
+ "Preparing data for Gaussian Splatting...\n",
1640
+ "Copying images...\n",
1641
+ "Copied 40 images\n",
1642
+ "Converting camera model to PINHOLE format...\n",
1643
+ "Reading camera file: /content/colmap_workspace/sparse/0/cameras.txt\n",
1644
+ "Converted 1 cameras to PINHOLE format\n",
1645
+ "Copied images.txt\n",
1646
+ "Copied points3D.txt\n",
1647
+ "Data preparation complete: /content/2d-gaussian-splatting/data/video\n",
1648
+ "============================================================\n",
1649
+ "Step 4: Training Gaussian Splatting model\n",
1650
+ "============================================================\n",
1651
+ "Model trained at: /content/2d-gaussian-splatting/output/video\n"
1652
+ ]
1653
+ }
1654
+ ]
1655
+ },
1656
+ {
1657
+ "cell_type": "code",
1658
+ "source": [],
1659
+ "metadata": {
1660
+ "id": "9GN6Eny2XsAd"
1661
+ },
1662
+ "id": "9GN6Eny2XsAd",
1663
+ "execution_count": 43,
1664
+ "outputs": []
1665
+ },
1666
+ {
1667
+ "cell_type": "markdown",
1668
+ "id": "e17ec719",
1669
+ "metadata": {
1670
+ "papermill": {
1671
+ "duration": 0.49801,
1672
+ "end_time": "2026-01-11T00:00:18.165833",
1673
+ "exception": false,
1674
+ "start_time": "2026-01-11T00:00:17.667823",
1675
+ "status": "completed"
1676
+ },
1677
+ "tags": [],
1678
+ "id": "e17ec719"
1679
+ },
1680
+ "source": []
1681
+ },
1682
+ {
1683
+ "cell_type": "markdown",
1684
+ "id": "38b3974c",
1685
+ "metadata": {
1686
+ "papermill": {
1687
+ "duration": 0.427583,
1688
+ "end_time": "2026-01-11T00:00:19.008387",
1689
+ "exception": false,
1690
+ "start_time": "2026-01-11T00:00:18.580804",
1691
+ "status": "completed"
1692
+ },
1693
+ "tags": [],
1694
+ "id": "38b3974c"
1695
+ },
1696
+ "source": []
1697
+ }
1698
+ ],
1699
+ "metadata": {
1700
+ "kaggle": {
1701
+ "accelerator": "nvidiaTeslaT4",
1702
+ "dataSources": [
1703
+ {
1704
+ "databundleVersionId": 5447706,
1705
+ "sourceId": 49349,
1706
+ "sourceType": "competition"
1707
+ },
1708
+ {
1709
+ "datasetId": 1429416,
1710
+ "sourceId": 14451718,
1711
+ "sourceType": "datasetVersion"
1712
+ }
1713
+ ],
1714
+ "dockerImageVersionId": 31090,
1715
+ "isGpuEnabled": true,
1716
+ "isInternetEnabled": true,
1717
+ "language": "python",
1718
+ "sourceType": "notebook"
1719
+ },
1720
+ "kernelspec": {
1721
+ "display_name": "Python 3",
1722
+ "name": "python3"
1723
+ },
1724
+ "language_info": {
1725
+ "codemirror_mode": {
1726
+ "name": "ipython",
1727
+ "version": 3
1728
+ },
1729
+ "file_extension": ".py",
1730
+ "mimetype": "text/x-python",
1731
+ "name": "python",
1732
+ "nbconvert_exporter": "python",
1733
+ "pygments_lexer": "ipython3",
1734
+ "version": "3.11.13"
1735
+ },
1736
+ "papermill": {
1737
+ "default_parameters": {},
1738
+ "duration": 20573.990788,
1739
+ "end_time": "2026-01-11T00:00:22.081506",
1740
+ "environment_variables": {},
1741
+ "exception": null,
1742
+ "input_path": "__notebook__.ipynb",
1743
+ "output_path": "__notebook__.ipynb",
1744
+ "parameters": {},
1745
+ "start_time": "2026-01-10T18:17:28.090718",
1746
+ "version": "2.6.0"
1747
+ },
1748
+ "colab": {
1749
+ "provenance": [],
1750
+ "gpuType": "T4"
1751
+ },
1752
+ "accelerator": "GPU"
1753
+ },
1754
+ "nbformat": 4,
1755
+ "nbformat_minor": 5
1756
+ }