stpete2 commited on
Commit
b71ff8f
·
verified ·
1 Parent(s): cd95934

Upload 2 files

Browse files
biplet_colmap_mipgs_colab_07.ipynb ADDED
@@ -0,0 +1,1028 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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-colmap-mipgs-colab-00**"
19
+ ]
20
+ },
21
+ {
22
+ "cell_type": "code",
23
+ "source": [
24
+ "#サイズの異なる画像を扱う\n",
25
+ "from google.colab import drive\n",
26
+ "drive.mount('/content/drive')"
27
+ ],
28
+ "metadata": {
29
+ "colab": {
30
+ "base_uri": "https://localhost:8080/"
31
+ },
32
+ "id": "JON4rYSEOzCg",
33
+ "outputId": "26faa569-d3de-41d3-be2f-fbf38d363f7a"
34
+ },
35
+ "id": "JON4rYSEOzCg",
36
+ "execution_count": 3,
37
+ "outputs": [
38
+ {
39
+ "output_type": "stream",
40
+ "name": "stdout",
41
+ "text": [
42
+ "Mounted at /content/drive\n"
43
+ ]
44
+ }
45
+ ]
46
+ },
47
+ {
48
+ "cell_type": "code",
49
+ "execution_count": 4,
50
+ "id": "22353010",
51
+ "metadata": {
52
+ "execution": {
53
+ "iopub.execute_input": "2026-01-10T18:17:32.181455Z",
54
+ "iopub.status.busy": "2026-01-10T18:17:32.180969Z",
55
+ "iopub.status.idle": "2026-01-10T18:17:32.355942Z",
56
+ "shell.execute_reply": "2026-01-10T18:17:32.355229Z"
57
+ },
58
+ "papermill": {
59
+ "duration": 0.179454,
60
+ "end_time": "2026-01-10T18:17:32.357275",
61
+ "exception": false,
62
+ "start_time": "2026-01-10T18:17:32.177821",
63
+ "status": "completed"
64
+ },
65
+ "tags": [],
66
+ "id": "22353010"
67
+ },
68
+ "outputs": [],
69
+ "source": [
70
+ "import os\n",
71
+ "import sys\n",
72
+ "import subprocess\n",
73
+ "import shutil\n",
74
+ "from pathlib import Path\n",
75
+ "import cv2\n",
76
+ "from PIL import Image\n",
77
+ "import glob\n",
78
+ "\n",
79
+ "IMAGE_PATH=\"/content/drive/MyDrive/your_folder/fountain100\"\n",
80
+ "WORK_DIR = '/content/mip-splatting'\n",
81
+ "OUTPUT_DIR = '/content/output'\n",
82
+ "COLMAP_DIR = '/content/colmap_data'"
83
+ ]
84
+ },
85
+ {
86
+ "cell_type": "code",
87
+ "execution_count": 4,
88
+ "metadata": {
89
+ "execution": {
90
+ "iopub.execute_input": "2026-01-10T18:22:43.807508Z",
91
+ "iopub.status.busy": "2026-01-10T18:22:43.807294Z",
92
+ "iopub.status.idle": "2026-01-11T00:00:17.030890Z",
93
+ "shell.execute_reply": "2026-01-11T00:00:17.029927Z"
94
+ },
95
+ "papermill": {
96
+ "duration": 20253.434865,
97
+ "end_time": "2026-01-11T00:00:17.234174",
98
+ "exception": false,
99
+ "start_time": "2026-01-10T18:22:43.799309",
100
+ "status": "completed"
101
+ },
102
+ "tags": [],
103
+ "id": "QXI_UOXaNbgI"
104
+ },
105
+ "outputs": [],
106
+ "source": [
107
+ "\n"
108
+ ],
109
+ "id": "QXI_UOXaNbgI"
110
+ },
111
+ {
112
+ "cell_type": "code",
113
+ "execution_count": null,
114
+ "id": "be6df249",
115
+ "metadata": {
116
+ "execution": {
117
+ "iopub.execute_input": "2026-01-10T18:17:32.363444Z",
118
+ "iopub.status.busy": "2026-01-10T18:17:32.363175Z",
119
+ "iopub.status.idle": "2026-01-10T18:22:43.720241Z",
120
+ "shell.execute_reply": "2026-01-10T18:22:43.719380Z"
121
+ },
122
+ "papermill": {
123
+ "duration": 311.361656,
124
+ "end_time": "2026-01-10T18:22:43.721610",
125
+ "exception": false,
126
+ "start_time": "2026-01-10T18:17:32.359954",
127
+ "status": "completed"
128
+ },
129
+ "tags": [],
130
+ "id": "be6df249",
131
+ "outputId": "9f6895a6-db59-4d18-bddd-b2e42d047cf9",
132
+ "colab": {
133
+ "base_uri": "https://localhost:8080/"
134
+ }
135
+ },
136
+ "outputs": [
137
+ {
138
+ "output_type": "stream",
139
+ "name": "stdout",
140
+ "text": [
141
+ "======================================================================\n",
142
+ "Setting up mip-splatting environment\n",
143
+ "======================================================================\n",
144
+ "\n",
145
+ "STEP 1: Clone mip-splatting repository\n",
146
+ "======================================================================\n",
147
+ " > Cloning mip-splatting with submodules...\n",
148
+ "Running: git clone --recursive https://github.com/autonomousvision/mip-splatting.git /content/mip-splatting\n",
149
+ "✅ Repository cloned with submodules\n",
150
+ "\n",
151
+ " > Verifying submodules...\n",
152
+ " > Found submodules: ['diff-gaussian-rasterization', 'simple-knn']\n",
153
+ "\n",
154
+ "======================================================================\n",
155
+ "STEP 1: System packages\n",
156
+ "======================================================================\n",
157
+ "Running: apt-get update -qq\n",
158
+ "Running: apt-get install -y -qq colmap build-essential cmake git libopenblas-dev xvfb\n"
159
+ ]
160
+ }
161
+ ],
162
+ "source": [
163
+ "def run_cmd(cmd, check=True, capture=False, cwd=None): # ← cwd=None を追加\n",
164
+ " \"\"\"Run command with better error handling\"\"\"\n",
165
+ " print(f\"Running: {' '.join(cmd)}\")\n",
166
+ " result = subprocess.run(\n",
167
+ " cmd,\n",
168
+ " capture_output=capture,\n",
169
+ " text=True,\n",
170
+ " check=False,\n",
171
+ " cwd=cwd # ← ここに渡す\n",
172
+ " )\n",
173
+ " if check and result.returncode != 0:\n",
174
+ " print(f\"❌ Command failed with code {result.returncode}\")\n",
175
+ " if capture:\n",
176
+ " print(f\"STDOUT: {result.stdout}\")\n",
177
+ " print(f\"STDERR: {result.stderr}\")\n",
178
+ " return result\n",
179
+ "\n",
180
+ "\n",
181
+ "def install_submodule(name, url, base_dir):\n",
182
+ " \"\"\"個別のサブモジュールをインストール\"\"\"\n",
183
+ " print(f\"\\n{'='*70}\")\n",
184
+ " print(f\"Installing {name}\")\n",
185
+ " print(f\"{'='*70}\")\n",
186
+ "\n",
187
+ " # 絶対パスを使用\n",
188
+ " path = os.path.abspath(os.path.join(base_dir, \"submodules\", name))\n",
189
+ " print(f\" > Target path: {path}\")\n",
190
+ "\n",
191
+ " # Step 1: 既存を削除\n",
192
+ " if os.path.exists(path):\n",
193
+ " print(f\" > Removing old {name}...\")\n",
194
+ " shutil.rmtree(path)\n",
195
+ "\n",
196
+ " # Step 2: クローン\n",
197
+ " print(f\" > Cloning from {url}...\")\n",
198
+ " os.makedirs(os.path.dirname(path), exist_ok=True)\n",
199
+ " try:\n",
200
+ " run_cmd([\"git\", \"clone\", url, path])\n",
201
+ " except subprocess.CalledProcessError as e:\n",
202
+ " print(f\"❌ Failed to clone {name}\")\n",
203
+ " print(e.stderr)\n",
204
+ " return False\n",
205
+ "\n",
206
+ " # Step 3: ファイル確認\n",
207
+ " print(f\" > Checking cloned files...\")\n",
208
+ " files = os.listdir(path)\n",
209
+ " print(f\" > Files in {name}: {files[:10]}...\")\n",
210
+ "\n",
211
+ " # Step 4: ビルドキャッシュ削除\n",
212
+ " build_dir = os.path.join(path, \"build\")\n",
213
+ " if os.path.exists(build_dir):\n",
214
+ " print(f\" > Cleaning build cache...\")\n",
215
+ " shutil.rmtree(build_dir)\n",
216
+ "\n",
217
+ " # Step 5: インストール\n",
218
+ " print(f\" > Installing {name} (This may take a few minutes)...\")\n",
219
+ "\n",
220
+ " # 環境変数を明示的に引き継ぐ\n",
221
+ " current_env = os.environ.copy()\n",
222
+ " result = subprocess.run(\n",
223
+ " [sys.executable, \"-m\", \"pip\", \"install\", \"-e\", \".\", \"--no-build-isolation\", \"-v\"],\n",
224
+ " cwd=path,\n",
225
+ " env=current_env,\n",
226
+ " capture_output=True,\n",
227
+ " text=True\n",
228
+ " )\n",
229
+ "\n",
230
+ " if result.returncode != 0:\n",
231
+ " print(f\"❌ Failed to install {name}\")\n",
232
+ " # C++/CUDAのビルドエラーは stdout に出ることが多いため、両方出力\n",
233
+ " print(\"\\n--- STDOUT (Build Logs) ---\")\n",
234
+ " stdout_lines = result.stdout.split('\\n')\n",
235
+ " print('\\n'.join(stdout_lines[-60:])) # 最後の60行を表示\n",
236
+ " print(\"\\n--- STDERR (Error Details) ---\")\n",
237
+ " print(result.stderr)\n",
238
+ " return False\n",
239
+ "\n",
240
+ " print(f\"✅ Successfully installed {name}\")\n",
241
+ " return True\n",
242
+ "\n",
243
+ "\n",
244
+ "def install_mipsplatting_submodule(name, base_dir):\n",
245
+ " \"\"\"mip-splattingに含まれるsubmoduleをインストール(クローン不要)\"\"\"\n",
246
+ " print(f\"\\n{'='*70}\")\n",
247
+ " print(f\"Installing {name} (from mip-splatting submodules)\")\n",
248
+ " print(f\"{'='*70}\")\n",
249
+ "\n",
250
+ " # submoduleのパス\n",
251
+ " path = os.path.abspath(os.path.join(base_dir, \"submodules\", name))\n",
252
+ " print(f\" > Target path: {path}\")\n",
253
+ "\n",
254
+ " # ファイルの存在確認\n",
255
+ " if not os.path.exists(path):\n",
256
+ " print(f\"❌ Path not found: {path}\")\n",
257
+ " return False\n",
258
+ "\n",
259
+ " # setup.pyの存在確認\n",
260
+ " setup_py = os.path.join(path, \"setup.py\")\n",
261
+ " if not os.path.exists(setup_py):\n",
262
+ " print(f\"❌ setup.py not found: {setup_py}\")\n",
263
+ " return False\n",
264
+ "\n",
265
+ " print(f\" > Checking files...\")\n",
266
+ " files = os.listdir(path)\n",
267
+ " print(f\" > Files in {name}: {files[:10]}...\")\n",
268
+ "\n",
269
+ " # ビルドキャッシュ削除\n",
270
+ " build_dir = os.path.join(path, \"build\")\n",
271
+ " if os.path.exists(build_dir):\n",
272
+ " print(f\" > Cleaning build cache...\")\n",
273
+ " shutil.rmtree(build_dir)\n",
274
+ "\n",
275
+ " # インストール\n",
276
+ " print(f\" > Installing {name} (This may take a few minutes)...\")\n",
277
+ "\n",
278
+ " current_env = os.environ.copy()\n",
279
+ " result = subprocess.run(\n",
280
+ " [sys.executable, \"-m\", \"pip\", \"install\", \"-e\", \".\", \"--no-build-isolation\", \"-v\"],\n",
281
+ " cwd=path,\n",
282
+ " env=current_env,\n",
283
+ " capture_output=True,\n",
284
+ " text=True\n",
285
+ " )\n",
286
+ "\n",
287
+ " if result.returncode != 0:\n",
288
+ " print(f\"❌ Failed to install {name}\")\n",
289
+ " print(\"\\n--- STDOUT (Build Logs) ---\")\n",
290
+ " stdout_lines = result.stdout.split('\\n')\n",
291
+ " print('\\n'.join(stdout_lines[-60:]))\n",
292
+ " print(\"\\n--- STDERR (Error Details) ---\")\n",
293
+ " print(result.stderr)\n",
294
+ " return False\n",
295
+ "\n",
296
+ " print(f\"✅ Successfully installed {name}\")\n",
297
+ " return True\n",
298
+ "\n",
299
+ "\n",
300
+ "def setup_environment():\n",
301
+ " \"\"\"Setup mip-splatting environment with correct submodules\"\"\"\n",
302
+ " print(\"=\"*70)\n",
303
+ " print(\"Setting up mip-splatting environment\")\n",
304
+ " print(\"=\"*70)\n",
305
+ "\n",
306
+ " WORK_DIR = \"/content/mip-splatting\"\n",
307
+ "\n",
308
+ " # =====================================================================\n",
309
+ " # STEP 1: Clone main repository with submodules\n",
310
+ " # =====================================================================\n",
311
+ " print(\"\\nSTEP 1: Clone mip-splatting repository\")\n",
312
+ " print(\"=\"*70)\n",
313
+ "\n",
314
+ " if os.path.exists(WORK_DIR):\n",
315
+ " print(f\" > {WORK_DIR} already exists, removing...\")\n",
316
+ " shutil.rmtree(WORK_DIR)\n",
317
+ "\n",
318
+ " print(f\" > Cloning mip-splatting with submodules...\")\n",
319
+ " # --recursive で submodules も一緒にクローン\n",
320
+ " run_cmd([\n",
321
+ " \"git\", \"clone\", \"--recursive\",\n",
322
+ " \"https://github.com/autonomousvision/mip-splatting.git\",\n",
323
+ " WORK_DIR\n",
324
+ " ])\n",
325
+ " print(\"✅ Repository cloned with submodules\")\n",
326
+ "\n",
327
+ " # submodulesが正しくクローンされたか確認\n",
328
+ " print(\"\\n > Verifying submodules...\")\n",
329
+ " submodules_dir = os.path.join(WORK_DIR, \"submodules\")\n",
330
+ " if os.path.exists(submodules_dir):\n",
331
+ " items = os.listdir(submodules_dir)\n",
332
+ " print(f\" > Found submodules: {items}\")\n",
333
+ "\n",
334
+ " # 空のsubmoduleディレクトリがある場合は初期化\n",
335
+ " for item in items:\n",
336
+ " item_path = os.path.join(submodules_dir, item)\n",
337
+ " if os.path.isdir(item_path):\n",
338
+ " item_files = os.listdir(item_path)\n",
339
+ " if not item_files or len(item_files) == 0:\n",
340
+ " print(f\" > {item} is empty, initializing...\")\n",
341
+ " run_cmd([\"git\", \"submodule\", \"update\", \"--init\", \"--recursive\"], cwd=WORK_DIR)\n",
342
+ " break\n",
343
+ " # =====================================================================\n",
344
+ " # STEP 1: System packages (Colab)\n",
345
+ " # =====================================================================\n",
346
+ " print(\"\\n\" + \"=\"*70)\n",
347
+ " print(\"STEP 1: System packages\")\n",
348
+ " print(\"=\"*70)\n",
349
+ "\n",
350
+ " run_cmd([\"apt-get\", \"update\", \"-qq\"])\n",
351
+ " run_cmd([\n",
352
+ " \"apt-get\", \"install\", \"-y\", \"-qq\",\n",
353
+ " \"colmap\",\n",
354
+ " \"build-essential\",\n",
355
+ " \"cmake\",\n",
356
+ " \"git\",\n",
357
+ " \"libopenblas-dev\",\n",
358
+ " \"xvfb\"\n",
359
+ " ])\n",
360
+ "\n",
361
+ " # virtual display (COLMAP / OpenCV safety)\n",
362
+ " os.environ[\"QT_QPA_PLATFORM\"] = \"offscreen\"\n",
363
+ " os.environ[\"DISPLAY\"] = \":99\"\n",
364
+ " subprocess.Popen(\n",
365
+ " [\"Xvfb\", \":99\", \"-screen\", \"0\", \"1024x768x24\"],\n",
366
+ " stdout=subprocess.DEVNULL,\n",
367
+ " stderr=subprocess.DEVNULL\n",
368
+ " )\n",
369
+ "\n",
370
+ " # =====================================================================\n",
371
+ " # STEP 2: Fix numpy compatibility\n",
372
+ " # =====================================================================\n",
373
+ " print(\"\\nSTEP 2: Fix numpy compatibility\")\n",
374
+ " print(\"=\"*70)\n",
375
+ "\n",
376
+ " print(\" > Uninstalling numpy 2.x...\")\n",
377
+ " run_cmd([sys.executable, \"-m\", \"pip\", \"uninstall\", \"numpy\", \"-y\"], check=False)\n",
378
+ "\n",
379
+ " print(\" > Installing numpy<2.0...\")\n",
380
+ " run_cmd([sys.executable, \"-m\", \"pip\", \"install\", \"numpy<2.0\"])\n",
381
+ " print(\"✅ numpy<2.0 installed\")\n",
382
+ "\n",
383
+ " # =====================================================================\n",
384
+ " # STEP 3: Install core dependencies\n",
385
+ " # =====================================================================\n",
386
+ " print(\"\\nSTEP 3: Install core dependencies\")\n",
387
+ " print(\"=\"*70)\n",
388
+ "\n",
389
+ " core_packages = [\n",
390
+ " \"open3d\",\n",
391
+ " \"plyfile\",\n",
392
+ " \"tqdm\",\n",
393
+ " \"Pillow\",\n",
394
+ " \"opencv-python\"\n",
395
+ " ]\n",
396
+ "\n",
397
+ " for package in core_packages:\n",
398
+ " print(f\" > Installing {package}...\")\n",
399
+ " run_cmd([sys.executable, \"-m\", \"pip\", \"install\", package])\n",
400
+ " print(\"✅ Core dependencies installed\")\n",
401
+ "\n",
402
+ " # =====================================================================\n",
403
+ " # STEP 4: Build mip-splatting submodules\n",
404
+ " # =====================================================================\n",
405
+ " print(\"\\nSTEP 4: Build mip-splatting submodules\")\n",
406
+ " print(\"=\"*70)\n",
407
+ "\n",
408
+ " # simple-knn: 実績のあるfixed版を使用(クローンし直す)\n",
409
+ " success_knn = install_submodule(\n",
410
+ " \"simple-knn\",\n",
411
+ " \"https://github.com/tztechno/simple-knn.git\",\n",
412
+ " WORK_DIR\n",
413
+ " )\n",
414
+ "\n",
415
+ " if not success_knn:\n",
416
+ " print(\"❌ Failed to install simple-knn\")\n",
417
+ " return None\n",
418
+ "\n",
419
+ " # diff-gaussian-rasterization: mip-splattingに含まれているものを使用\n",
420
+ " # (kernel_size対応版なのでクローンし直さない)\n",
421
+ " success_rast = install_mipsplatting_submodule(\n",
422
+ " \"diff-gaussian-rasterization\",\n",
423
+ " WORK_DIR\n",
424
+ " )\n",
425
+ "\n",
426
+ " if not success_rast:\n",
427
+ " print(\"❌ Failed to install diff-gaussian-rasterization\")\n",
428
+ " return None\n",
429
+ "\n",
430
+ "\n",
431
+ " return WORK_DIR\n",
432
+ "\n",
433
+ "\n",
434
+ "\n",
435
+ "work_dir = setup_environment()\n",
436
+ "\n"
437
+ ]
438
+ },
439
+ {
440
+ "cell_type": "code",
441
+ "execution_count": null,
442
+ "id": "b8690389",
443
+ "metadata": {
444
+ "execution": {
445
+ "iopub.execute_input": "2026-01-10T18:22:43.739411Z",
446
+ "iopub.status.busy": "2026-01-10T18:22:43.738855Z",
447
+ "iopub.status.idle": "2026-01-10T18:22:43.755664Z",
448
+ "shell.execute_reply": "2026-01-10T18:22:43.754865Z"
449
+ },
450
+ "papermill": {
451
+ "duration": 0.027297,
452
+ "end_time": "2026-01-10T18:22:43.756758",
453
+ "exception": false,
454
+ "start_time": "2026-01-10T18:22:43.729461",
455
+ "status": "completed"
456
+ },
457
+ "tags": [],
458
+ "id": "b8690389"
459
+ },
460
+ "outputs": [],
461
+ "source": [
462
+ "import os\n",
463
+ "import glob\n",
464
+ "import cv2\n",
465
+ "import numpy as np\n",
466
+ "from PIL import Image\n",
467
+ "\n",
468
+ "# =========================================================\n",
469
+ "# Utility: aspect ratio preserved + black padding\n",
470
+ "# =========================================================\n",
471
+ "\n",
472
+ "def normalize_image_sizes_biplet(input_dir, output_dir=None, size=1024, max_images=None):\n",
473
+ " \"\"\"\n",
474
+ " Generates two square crops (Left & Right or Top & Bottom)\n",
475
+ " from each image in a directory and returns the output directory\n",
476
+ " and the list of generated file paths.\n",
477
+ "\n",
478
+ " Args:\n",
479
+ " input_dir: Input directory containing source images\n",
480
+ " output_dir: Output directory for processed images\n",
481
+ " size: Target square size (default: 1024)\n",
482
+ " max_images: Maximum number of SOURCE images to process (default: None = all images)\n",
483
+ " \"\"\"\n",
484
+ " if output_dir is None:\n",
485
+ " output_dir = 'output/images_biplet'\n",
486
+ " os.makedirs(output_dir, exist_ok=True)\n",
487
+ "\n",
488
+ " print(f\"--- Step 1: Biplet-Square Normalization ---\")\n",
489
+ " print(f\"Generating 2 cropped squares (Left/Right or Top/Bottom) for each image...\")\n",
490
+ " print()\n",
491
+ "\n",
492
+ " generated_paths = []\n",
493
+ " converted_count = 0\n",
494
+ " size_stats = {}\n",
495
+ "\n",
496
+ " # Sort for consistent processing order\n",
497
+ " image_files = sorted([f for f in os.listdir(input_dir)\n",
498
+ " if f.lower().endswith(('.jpg', '.jpeg', '.png'))])\n",
499
+ "\n",
500
+ " # ★ max_images で元画像数を制限\n",
501
+ " if max_images is not None:\n",
502
+ " image_files = image_files[:max_images]\n",
503
+ " print(f\"Processing limited to {max_images} source images (will generate {max_images * 2} cropped images)\")\n",
504
+ "\n",
505
+ " for img_file in image_files:\n",
506
+ " input_path = os.path.join(input_dir, img_file)\n",
507
+ " try:\n",
508
+ " img = Image.open(input_path)\n",
509
+ " original_size = img.size\n",
510
+ "\n",
511
+ " # Tracking original aspect ratios\n",
512
+ " size_key = f\"{original_size[0]}x{original_size[1]}\"\n",
513
+ " size_stats[size_key] = size_stats.get(size_key, 0) + 1\n",
514
+ "\n",
515
+ " # Generate 2 crops using the helper function\n",
516
+ " crops = generate_two_crops(img, size)\n",
517
+ " base_name, ext = os.path.splitext(img_file)\n",
518
+ "\n",
519
+ " for mode, cropped_img in crops.items():\n",
520
+ " output_path = os.path.join(output_dir, f\"{base_name}_{mode}{ext}\")\n",
521
+ " cropped_img.save(output_path, quality=95)\n",
522
+ " generated_paths.append(output_path)\n",
523
+ "\n",
524
+ " converted_count += 1\n",
525
+ " print(f\" ✓ {img_file}: {original_size} → 2 square images generated\")\n",
526
+ "\n",
527
+ " except Exception as e:\n",
528
+ " print(f\" ✗ Error processing {img_file}: {e}\")\n",
529
+ "\n",
530
+ " print(f\"\\nProcessing complete: {converted_count} source images processed\")\n",
531
+ " print(f\"Total output images: {len(generated_paths)}\")\n",
532
+ " print(f\"Original size distribution: {size_stats}\")\n",
533
+ "\n",
534
+ " return output_dir, generated_paths\n",
535
+ "\n",
536
+ "\n",
537
+ "def generate_two_crops(img, size):\n",
538
+ " \"\"\"\n",
539
+ " Crops the image into a square and returns 2 variations\n",
540
+ " (Left/Right for landscape, Top/Bottom for portrait).\n",
541
+ " \"\"\"\n",
542
+ " width, height = img.size\n",
543
+ " crop_size = min(width, height)\n",
544
+ " crops = {}\n",
545
+ "\n",
546
+ " if width > height:\n",
547
+ " # Landscape → Left & Right\n",
548
+ " positions = {\n",
549
+ " 'left': 0,\n",
550
+ " 'right': width - crop_size\n",
551
+ " }\n",
552
+ " for mode, x_offset in positions.items():\n",
553
+ " box = (x_offset, 0, x_offset + crop_size, crop_size)\n",
554
+ " crops[mode] = img.crop(box).resize(\n",
555
+ " (size, size),\n",
556
+ " Image.Resampling.LANCZOS\n",
557
+ " )\n",
558
+ "\n",
559
+ " else:\n",
560
+ " # Portrait or Square → Top & Bottom\n",
561
+ " positions = {\n",
562
+ " 'top': 0,\n",
563
+ " 'bottom': height - crop_size\n",
564
+ " }\n",
565
+ " for mode, y_offset in positions.items():\n",
566
+ " box = (0, y_offset, crop_size, y_offset + crop_size)\n",
567
+ " crops[mode] = img.crop(box).resize(\n",
568
+ " (size, size),\n",
569
+ " Image.Resampling.LANCZOS\n",
570
+ " )\n",
571
+ "\n",
572
+ " return crops\n"
573
+ ]
574
+ },
575
+ {
576
+ "cell_type": "code",
577
+ "execution_count": null,
578
+ "id": "7acc20b6",
579
+ "metadata": {
580
+ "execution": {
581
+ "iopub.execute_input": "2026-01-10T18:22:43.772525Z",
582
+ "iopub.status.busy": "2026-01-10T18:22:43.772303Z",
583
+ "iopub.status.idle": "2026-01-10T18:22:43.790574Z",
584
+ "shell.execute_reply": "2026-01-10T18:22:43.789515Z"
585
+ },
586
+ "papermill": {
587
+ "duration": 0.027612,
588
+ "end_time": "2026-01-10T18:22:43.791681",
589
+ "exception": false,
590
+ "start_time": "2026-01-10T18:22:43.764069",
591
+ "status": "completed"
592
+ },
593
+ "tags": [],
594
+ "id": "7acc20b6"
595
+ },
596
+ "outputs": [],
597
+ "source": [
598
+ "def run_colmap_reconstruction(image_dir, colmap_dir):\n",
599
+ " \"\"\"Estimate camera poses and 3D point cloud with COLMAP\"\"\"\n",
600
+ " print(\"Running SfM reconstruction with COLMAP...\")\n",
601
+ "\n",
602
+ " database_path = os.path.join(colmap_dir, \"database.db\")\n",
603
+ " sparse_dir = os.path.join(colmap_dir, \"sparse\")\n",
604
+ " os.makedirs(sparse_dir, exist_ok=True)\n",
605
+ "\n",
606
+ " # Set environment variable\n",
607
+ " env = os.environ.copy()\n",
608
+ " env['QT_QPA_PLATFORM'] = 'offscreen'\n",
609
+ "\n",
610
+ " # Feature extraction\n",
611
+ " print(\"1/4: Extracting features...\")\n",
612
+ " subprocess.run([\n",
613
+ " 'colmap', 'feature_extractor',\n",
614
+ " '--database_path', database_path,\n",
615
+ " '--image_path', image_dir,\n",
616
+ " '--ImageReader.single_camera', '1',\n",
617
+ " '--ImageReader.camera_model', 'OPENCV',\n",
618
+ " '--SiftExtraction.use_gpu', '0' # Use CPU\n",
619
+ " ], check=True, env=env)\n",
620
+ "\n",
621
+ " # Feature matching\n",
622
+ " print(\"2/4: Matching features...\")\n",
623
+ " subprocess.run([\n",
624
+ " 'colmap', 'exhaustive_matcher', # Use sequential_matcher instead of exhaustive_matcher\n",
625
+ " '--database_path', database_path,\n",
626
+ " '--SiftMatching.use_gpu', '0' # Use CPU\n",
627
+ " ], check=True, env=env)\n",
628
+ "\n",
629
+ " # Sparse reconstruction\n",
630
+ " print(\"3/4: Sparse reconstruction...\")\n",
631
+ " subprocess.run([\n",
632
+ " 'colmap', 'mapper',\n",
633
+ " '--database_path', database_path,\n",
634
+ " '--image_path', image_dir,\n",
635
+ " '--output_path', sparse_dir,\n",
636
+ " '--Mapper.ba_global_max_num_iterations', '20', # Speed up\n",
637
+ " '--Mapper.ba_local_max_num_iterations', '10'\n",
638
+ " ], check=True, env=env)\n",
639
+ "\n",
640
+ " # Export to text format\n",
641
+ " print(\"4/4: Exporting to text format...\")\n",
642
+ " model_dir = os.path.join(sparse_dir, '0')\n",
643
+ " if not os.path.exists(model_dir):\n",
644
+ " # Use the first model found\n",
645
+ " subdirs = [d for d in os.listdir(sparse_dir) if os.path.isdir(os.path.join(sparse_dir, d))]\n",
646
+ " if subdirs:\n",
647
+ " model_dir = os.path.join(sparse_dir, subdirs[0])\n",
648
+ " else:\n",
649
+ " raise FileNotFoundError(\"COLMAP reconstruction failed\")\n",
650
+ "\n",
651
+ " subprocess.run([\n",
652
+ " 'colmap', 'model_converter',\n",
653
+ " '--input_path', model_dir,\n",
654
+ " '--output_path', model_dir,\n",
655
+ " '--output_type', 'TXT'\n",
656
+ " ], check=True, env=env)\n",
657
+ "\n",
658
+ " print(f\"COLMAP reconstruction complete: {model_dir}\")\n",
659
+ " return model_dir\n",
660
+ "\n",
661
+ "\n",
662
+ "def convert_cameras_to_pinhole(input_file, output_file):\n",
663
+ " \"\"\"Convert camera model to PINHOLE format\"\"\"\n",
664
+ " print(f\"Reading camera file: {input_file}\")\n",
665
+ "\n",
666
+ " with open(input_file, 'r') as f:\n",
667
+ " lines = f.readlines()\n",
668
+ "\n",
669
+ " converted_count = 0\n",
670
+ " with open(output_file, 'w') as f:\n",
671
+ " for line in lines:\n",
672
+ " if line.startswith('#') or line.strip() == '':\n",
673
+ " f.write(line)\n",
674
+ " else:\n",
675
+ " parts = line.strip().split()\n",
676
+ " if len(parts) >= 4:\n",
677
+ " cam_id = parts[0]\n",
678
+ " model = parts[1]\n",
679
+ " width = parts[2]\n",
680
+ " height = parts[3]\n",
681
+ " params = parts[4:]\n",
682
+ "\n",
683
+ " # Convert to PINHOLE format\n",
684
+ " if model == \"PINHOLE\":\n",
685
+ " f.write(line)\n",
686
+ " elif model == \"OPENCV\":\n",
687
+ " # OPENCV: fx, fy, cx, cy, k1, k2, p1, p2\n",
688
+ " fx = params[0]\n",
689
+ " fy = params[1]\n",
690
+ " cx = params[2]\n",
691
+ " cy = params[3]\n",
692
+ " f.write(f\"{cam_id} PINHOLE {width} {height} {fx} {fy} {cx} {cy}\\n\")\n",
693
+ " converted_count += 1\n",
694
+ " else:\n",
695
+ " # Convert other models too\n",
696
+ " fx = fy = max(float(width), float(height))\n",
697
+ " cx = float(width) / 2\n",
698
+ " cy = float(height) / 2\n",
699
+ " f.write(f\"{cam_id} PINHOLE {width} {height} {fx} {fy} {cx} {cy}\\n\")\n",
700
+ " converted_count += 1\n",
701
+ " else:\n",
702
+ " f.write(line)\n",
703
+ "\n",
704
+ " print(f\"Converted {converted_count} cameras to PINHOLE format\")\n",
705
+ "\n",
706
+ "\n",
707
+ "def prepare_gaussian_splatting_data(image_dir, colmap_model_dir):\n",
708
+ " \"\"\"Prepare data for Gaussian Splatting\"\"\"\n",
709
+ " print(\"Preparing data for Gaussian Splatting...\")\n",
710
+ "\n",
711
+ " data_dir = f\"{WORK_DIR}/data/video\"\n",
712
+ " os.makedirs(f\"{data_dir}/sparse/0\", exist_ok=True)\n",
713
+ " os.makedirs(f\"{data_dir}/images\", exist_ok=True)\n",
714
+ "\n",
715
+ " # Copy images\n",
716
+ " print(\"Copying images...\")\n",
717
+ " img_count = 0\n",
718
+ " for img_file in os.listdir(image_dir):\n",
719
+ " if img_file.lower().endswith(('.jpg', '.jpeg', '.png')):\n",
720
+ " shutil.copy(\n",
721
+ " os.path.join(image_dir, img_file),\n",
722
+ " f\"{data_dir}/images/{img_file}\"\n",
723
+ " )\n",
724
+ " img_count += 1\n",
725
+ " print(f\"Copied {img_count} images\")\n",
726
+ "\n",
727
+ " # Convert and copy camera file to PINHOLE format\n",
728
+ " print(\"Converting camera model to PINHOLE format...\")\n",
729
+ " convert_cameras_to_pinhole(\n",
730
+ " os.path.join(colmap_model_dir, 'cameras.txt'),\n",
731
+ " f\"{data_dir}/sparse/0/cameras.txt\"\n",
732
+ " )\n",
733
+ "\n",
734
+ " # Copy other files\n",
735
+ " for filename in ['images.txt', 'points3D.txt']:\n",
736
+ " src = os.path.join(colmap_model_dir, filename)\n",
737
+ " dst = f\"{data_dir}/sparse/0/{filename}\"\n",
738
+ " if os.path.exists(src):\n",
739
+ " shutil.copy(src, dst)\n",
740
+ " print(f\"Copied {filename}\")\n",
741
+ " else:\n",
742
+ " print(f\"Warning: {filename} not found\")\n",
743
+ "\n",
744
+ " print(f\"Data preparation complete: {data_dir}\")\n",
745
+ " return data_dir\n",
746
+ "\n",
747
+ "\n",
748
+ "\n",
749
+ "\n",
750
+ "# After (mipGS) - Added Kernel Size and Multi-Scale Support\n",
751
+ "def train_gaussian_splatting(data_dir, work_dir, iterations=3000):\n",
752
+ " \"\"\"Training function for mipGS with comprehensive error handling\"\"\"\n",
753
+ "\n",
754
+ " # 入力検証\n",
755
+ " if not work_dir:\n",
756
+ " raise ValueError(\"work_dir cannot be None or empty\")\n",
757
+ "\n",
758
+ " if not os.path.exists(work_dir):\n",
759
+ " raise FileNotFoundError(f\"Work directory not found: {work_dir}\")\n",
760
+ "\n",
761
+ " if not os.path.exists(data_dir):\n",
762
+ " raise FileNotFoundError(f\"Data directory not found: {data_dir}\")\n",
763
+ "\n",
764
+ " train_py_path = os.path.join(work_dir, \"train.py\")\n",
765
+ " if not os.path.exists(train_py_path):\n",
766
+ " raise FileNotFoundError(f\"train.py not found: {train_py_path}\")\n",
767
+ "\n",
768
+ " # モデル保存パス\n",
769
+ " model_path = os.path.join(work_dir, \"output\", \"video\")\n",
770
+ " os.makedirs(model_path, exist_ok=True)\n",
771
+ "\n",
772
+ " # コマンド構築\n",
773
+ " cmd = [\n",
774
+ " sys.executable, 'train.py',\n",
775
+ " '-s', data_dir,\n",
776
+ " '-m', model_path,\n",
777
+ " '--iterations', str(iterations),\n",
778
+ " '--eval'\n",
779
+ " ]\n",
780
+ "\n",
781
+ " print(f\"Training configuration:\")\n",
782
+ " print(f\" Work dir: {work_dir}\")\n",
783
+ " print(f\" Data dir: {data_dir}\")\n",
784
+ " print(f\" Model path: {model_path}\")\n",
785
+ " print(f\" Command: {' '.join(cmd)}\")\n",
786
+ "\n",
787
+ " # 実行\n",
788
+ " result = subprocess.run(\n",
789
+ " cmd,\n",
790
+ " cwd=work_dir,\n",
791
+ " capture_output=True,\n",
792
+ " text=True\n",
793
+ " )\n",
794
+ "\n",
795
+ " # エラーチェック\n",
796
+ " if result.returncode != 0:\n",
797
+ " print(f\"\\n❌ Training failed with exit code {result.returncode}\")\n",
798
+ " print(\"\\n--- STDOUT ---\")\n",
799
+ " print(result.stdout)\n",
800
+ " print(\"\\n--- STDERR ---\")\n",
801
+ " print(result.stderr)\n",
802
+ " raise subprocess.CalledProcessError(result.returncode, cmd)\n",
803
+ "\n",
804
+ " print(\"\\n✅ Training completed successfully\")\n",
805
+ " return model_path\n",
806
+ "\n"
807
+ ]
808
+ },
809
+ {
810
+ "cell_type": "code",
811
+ "source": [
812
+ "# New function for mipGS - Fuse 3D filter into Gaussian parameters\n",
813
+ "def create_fused_ply(model_path, scene_name, output_dir=\"fused\"):\n",
814
+ " \"\"\"\n",
815
+ " Fuse the 3D smoothing filter to Gaussian parameters for deployment\n",
816
+ " This creates a .ply file that can be used in online viewers\n",
817
+ "\n",
818
+ " Args:\n",
819
+ " model_path: Path to trained model\n",
820
+ " scene_name: Name of the scene\n",
821
+ " output_dir: Directory to save fused .ply file\n",
822
+ " \"\"\"\n",
823
+ " os.makedirs(output_dir, exist_ok=True)\n",
824
+ " output_ply = f\"{output_dir}/{scene_name}_fused.ply\"\n",
825
+ "\n",
826
+ " cmd = [\n",
827
+ " sys.executable, 'create_fused_ply.py',\n",
828
+ " '-m', f\"{model_path}/{scene_name}\",\n",
829
+ " '--output_ply', output_ply\n",
830
+ " ]\n",
831
+ " subprocess.run(cmd, cwd=WORK_DIR, check=True)\n",
832
+ " return output_ply\n",
833
+ ""
834
+ ],
835
+ "metadata": {
836
+ "id": "-Cwgr3I0b57O"
837
+ },
838
+ "id": "-Cwgr3I0b57O",
839
+ "execution_count": null,
840
+ "outputs": []
841
+ },
842
+ {
843
+ "cell_type": "code",
844
+ "execution_count": null,
845
+ "id": "f75233a8",
846
+ "metadata": {
847
+ "execution": {
848
+ "iopub.execute_input": "2026-01-10T18:22:43.807508Z",
849
+ "iopub.status.busy": "2026-01-10T18:22:43.807294Z",
850
+ "iopub.status.idle": "2026-01-11T00:00:17.030890Z",
851
+ "shell.execute_reply": "2026-01-11T00:00:17.029927Z"
852
+ },
853
+ "papermill": {
854
+ "duration": 20253.434865,
855
+ "end_time": "2026-01-11T00:00:17.234174",
856
+ "exception": false,
857
+ "start_time": "2026-01-10T18:22:43.799309",
858
+ "status": "completed"
859
+ },
860
+ "tags": [],
861
+ "id": "f75233a8"
862
+ },
863
+ "outputs": [],
864
+ "source": [
865
+ "def main_pipeline(image_dir, output_dir,\n",
866
+ " square_size=1024, max_images=100):\n",
867
+ " \"\"\"Main execution function\"\"\"\n",
868
+ " try:\n",
869
+ " # Step 1: 画像の正規化と前処理\n",
870
+ " print(\"=\"*60)\n",
871
+ " print(\"Step 1: Normalizing and preprocessing images\")\n",
872
+ " print(\"=\"*60)\n",
873
+ "\n",
874
+ " frame_dir = os.path.join(COLMAP_DIR, \"images\")\n",
875
+ " os.makedirs(frame_dir, exist_ok=True)\n",
876
+ "\n",
877
+ " # 画像を正規化して直接COLMAPのディレクトリに保存\n",
878
+ " num_processed = normalize_image_sizes_biplet(\n",
879
+ " input_dir=image_dir,\n",
880
+ " output_dir=frame_dir, # 直接colmap/imagesに保存\n",
881
+ " size=square_size,\n",
882
+ " max_images=max_images\n",
883
+ " )\n",
884
+ "\n",
885
+ " print(f\"Processed {num_processed} images\")\n",
886
+ "\n",
887
+ " # Step 2: Estimate Camera Info with COLMAP\n",
888
+ " print(\"=\"*60)\n",
889
+ " print(\"Step 2: Running COLMAP reconstruction\")\n",
890
+ " print(\"=\"*60)\n",
891
+ " colmap_model_dir = run_colmap_reconstruction(frame_dir, COLMAP_DIR)\n",
892
+ "\n",
893
+ " print(frame_dir)\n",
894
+ " print(colmap_model_dir)\n",
895
+ "\n",
896
+ " # Step 3: Prepare Data for Gaussian Splatting\n",
897
+ " print(\"=\"*60)\n",
898
+ " print(\"Step 3: Preparing Gaussian Splatting data\")\n",
899
+ " print(\"=\"*60)\n",
900
+ " data_dir = prepare_gaussian_splatting_data(frame_dir, colmap_model_dir)\n",
901
+ "\n",
902
+ " # Step 4: Train Model\n",
903
+ " print(\"=\"*60)\n",
904
+ " print(\"Step 4: Training Gaussian Splatting model\")\n",
905
+ " print(\"=\"*60)\n",
906
+ " model_path = train_gaussian_splatting(\n",
907
+ " data_dir=data_dir,\n",
908
+ " work_dir=work_dir, # 明示的に渡す\n",
909
+ " iterations=3000\n",
910
+ " )\n",
911
+ "\n",
912
+ " return ply_path\n",
913
+ "\n",
914
+ " except Exception as e:\n",
915
+ " print(f\"Error: {str(e)}\")\n",
916
+ " import traceback\n",
917
+ " traceback.print_exc()\n",
918
+ " return None, None\n",
919
+ "\n",
920
+ "\n",
921
+ "\n",
922
+ "\n",
923
+ "if __name__ == \"__main__\":\n",
924
+ " IMAGE_DIR = \"/content/drive/MyDrive/your_folder/fountain100\"\n",
925
+ " OUTPUT_DIR = \"/content/output\"\n",
926
+ " COLMAP_DIR = \"/content/colmap\"\n",
927
+ "\n",
928
+ " ply_path = main_pipeline(\n",
929
+ " image_dir=IMAGE_DIR,\n",
930
+ " output_dir=OUTPUT_DIR,\n",
931
+ " square_size=1024,\n",
932
+ " max_images=20\n",
933
+ " )\n",
934
+ "\n",
935
+ "\n"
936
+ ]
937
+ },
938
+ {
939
+ "cell_type": "markdown",
940
+ "id": "e17ec719",
941
+ "metadata": {
942
+ "papermill": {
943
+ "duration": 0.49801,
944
+ "end_time": "2026-01-11T00:00:18.165833",
945
+ "exception": false,
946
+ "start_time": "2026-01-11T00:00:17.667823",
947
+ "status": "completed"
948
+ },
949
+ "tags": [],
950
+ "id": "e17ec719"
951
+ },
952
+ "source": []
953
+ },
954
+ {
955
+ "cell_type": "markdown",
956
+ "id": "38b3974c",
957
+ "metadata": {
958
+ "papermill": {
959
+ "duration": 0.427583,
960
+ "end_time": "2026-01-11T00:00:19.008387",
961
+ "exception": false,
962
+ "start_time": "2026-01-11T00:00:18.580804",
963
+ "status": "completed"
964
+ },
965
+ "tags": [],
966
+ "id": "38b3974c"
967
+ },
968
+ "source": []
969
+ }
970
+ ],
971
+ "metadata": {
972
+ "kaggle": {
973
+ "accelerator": "nvidiaTeslaT4",
974
+ "dataSources": [
975
+ {
976
+ "databundleVersionId": 5447706,
977
+ "sourceId": 49349,
978
+ "sourceType": "competition"
979
+ },
980
+ {
981
+ "datasetId": 1429416,
982
+ "sourceId": 14451718,
983
+ "sourceType": "datasetVersion"
984
+ }
985
+ ],
986
+ "dockerImageVersionId": 31090,
987
+ "isGpuEnabled": true,
988
+ "isInternetEnabled": true,
989
+ "language": "python",
990
+ "sourceType": "notebook"
991
+ },
992
+ "kernelspec": {
993
+ "display_name": "Python 3",
994
+ "name": "python3"
995
+ },
996
+ "language_info": {
997
+ "codemirror_mode": {
998
+ "name": "ipython",
999
+ "version": 3
1000
+ },
1001
+ "file_extension": ".py",
1002
+ "mimetype": "text/x-python",
1003
+ "name": "python",
1004
+ "nbconvert_exporter": "python",
1005
+ "pygments_lexer": "ipython3",
1006
+ "version": "3.11.13"
1007
+ },
1008
+ "papermill": {
1009
+ "default_parameters": {},
1010
+ "duration": 20573.990788,
1011
+ "end_time": "2026-01-11T00:00:22.081506",
1012
+ "environment_variables": {},
1013
+ "exception": null,
1014
+ "input_path": "__notebook__.ipynb",
1015
+ "output_path": "__notebook__.ipynb",
1016
+ "parameters": {},
1017
+ "start_time": "2026-01-10T18:17:28.090718",
1018
+ "version": "2.6.0"
1019
+ },
1020
+ "colab": {
1021
+ "provenance": [],
1022
+ "gpuType": "T4"
1023
+ },
1024
+ "accelerator": "GPU"
1025
+ },
1026
+ "nbformat": 4,
1027
+ "nbformat_minor": 5
1028
+ }
biplet_colmap_mipgs_colab_07oo.ipynb ADDED
@@ -0,0 +1,1150 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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-colmap-mipgs-colab-00**"
19
+ ]
20
+ },
21
+ {
22
+ "cell_type": "code",
23
+ "source": [
24
+ "#サイズの異なる画像を扱う\n",
25
+ "from google.colab import drive\n",
26
+ "drive.mount('/content/drive')"
27
+ ],
28
+ "metadata": {
29
+ "colab": {
30
+ "base_uri": "https://localhost:8080/"
31
+ },
32
+ "id": "JON4rYSEOzCg",
33
+ "outputId": "26faa569-d3de-41d3-be2f-fbf38d363f7a"
34
+ },
35
+ "id": "JON4rYSEOzCg",
36
+ "execution_count": 3,
37
+ "outputs": [
38
+ {
39
+ "output_type": "stream",
40
+ "name": "stdout",
41
+ "text": [
42
+ "Mounted at /content/drive\n"
43
+ ]
44
+ }
45
+ ]
46
+ },
47
+ {
48
+ "cell_type": "code",
49
+ "execution_count": 4,
50
+ "id": "22353010",
51
+ "metadata": {
52
+ "execution": {
53
+ "iopub.execute_input": "2026-01-10T18:17:32.181455Z",
54
+ "iopub.status.busy": "2026-01-10T18:17:32.180969Z",
55
+ "iopub.status.idle": "2026-01-10T18:17:32.355942Z",
56
+ "shell.execute_reply": "2026-01-10T18:17:32.355229Z"
57
+ },
58
+ "papermill": {
59
+ "duration": 0.179454,
60
+ "end_time": "2026-01-10T18:17:32.357275",
61
+ "exception": false,
62
+ "start_time": "2026-01-10T18:17:32.177821",
63
+ "status": "completed"
64
+ },
65
+ "tags": [],
66
+ "id": "22353010"
67
+ },
68
+ "outputs": [],
69
+ "source": [
70
+ "import os\n",
71
+ "import sys\n",
72
+ "import subprocess\n",
73
+ "import shutil\n",
74
+ "from pathlib import Path\n",
75
+ "import cv2\n",
76
+ "from PIL import Image\n",
77
+ "import glob\n",
78
+ "\n",
79
+ "IMAGE_PATH=\"/content/drive/MyDrive/your_folder/fountain100\"\n",
80
+ "WORK_DIR = '/content/mip-splatting'\n",
81
+ "OUTPUT_DIR = '/content/output'\n",
82
+ "COLMAP_DIR = '/content/colmap_data'"
83
+ ]
84
+ },
85
+ {
86
+ "cell_type": "code",
87
+ "execution_count": 4,
88
+ "metadata": {
89
+ "execution": {
90
+ "iopub.execute_input": "2026-01-10T18:22:43.807508Z",
91
+ "iopub.status.busy": "2026-01-10T18:22:43.807294Z",
92
+ "iopub.status.idle": "2026-01-11T00:00:17.030890Z",
93
+ "shell.execute_reply": "2026-01-11T00:00:17.029927Z"
94
+ },
95
+ "papermill": {
96
+ "duration": 20253.434865,
97
+ "end_time": "2026-01-11T00:00:17.234174",
98
+ "exception": false,
99
+ "start_time": "2026-01-10T18:22:43.799309",
100
+ "status": "completed"
101
+ },
102
+ "tags": [],
103
+ "id": "QXI_UOXaNbgI"
104
+ },
105
+ "outputs": [],
106
+ "source": [
107
+ "\n"
108
+ ],
109
+ "id": "QXI_UOXaNbgI"
110
+ },
111
+ {
112
+ "cell_type": "code",
113
+ "execution_count": 5,
114
+ "id": "be6df249",
115
+ "metadata": {
116
+ "execution": {
117
+ "iopub.execute_input": "2026-01-10T18:17:32.363444Z",
118
+ "iopub.status.busy": "2026-01-10T18:17:32.363175Z",
119
+ "iopub.status.idle": "2026-01-10T18:22:43.720241Z",
120
+ "shell.execute_reply": "2026-01-10T18:22:43.719380Z"
121
+ },
122
+ "papermill": {
123
+ "duration": 311.361656,
124
+ "end_time": "2026-01-10T18:22:43.721610",
125
+ "exception": false,
126
+ "start_time": "2026-01-10T18:17:32.359954",
127
+ "status": "completed"
128
+ },
129
+ "tags": [],
130
+ "id": "be6df249",
131
+ "outputId": "9f6895a6-db59-4d18-bddd-b2e42d047cf9",
132
+ "colab": {
133
+ "base_uri": "https://localhost:8080/"
134
+ }
135
+ },
136
+ "outputs": [
137
+ {
138
+ "output_type": "stream",
139
+ "name": "stdout",
140
+ "text": [
141
+ "======================================================================\n",
142
+ "Setting up mip-splatting environment\n",
143
+ "======================================================================\n",
144
+ "\n",
145
+ "STEP 1: Clone mip-splatting repository\n",
146
+ "======================================================================\n",
147
+ " > Cloning mip-splatting with submodules...\n",
148
+ "Running: git clone --recursive https://github.com/autonomousvision/mip-splatting.git /content/mip-splatting\n",
149
+ "✅ Repository cloned with submodules\n",
150
+ "\n",
151
+ " > Verifying submodules...\n",
152
+ " > Found submodules: ['diff-gaussian-rasterization', 'simple-knn']\n",
153
+ "\n",
154
+ "======================================================================\n",
155
+ "STEP 1: System packages\n",
156
+ "======================================================================\n",
157
+ "Running: apt-get update -qq\n",
158
+ "Running: apt-get install -y -qq colmap build-essential cmake git libopenblas-dev xvfb\n",
159
+ "\n",
160
+ "STEP 2: Fix numpy compatibility\n",
161
+ "======================================================================\n",
162
+ " > Uninstalling numpy 2.x...\n",
163
+ "Running: /usr/bin/python3 -m pip uninstall numpy -y\n",
164
+ " > Installing numpy<2.0...\n",
165
+ "Running: /usr/bin/python3 -m pip install numpy<2.0\n",
166
+ "✅ numpy<2.0 installed\n",
167
+ "\n",
168
+ "STEP 3: Install core dependencies\n",
169
+ "======================================================================\n",
170
+ " > Installing open3d...\n",
171
+ "Running: /usr/bin/python3 -m pip install open3d\n",
172
+ " > Installing plyfile...\n",
173
+ "Running: /usr/bin/python3 -m pip install plyfile\n",
174
+ " > Installing tqdm...\n",
175
+ "Running: /usr/bin/python3 -m pip install tqdm\n",
176
+ " > Installing Pillow...\n",
177
+ "Running: /usr/bin/python3 -m pip install Pillow\n",
178
+ " > Installing opencv-python...\n",
179
+ "Running: /usr/bin/python3 -m pip install opencv-python\n",
180
+ "✅ Core dependencies installed\n",
181
+ "\n",
182
+ "STEP 4: Build mip-splatting submodules\n",
183
+ "======================================================================\n",
184
+ "\n",
185
+ "======================================================================\n",
186
+ "Installing simple-knn\n",
187
+ "======================================================================\n",
188
+ " > Target path: /content/mip-splatting/submodules/simple-knn\n",
189
+ " > Removing old simple-knn...\n",
190
+ " > Cloning from https://github.com/tztechno/simple-knn.git...\n",
191
+ "Running: git clone https://github.com/tztechno/simple-knn.git /content/mip-splatting/submodules/simple-knn\n",
192
+ " > Checking cloned files...\n",
193
+ " > Files in simple-knn: ['spatial.cu', '.gitignore', '.git', 'setup.py', 'simple_knn.h', 'simple_knn0.cu', 'ext.cpp', 'simple_knn', 'spatial.h', 'simple_knn.cu']...\n",
194
+ " > Installing simple-knn (This may take a few minutes)...\n",
195
+ "✅ Successfully installed simple-knn\n",
196
+ "\n",
197
+ "======================================================================\n",
198
+ "Installing diff-gaussian-rasterization (from mip-splatting submodules)\n",
199
+ "======================================================================\n",
200
+ " > Target path: /content/mip-splatting/submodules/diff-gaussian-rasterization\n",
201
+ " > Checking files...\n",
202
+ " > Files in diff-gaussian-rasterization: ['LICENSE.md', 'rasterize_points.h', 'cuda_rasterizer', 'diff_gaussian_rasterization', 'setup.py', 'ext.cpp', 'rasterize_points.cu', 'diff_gaussian_rasterization.egg-info', 'CMakeLists.txt', 'third_party']...\n",
203
+ " > Installing diff-gaussian-rasterization (This may take a few minutes)...\n",
204
+ "✅ Successfully installed diff-gaussian-rasterization\n"
205
+ ]
206
+ }
207
+ ],
208
+ "source": [
209
+ "def run_cmd(cmd, check=True, capture=False, cwd=None): # ← cwd=None を追加\n",
210
+ " \"\"\"Run command with better error handling\"\"\"\n",
211
+ " print(f\"Running: {' '.join(cmd)}\")\n",
212
+ " result = subprocess.run(\n",
213
+ " cmd,\n",
214
+ " capture_output=capture,\n",
215
+ " text=True,\n",
216
+ " check=False,\n",
217
+ " cwd=cwd # ← ここに渡す\n",
218
+ " )\n",
219
+ " if check and result.returncode != 0:\n",
220
+ " print(f\"❌ Command failed with code {result.returncode}\")\n",
221
+ " if capture:\n",
222
+ " print(f\"STDOUT: {result.stdout}\")\n",
223
+ " print(f\"STDERR: {result.stderr}\")\n",
224
+ " return result\n",
225
+ "\n",
226
+ "\n",
227
+ "def install_submodule(name, url, base_dir):\n",
228
+ " \"\"\"個別のサブモジュールをインストール\"\"\"\n",
229
+ " print(f\"\\n{'='*70}\")\n",
230
+ " print(f\"Installing {name}\")\n",
231
+ " print(f\"{'='*70}\")\n",
232
+ "\n",
233
+ " # 絶対パスを使用\n",
234
+ " path = os.path.abspath(os.path.join(base_dir, \"submodules\", name))\n",
235
+ " print(f\" > Target path: {path}\")\n",
236
+ "\n",
237
+ " # Step 1: 既存を削除\n",
238
+ " if os.path.exists(path):\n",
239
+ " print(f\" > Removing old {name}...\")\n",
240
+ " shutil.rmtree(path)\n",
241
+ "\n",
242
+ " # Step 2: クローン\n",
243
+ " print(f\" > Cloning from {url}...\")\n",
244
+ " os.makedirs(os.path.dirname(path), exist_ok=True)\n",
245
+ " try:\n",
246
+ " run_cmd([\"git\", \"clone\", url, path])\n",
247
+ " except subprocess.CalledProcessError as e:\n",
248
+ " print(f\"❌ Failed to clone {name}\")\n",
249
+ " print(e.stderr)\n",
250
+ " return False\n",
251
+ "\n",
252
+ " # Step 3: ファイル確認\n",
253
+ " print(f\" > Checking cloned files...\")\n",
254
+ " files = os.listdir(path)\n",
255
+ " print(f\" > Files in {name}: {files[:10]}...\")\n",
256
+ "\n",
257
+ " # Step 4: ビルドキャッシュ削除\n",
258
+ " build_dir = os.path.join(path, \"build\")\n",
259
+ " if os.path.exists(build_dir):\n",
260
+ " print(f\" > Cleaning build cache...\")\n",
261
+ " shutil.rmtree(build_dir)\n",
262
+ "\n",
263
+ " # Step 5: インストール\n",
264
+ " print(f\" > Installing {name} (This may take a few minutes)...\")\n",
265
+ "\n",
266
+ " # 環境変数を明示的に引き継ぐ\n",
267
+ " current_env = os.environ.copy()\n",
268
+ " result = subprocess.run(\n",
269
+ " [sys.executable, \"-m\", \"pip\", \"install\", \"-e\", \".\", \"--no-build-isolation\", \"-v\"],\n",
270
+ " cwd=path,\n",
271
+ " env=current_env,\n",
272
+ " capture_output=True,\n",
273
+ " text=True\n",
274
+ " )\n",
275
+ "\n",
276
+ " if result.returncode != 0:\n",
277
+ " print(f\"❌ Failed to install {name}\")\n",
278
+ " # C++/CUDAのビルドエラーは stdout に出ることが多いため、両方出力\n",
279
+ " print(\"\\n--- STDOUT (Build Logs) ---\")\n",
280
+ " stdout_lines = result.stdout.split('\\n')\n",
281
+ " print('\\n'.join(stdout_lines[-60:])) # 最後の60行を表示\n",
282
+ " print(\"\\n--- STDERR (Error Details) ---\")\n",
283
+ " print(result.stderr)\n",
284
+ " return False\n",
285
+ "\n",
286
+ " print(f\"✅ Successfully installed {name}\")\n",
287
+ " return True\n",
288
+ "\n",
289
+ "\n",
290
+ "def install_mipsplatting_submodule(name, base_dir):\n",
291
+ " \"\"\"mip-splattingに含まれるsubmoduleをインストール(クローン不要)\"\"\"\n",
292
+ " print(f\"\\n{'='*70}\")\n",
293
+ " print(f\"Installing {name} (from mip-splatting submodules)\")\n",
294
+ " print(f\"{'='*70}\")\n",
295
+ "\n",
296
+ " # submoduleのパス\n",
297
+ " path = os.path.abspath(os.path.join(base_dir, \"submodules\", name))\n",
298
+ " print(f\" > Target path: {path}\")\n",
299
+ "\n",
300
+ " # ファイルの存在確認\n",
301
+ " if not os.path.exists(path):\n",
302
+ " print(f\"❌ Path not found: {path}\")\n",
303
+ " return False\n",
304
+ "\n",
305
+ " # setup.pyの存在確認\n",
306
+ " setup_py = os.path.join(path, \"setup.py\")\n",
307
+ " if not os.path.exists(setup_py):\n",
308
+ " print(f\"❌ setup.py not found: {setup_py}\")\n",
309
+ " return False\n",
310
+ "\n",
311
+ " print(f\" > Checking files...\")\n",
312
+ " files = os.listdir(path)\n",
313
+ " print(f\" > Files in {name}: {files[:10]}...\")\n",
314
+ "\n",
315
+ " # ビルドキャッシュ削除\n",
316
+ " build_dir = os.path.join(path, \"build\")\n",
317
+ " if os.path.exists(build_dir):\n",
318
+ " print(f\" > Cleaning build cache...\")\n",
319
+ " shutil.rmtree(build_dir)\n",
320
+ "\n",
321
+ " # インストール\n",
322
+ " print(f\" > Installing {name} (This may take a few minutes)...\")\n",
323
+ "\n",
324
+ " current_env = os.environ.copy()\n",
325
+ " result = subprocess.run(\n",
326
+ " [sys.executable, \"-m\", \"pip\", \"install\", \"-e\", \".\", \"--no-build-isolation\", \"-v\"],\n",
327
+ " cwd=path,\n",
328
+ " env=current_env,\n",
329
+ " capture_output=True,\n",
330
+ " text=True\n",
331
+ " )\n",
332
+ "\n",
333
+ " if result.returncode != 0:\n",
334
+ " print(f\"❌ Failed to install {name}\")\n",
335
+ " print(\"\\n--- STDOUT (Build Logs) ---\")\n",
336
+ " stdout_lines = result.stdout.split('\\n')\n",
337
+ " print('\\n'.join(stdout_lines[-60:]))\n",
338
+ " print(\"\\n--- STDERR (Error Details) ---\")\n",
339
+ " print(result.stderr)\n",
340
+ " return False\n",
341
+ "\n",
342
+ " print(f\"✅ Successfully installed {name}\")\n",
343
+ " return True\n",
344
+ "\n",
345
+ "\n",
346
+ "def setup_environment():\n",
347
+ " \"\"\"Setup mip-splatting environment with correct submodules\"\"\"\n",
348
+ " print(\"=\"*70)\n",
349
+ " print(\"Setting up mip-splatting environment\")\n",
350
+ " print(\"=\"*70)\n",
351
+ "\n",
352
+ " WORK_DIR = \"/content/mip-splatting\"\n",
353
+ "\n",
354
+ " # =====================================================================\n",
355
+ " # STEP 1: Clone main repository with submodules\n",
356
+ " # =====================================================================\n",
357
+ " print(\"\\nSTEP 1: Clone mip-splatting repository\")\n",
358
+ " print(\"=\"*70)\n",
359
+ "\n",
360
+ " if os.path.exists(WORK_DIR):\n",
361
+ " print(f\" > {WORK_DIR} already exists, removing...\")\n",
362
+ " shutil.rmtree(WORK_DIR)\n",
363
+ "\n",
364
+ " print(f\" > Cloning mip-splatting with submodules...\")\n",
365
+ " # --recursive で submodules も一緒にクローン\n",
366
+ " run_cmd([\n",
367
+ " \"git\", \"clone\", \"--recursive\",\n",
368
+ " \"https://github.com/autonomousvision/mip-splatting.git\",\n",
369
+ " WORK_DIR\n",
370
+ " ])\n",
371
+ " print(\"✅ Repository cloned with submodules\")\n",
372
+ "\n",
373
+ " # submodulesが正しくクローンされたか確認\n",
374
+ " print(\"\\n > Verifying submodules...\")\n",
375
+ " submodules_dir = os.path.join(WORK_DIR, \"submodules\")\n",
376
+ " if os.path.exists(submodules_dir):\n",
377
+ " items = os.listdir(submodules_dir)\n",
378
+ " print(f\" > Found submodules: {items}\")\n",
379
+ "\n",
380
+ " # 空のsubmoduleディレクトリがある場合は初期化\n",
381
+ " for item in items:\n",
382
+ " item_path = os.path.join(submodules_dir, item)\n",
383
+ " if os.path.isdir(item_path):\n",
384
+ " item_files = os.listdir(item_path)\n",
385
+ " if not item_files or len(item_files) == 0:\n",
386
+ " print(f\" > {item} is empty, initializing...\")\n",
387
+ " run_cmd([\"git\", \"submodule\", \"update\", \"--init\", \"--recursive\"], cwd=WORK_DIR)\n",
388
+ " break\n",
389
+ " # =====================================================================\n",
390
+ " # STEP 1: System packages (Colab)\n",
391
+ " # =====================================================================\n",
392
+ " print(\"\\n\" + \"=\"*70)\n",
393
+ " print(\"STEP 1: System packages\")\n",
394
+ " print(\"=\"*70)\n",
395
+ "\n",
396
+ " run_cmd([\"apt-get\", \"update\", \"-qq\"])\n",
397
+ " run_cmd([\n",
398
+ " \"apt-get\", \"install\", \"-y\", \"-qq\",\n",
399
+ " \"colmap\",\n",
400
+ " \"build-essential\",\n",
401
+ " \"cmake\",\n",
402
+ " \"git\",\n",
403
+ " \"libopenblas-dev\",\n",
404
+ " \"xvfb\"\n",
405
+ " ])\n",
406
+ "\n",
407
+ " # virtual display (COLMAP / OpenCV safety)\n",
408
+ " os.environ[\"QT_QPA_PLATFORM\"] = \"offscreen\"\n",
409
+ " os.environ[\"DISPLAY\"] = \":99\"\n",
410
+ " subprocess.Popen(\n",
411
+ " [\"Xvfb\", \":99\", \"-screen\", \"0\", \"1024x768x24\"],\n",
412
+ " stdout=subprocess.DEVNULL,\n",
413
+ " stderr=subprocess.DEVNULL\n",
414
+ " )\n",
415
+ "\n",
416
+ " # =====================================================================\n",
417
+ " # STEP 2: Fix numpy compatibility\n",
418
+ " # =====================================================================\n",
419
+ " print(\"\\nSTEP 2: Fix numpy compatibility\")\n",
420
+ " print(\"=\"*70)\n",
421
+ "\n",
422
+ " print(\" > Uninstalling numpy 2.x...\")\n",
423
+ " run_cmd([sys.executable, \"-m\", \"pip\", \"uninstall\", \"numpy\", \"-y\"], check=False)\n",
424
+ "\n",
425
+ " print(\" > Installing numpy<2.0...\")\n",
426
+ " run_cmd([sys.executable, \"-m\", \"pip\", \"install\", \"numpy<2.0\"])\n",
427
+ " print(\"✅ numpy<2.0 installed\")\n",
428
+ "\n",
429
+ " # =====================================================================\n",
430
+ " # STEP 3: Install core dependencies\n",
431
+ " # =====================================================================\n",
432
+ " print(\"\\nSTEP 3: Install core dependencies\")\n",
433
+ " print(\"=\"*70)\n",
434
+ "\n",
435
+ " core_packages = [\n",
436
+ " \"open3d\",\n",
437
+ " \"plyfile\",\n",
438
+ " \"tqdm\",\n",
439
+ " \"Pillow\",\n",
440
+ " \"opencv-python\"\n",
441
+ " ]\n",
442
+ "\n",
443
+ " for package in core_packages:\n",
444
+ " print(f\" > Installing {package}...\")\n",
445
+ " run_cmd([sys.executable, \"-m\", \"pip\", \"install\", package])\n",
446
+ " print(\"✅ Core dependencies installed\")\n",
447
+ "\n",
448
+ " # =====================================================================\n",
449
+ " # STEP 4: Build mip-splatting submodules\n",
450
+ " # =====================================================================\n",
451
+ " print(\"\\nSTEP 4: Build mip-splatting submodules\")\n",
452
+ " print(\"=\"*70)\n",
453
+ "\n",
454
+ " # simple-knn: 実績のあるfixed版を使用(クローンし直す)\n",
455
+ " success_knn = install_submodule(\n",
456
+ " \"simple-knn\",\n",
457
+ " \"https://github.com/tztechno/simple-knn.git\",\n",
458
+ " WORK_DIR\n",
459
+ " )\n",
460
+ "\n",
461
+ " if not success_knn:\n",
462
+ " print(\"❌ Failed to install simple-knn\")\n",
463
+ " return None\n",
464
+ "\n",
465
+ " # diff-gaussian-rasterization: mip-splattingに含まれているものを使用\n",
466
+ " # (kernel_size対応版なのでクローンし直さない)\n",
467
+ " success_rast = install_mipsplatting_submodule(\n",
468
+ " \"diff-gaussian-rasterization\",\n",
469
+ " WORK_DIR\n",
470
+ " )\n",
471
+ "\n",
472
+ " if not success_rast:\n",
473
+ " print(\"❌ Failed to install diff-gaussian-rasterization\")\n",
474
+ " return None\n",
475
+ "\n",
476
+ "\n",
477
+ " return WORK_DIR\n",
478
+ "\n",
479
+ "\n",
480
+ "\n",
481
+ "work_dir = setup_environment()\n",
482
+ "\n"
483
+ ]
484
+ },
485
+ {
486
+ "cell_type": "code",
487
+ "execution_count": 6,
488
+ "id": "b8690389",
489
+ "metadata": {
490
+ "execution": {
491
+ "iopub.execute_input": "2026-01-10T18:22:43.739411Z",
492
+ "iopub.status.busy": "2026-01-10T18:22:43.738855Z",
493
+ "iopub.status.idle": "2026-01-10T18:22:43.755664Z",
494
+ "shell.execute_reply": "2026-01-10T18:22:43.754865Z"
495
+ },
496
+ "papermill": {
497
+ "duration": 0.027297,
498
+ "end_time": "2026-01-10T18:22:43.756758",
499
+ "exception": false,
500
+ "start_time": "2026-01-10T18:22:43.729461",
501
+ "status": "completed"
502
+ },
503
+ "tags": [],
504
+ "id": "b8690389"
505
+ },
506
+ "outputs": [],
507
+ "source": [
508
+ "import os\n",
509
+ "import glob\n",
510
+ "import cv2\n",
511
+ "import numpy as np\n",
512
+ "from PIL import Image\n",
513
+ "\n",
514
+ "# =========================================================\n",
515
+ "# Utility: aspect ratio preserved + black padding\n",
516
+ "# =========================================================\n",
517
+ "\n",
518
+ "def normalize_image_sizes_biplet(input_dir, output_dir=None, size=1024, max_images=None):\n",
519
+ " \"\"\"\n",
520
+ " Generates two square crops (Left & Right or Top & Bottom)\n",
521
+ " from each image in a directory and returns the output directory\n",
522
+ " and the list of generated file paths.\n",
523
+ "\n",
524
+ " Args:\n",
525
+ " input_dir: Input directory containing source images\n",
526
+ " output_dir: Output directory for processed images\n",
527
+ " size: Target square size (default: 1024)\n",
528
+ " max_images: Maximum number of SOURCE images to process (default: None = all images)\n",
529
+ " \"\"\"\n",
530
+ " if output_dir is None:\n",
531
+ " output_dir = 'output/images_biplet'\n",
532
+ " os.makedirs(output_dir, exist_ok=True)\n",
533
+ "\n",
534
+ " print(f\"--- Step 1: Biplet-Square Normalization ---\")\n",
535
+ " print(f\"Generating 2 cropped squares (Left/Right or Top/Bottom) for each image...\")\n",
536
+ " print()\n",
537
+ "\n",
538
+ " generated_paths = []\n",
539
+ " converted_count = 0\n",
540
+ " size_stats = {}\n",
541
+ "\n",
542
+ " # Sort for consistent processing order\n",
543
+ " image_files = sorted([f for f in os.listdir(input_dir)\n",
544
+ " if f.lower().endswith(('.jpg', '.jpeg', '.png'))])\n",
545
+ "\n",
546
+ " # ★ max_images で元画像数を制限\n",
547
+ " if max_images is not None:\n",
548
+ " image_files = image_files[:max_images]\n",
549
+ " print(f\"Processing limited to {max_images} source images (will generate {max_images * 2} cropped images)\")\n",
550
+ "\n",
551
+ " for img_file in image_files:\n",
552
+ " input_path = os.path.join(input_dir, img_file)\n",
553
+ " try:\n",
554
+ " img = Image.open(input_path)\n",
555
+ " original_size = img.size\n",
556
+ "\n",
557
+ " # Tracking original aspect ratios\n",
558
+ " size_key = f\"{original_size[0]}x{original_size[1]}\"\n",
559
+ " size_stats[size_key] = size_stats.get(size_key, 0) + 1\n",
560
+ "\n",
561
+ " # Generate 2 crops using the helper function\n",
562
+ " crops = generate_two_crops(img, size)\n",
563
+ " base_name, ext = os.path.splitext(img_file)\n",
564
+ "\n",
565
+ " for mode, cropped_img in crops.items():\n",
566
+ " output_path = os.path.join(output_dir, f\"{base_name}_{mode}{ext}\")\n",
567
+ " cropped_img.save(output_path, quality=95)\n",
568
+ " generated_paths.append(output_path)\n",
569
+ "\n",
570
+ " converted_count += 1\n",
571
+ " print(f\" ✓ {img_file}: {original_size} → 2 square images generated\")\n",
572
+ "\n",
573
+ " except Exception as e:\n",
574
+ " print(f\" ✗ Error processing {img_file}: {e}\")\n",
575
+ "\n",
576
+ " print(f\"\\nProcessing complete: {converted_count} source images processed\")\n",
577
+ " print(f\"Total output images: {len(generated_paths)}\")\n",
578
+ " print(f\"Original size distribution: {size_stats}\")\n",
579
+ "\n",
580
+ " return output_dir, generated_paths\n",
581
+ "\n",
582
+ "\n",
583
+ "def generate_two_crops(img, size):\n",
584
+ " \"\"\"\n",
585
+ " Crops the image into a square and returns 2 variations\n",
586
+ " (Left/Right for landscape, Top/Bottom for portrait).\n",
587
+ " \"\"\"\n",
588
+ " width, height = img.size\n",
589
+ " crop_size = min(width, height)\n",
590
+ " crops = {}\n",
591
+ "\n",
592
+ " if width > height:\n",
593
+ " # Landscape → Left & Right\n",
594
+ " positions = {\n",
595
+ " 'left': 0,\n",
596
+ " 'right': width - crop_size\n",
597
+ " }\n",
598
+ " for mode, x_offset in positions.items():\n",
599
+ " box = (x_offset, 0, x_offset + crop_size, crop_size)\n",
600
+ " crops[mode] = img.crop(box).resize(\n",
601
+ " (size, size),\n",
602
+ " Image.Resampling.LANCZOS\n",
603
+ " )\n",
604
+ "\n",
605
+ " else:\n",
606
+ " # Portrait or Square → Top & Bottom\n",
607
+ " positions = {\n",
608
+ " 'top': 0,\n",
609
+ " 'bottom': height - crop_size\n",
610
+ " }\n",
611
+ " for mode, y_offset in positions.items():\n",
612
+ " box = (0, y_offset, crop_size, y_offset + crop_size)\n",
613
+ " crops[mode] = img.crop(box).resize(\n",
614
+ " (size, size),\n",
615
+ " Image.Resampling.LANCZOS\n",
616
+ " )\n",
617
+ "\n",
618
+ " return crops\n"
619
+ ]
620
+ },
621
+ {
622
+ "cell_type": "code",
623
+ "execution_count": 7,
624
+ "id": "7acc20b6",
625
+ "metadata": {
626
+ "execution": {
627
+ "iopub.execute_input": "2026-01-10T18:22:43.772525Z",
628
+ "iopub.status.busy": "2026-01-10T18:22:43.772303Z",
629
+ "iopub.status.idle": "2026-01-10T18:22:43.790574Z",
630
+ "shell.execute_reply": "2026-01-10T18:22:43.789515Z"
631
+ },
632
+ "papermill": {
633
+ "duration": 0.027612,
634
+ "end_time": "2026-01-10T18:22:43.791681",
635
+ "exception": false,
636
+ "start_time": "2026-01-10T18:22:43.764069",
637
+ "status": "completed"
638
+ },
639
+ "tags": [],
640
+ "id": "7acc20b6"
641
+ },
642
+ "outputs": [],
643
+ "source": [
644
+ "def run_colmap_reconstruction(image_dir, colmap_dir):\n",
645
+ " \"\"\"Estimate camera poses and 3D point cloud with COLMAP\"\"\"\n",
646
+ " print(\"Running SfM reconstruction with COLMAP...\")\n",
647
+ "\n",
648
+ " database_path = os.path.join(colmap_dir, \"database.db\")\n",
649
+ " sparse_dir = os.path.join(colmap_dir, \"sparse\")\n",
650
+ " os.makedirs(sparse_dir, exist_ok=True)\n",
651
+ "\n",
652
+ " # Set environment variable\n",
653
+ " env = os.environ.copy()\n",
654
+ " env['QT_QPA_PLATFORM'] = 'offscreen'\n",
655
+ "\n",
656
+ " # Feature extraction\n",
657
+ " print(\"1/4: Extracting features...\")\n",
658
+ " subprocess.run([\n",
659
+ " 'colmap', 'feature_extractor',\n",
660
+ " '--database_path', database_path,\n",
661
+ " '--image_path', image_dir,\n",
662
+ " '--ImageReader.single_camera', '1',\n",
663
+ " '--ImageReader.camera_model', 'OPENCV',\n",
664
+ " '--SiftExtraction.use_gpu', '0' # Use CPU\n",
665
+ " ], check=True, env=env)\n",
666
+ "\n",
667
+ " # Feature matching\n",
668
+ " print(\"2/4: Matching features...\")\n",
669
+ " subprocess.run([\n",
670
+ " 'colmap', 'exhaustive_matcher', # Use sequential_matcher instead of exhaustive_matcher\n",
671
+ " '--database_path', database_path,\n",
672
+ " '--SiftMatching.use_gpu', '0' # Use CPU\n",
673
+ " ], check=True, env=env)\n",
674
+ "\n",
675
+ " # Sparse reconstruction\n",
676
+ " print(\"3/4: Sparse reconstruction...\")\n",
677
+ " subprocess.run([\n",
678
+ " 'colmap', 'mapper',\n",
679
+ " '--database_path', database_path,\n",
680
+ " '--image_path', image_dir,\n",
681
+ " '--output_path', sparse_dir,\n",
682
+ " '--Mapper.ba_global_max_num_iterations', '20', # Speed up\n",
683
+ " '--Mapper.ba_local_max_num_iterations', '10'\n",
684
+ " ], check=True, env=env)\n",
685
+ "\n",
686
+ " # Export to text format\n",
687
+ " print(\"4/4: Exporting to text format...\")\n",
688
+ " model_dir = os.path.join(sparse_dir, '0')\n",
689
+ " if not os.path.exists(model_dir):\n",
690
+ " # Use the first model found\n",
691
+ " subdirs = [d for d in os.listdir(sparse_dir) if os.path.isdir(os.path.join(sparse_dir, d))]\n",
692
+ " if subdirs:\n",
693
+ " model_dir = os.path.join(sparse_dir, subdirs[0])\n",
694
+ " else:\n",
695
+ " raise FileNotFoundError(\"COLMAP reconstruction failed\")\n",
696
+ "\n",
697
+ " subprocess.run([\n",
698
+ " 'colmap', 'model_converter',\n",
699
+ " '--input_path', model_dir,\n",
700
+ " '--output_path', model_dir,\n",
701
+ " '--output_type', 'TXT'\n",
702
+ " ], check=True, env=env)\n",
703
+ "\n",
704
+ " print(f\"COLMAP reconstruction complete: {model_dir}\")\n",
705
+ " return model_dir\n",
706
+ "\n",
707
+ "\n",
708
+ "def convert_cameras_to_pinhole(input_file, output_file):\n",
709
+ " \"\"\"Convert camera model to PINHOLE format\"\"\"\n",
710
+ " print(f\"Reading camera file: {input_file}\")\n",
711
+ "\n",
712
+ " with open(input_file, 'r') as f:\n",
713
+ " lines = f.readlines()\n",
714
+ "\n",
715
+ " converted_count = 0\n",
716
+ " with open(output_file, 'w') as f:\n",
717
+ " for line in lines:\n",
718
+ " if line.startswith('#') or line.strip() == '':\n",
719
+ " f.write(line)\n",
720
+ " else:\n",
721
+ " parts = line.strip().split()\n",
722
+ " if len(parts) >= 4:\n",
723
+ " cam_id = parts[0]\n",
724
+ " model = parts[1]\n",
725
+ " width = parts[2]\n",
726
+ " height = parts[3]\n",
727
+ " params = parts[4:]\n",
728
+ "\n",
729
+ " # Convert to PINHOLE format\n",
730
+ " if model == \"PINHOLE\":\n",
731
+ " f.write(line)\n",
732
+ " elif model == \"OPENCV\":\n",
733
+ " # OPENCV: fx, fy, cx, cy, k1, k2, p1, p2\n",
734
+ " fx = params[0]\n",
735
+ " fy = params[1]\n",
736
+ " cx = params[2]\n",
737
+ " cy = params[3]\n",
738
+ " f.write(f\"{cam_id} PINHOLE {width} {height} {fx} {fy} {cx} {cy}\\n\")\n",
739
+ " converted_count += 1\n",
740
+ " else:\n",
741
+ " # Convert other models too\n",
742
+ " fx = fy = max(float(width), float(height))\n",
743
+ " cx = float(width) / 2\n",
744
+ " cy = float(height) / 2\n",
745
+ " f.write(f\"{cam_id} PINHOLE {width} {height} {fx} {fy} {cx} {cy}\\n\")\n",
746
+ " converted_count += 1\n",
747
+ " else:\n",
748
+ " f.write(line)\n",
749
+ "\n",
750
+ " print(f\"Converted {converted_count} cameras to PINHOLE format\")\n",
751
+ "\n",
752
+ "\n",
753
+ "def prepare_gaussian_splatting_data(image_dir, colmap_model_dir):\n",
754
+ " \"\"\"Prepare data for Gaussian Splatting\"\"\"\n",
755
+ " print(\"Preparing data for Gaussian Splatting...\")\n",
756
+ "\n",
757
+ " data_dir = f\"{WORK_DIR}/data/video\"\n",
758
+ " os.makedirs(f\"{data_dir}/sparse/0\", exist_ok=True)\n",
759
+ " os.makedirs(f\"{data_dir}/images\", exist_ok=True)\n",
760
+ "\n",
761
+ " # Copy images\n",
762
+ " print(\"Copying images...\")\n",
763
+ " img_count = 0\n",
764
+ " for img_file in os.listdir(image_dir):\n",
765
+ " if img_file.lower().endswith(('.jpg', '.jpeg', '.png')):\n",
766
+ " shutil.copy(\n",
767
+ " os.path.join(image_dir, img_file),\n",
768
+ " f\"{data_dir}/images/{img_file}\"\n",
769
+ " )\n",
770
+ " img_count += 1\n",
771
+ " print(f\"Copied {img_count} images\")\n",
772
+ "\n",
773
+ " # Convert and copy camera file to PINHOLE format\n",
774
+ " print(\"Converting camera model to PINHOLE format...\")\n",
775
+ " convert_cameras_to_pinhole(\n",
776
+ " os.path.join(colmap_model_dir, 'cameras.txt'),\n",
777
+ " f\"{data_dir}/sparse/0/cameras.txt\"\n",
778
+ " )\n",
779
+ "\n",
780
+ " # Copy other files\n",
781
+ " for filename in ['images.txt', 'points3D.txt']:\n",
782
+ " src = os.path.join(colmap_model_dir, filename)\n",
783
+ " dst = f\"{data_dir}/sparse/0/{filename}\"\n",
784
+ " if os.path.exists(src):\n",
785
+ " shutil.copy(src, dst)\n",
786
+ " print(f\"Copied {filename}\")\n",
787
+ " else:\n",
788
+ " print(f\"Warning: {filename} not found\")\n",
789
+ "\n",
790
+ " print(f\"Data preparation complete: {data_dir}\")\n",
791
+ " return data_dir\n",
792
+ "\n",
793
+ "\n",
794
+ "\n",
795
+ "\n",
796
+ "# After (mipGS) - Added Kernel Size and Multi-Scale Support\n",
797
+ "def train_gaussian_splatting(data_dir, work_dir, iterations=3000):\n",
798
+ " \"\"\"Training function for mipGS with comprehensive error handling\"\"\"\n",
799
+ "\n",
800
+ " # 入力検証\n",
801
+ " if not work_dir:\n",
802
+ " raise ValueError(\"work_dir cannot be None or empty\")\n",
803
+ "\n",
804
+ " if not os.path.exists(work_dir):\n",
805
+ " raise FileNotFoundError(f\"Work directory not found: {work_dir}\")\n",
806
+ "\n",
807
+ " if not os.path.exists(data_dir):\n",
808
+ " raise FileNotFoundError(f\"Data directory not found: {data_dir}\")\n",
809
+ "\n",
810
+ " train_py_path = os.path.join(work_dir, \"train.py\")\n",
811
+ " if not os.path.exists(train_py_path):\n",
812
+ " raise FileNotFoundError(f\"train.py not found: {train_py_path}\")\n",
813
+ "\n",
814
+ " # モデル保存パス\n",
815
+ " model_path = os.path.join(work_dir, \"output\", \"video\")\n",
816
+ " os.makedirs(model_path, exist_ok=True)\n",
817
+ "\n",
818
+ " # コマンド構築\n",
819
+ " cmd = [\n",
820
+ " sys.executable, 'train.py',\n",
821
+ " '-s', data_dir,\n",
822
+ " '-m', model_path,\n",
823
+ " '--iterations', str(iterations),\n",
824
+ " '--eval'\n",
825
+ " ]\n",
826
+ "\n",
827
+ " print(f\"Training configuration:\")\n",
828
+ " print(f\" Work dir: {work_dir}\")\n",
829
+ " print(f\" Data dir: {data_dir}\")\n",
830
+ " print(f\" Model path: {model_path}\")\n",
831
+ " print(f\" Command: {' '.join(cmd)}\")\n",
832
+ "\n",
833
+ " # 実行\n",
834
+ " result = subprocess.run(\n",
835
+ " cmd,\n",
836
+ " cwd=work_dir,\n",
837
+ " capture_output=True,\n",
838
+ " text=True\n",
839
+ " )\n",
840
+ "\n",
841
+ " # エラーチェック\n",
842
+ " if result.returncode != 0:\n",
843
+ " print(f\"\\n❌ Training failed with exit code {result.returncode}\")\n",
844
+ " print(\"\\n--- STDOUT ---\")\n",
845
+ " print(result.stdout)\n",
846
+ " print(\"\\n--- STDERR ---\")\n",
847
+ " print(result.stderr)\n",
848
+ " raise subprocess.CalledProcessError(result.returncode, cmd)\n",
849
+ "\n",
850
+ " print(\"\\n✅ Training completed successfully\")\n",
851
+ " return model_path\n",
852
+ "\n"
853
+ ]
854
+ },
855
+ {
856
+ "cell_type": "code",
857
+ "source": [
858
+ "# New function for mipGS - Fuse 3D filter into Gaussian parameters\n",
859
+ "def create_fused_ply(model_path, scene_name, output_dir=\"fused\"):\n",
860
+ " \"\"\"\n",
861
+ " Fuse the 3D smoothing filter to Gaussian parameters for deployment\n",
862
+ " This creates a .ply file that can be used in online viewers\n",
863
+ "\n",
864
+ " Args:\n",
865
+ " model_path: Path to trained model\n",
866
+ " scene_name: Name of the scene\n",
867
+ " output_dir: Directory to save fused .ply file\n",
868
+ " \"\"\"\n",
869
+ " os.makedirs(output_dir, exist_ok=True)\n",
870
+ " output_ply = f\"{output_dir}/{scene_name}_fused.ply\"\n",
871
+ "\n",
872
+ " cmd = [\n",
873
+ " sys.executable, 'create_fused_ply.py',\n",
874
+ " '-m', f\"{model_path}/{scene_name}\",\n",
875
+ " '--output_ply', output_ply\n",
876
+ " ]\n",
877
+ " subprocess.run(cmd, cwd=WORK_DIR, check=True)\n",
878
+ " return output_ply\n",
879
+ ""
880
+ ],
881
+ "metadata": {
882
+ "id": "-Cwgr3I0b57O"
883
+ },
884
+ "id": "-Cwgr3I0b57O",
885
+ "execution_count": 8,
886
+ "outputs": []
887
+ },
888
+ {
889
+ "cell_type": "code",
890
+ "execution_count": 9,
891
+ "id": "f75233a8",
892
+ "metadata": {
893
+ "execution": {
894
+ "iopub.execute_input": "2026-01-10T18:22:43.807508Z",
895
+ "iopub.status.busy": "2026-01-10T18:22:43.807294Z",
896
+ "iopub.status.idle": "2026-01-11T00:00:17.030890Z",
897
+ "shell.execute_reply": "2026-01-11T00:00:17.029927Z"
898
+ },
899
+ "papermill": {
900
+ "duration": 20253.434865,
901
+ "end_time": "2026-01-11T00:00:17.234174",
902
+ "exception": false,
903
+ "start_time": "2026-01-10T18:22:43.799309",
904
+ "status": "completed"
905
+ },
906
+ "tags": [],
907
+ "id": "f75233a8",
908
+ "outputId": "4d068a8d-5a0b-4fb5-dbc7-c89fe2422fd6",
909
+ "colab": {
910
+ "base_uri": "https://localhost:8080/"
911
+ }
912
+ },
913
+ "outputs": [
914
+ {
915
+ "output_type": "stream",
916
+ "name": "stdout",
917
+ "text": [
918
+ "============================================================\n",
919
+ "Step 1: Normalizing and preprocessing images\n",
920
+ "============================================================\n",
921
+ "--- Step 1: Biplet-Square Normalization ---\n",
922
+ "Generating 2 cropped squares (Left/Right or Top/Bottom) for each image...\n",
923
+ "\n",
924
+ "Processing limited to 20 source images (will generate 40 cropped images)\n",
925
+ " ✓ image_101.jpeg: (1440, 1920) → 2 square images generated\n",
926
+ " ✓ image_102.jpeg: (1440, 1920) → 2 square images generated\n",
927
+ " ✓ image_103.jpeg: (1440, 1920) → 2 square images generated\n",
928
+ " ✓ image_104.jpeg: (1440, 1920) → 2 square images generated\n",
929
+ " ✓ image_105.jpeg: (1440, 1920) → 2 square images generated\n",
930
+ " ✓ image_106.jpeg: (1440, 1920) → 2 square images generated\n",
931
+ " ✓ image_107.jpeg: (1440, 1920) → 2 square images generated\n",
932
+ " ✓ image_108.jpeg: (1440, 1920) → 2 square images generated\n",
933
+ " ✓ image_109.jpeg: (1440, 1920) → 2 square images generated\n",
934
+ " ✓ image_110.jpeg: (1440, 1920) → 2 square images generated\n",
935
+ " ✓ image_111.jpeg: (1440, 1920) → 2 square images generated\n",
936
+ " ✓ image_112.jpeg: (1440, 1920) → 2 square images generated\n",
937
+ " ✓ image_113.jpeg: (1440, 1920) → 2 square images generated\n",
938
+ " ✓ image_114.jpeg: (1440, 1920) → 2 square images generated\n",
939
+ " ✓ image_115.jpeg: (1440, 1920) → 2 square images generated\n",
940
+ " ✓ image_116.jpeg: (1440, 1920) → 2 square images generated\n",
941
+ " ✓ image_117.jpeg: (1440, 1920) → 2 square images generated\n",
942
+ " ✓ image_118.jpeg: (1440, 1920) → 2 square images generated\n",
943
+ " ✓ image_119.jpeg: (1440, 1920) → 2 square images generated\n",
944
+ " ✓ image_120.jpeg: (1440, 1920) → 2 square images generated\n",
945
+ "\n",
946
+ "Processing complete: 20 source images processed\n",
947
+ "Total output images: 40\n",
948
+ "Original size distribution: {'1440x1920': 20}\n",
949
+ "Processed ('/content/colmap/images', ['/content/colmap/images/image_101_top.jpeg', '/content/colmap/images/image_101_bottom.jpeg', '/content/colmap/images/image_102_top.jpeg', '/content/colmap/images/image_102_bottom.jpeg', '/content/colmap/images/image_103_top.jpeg', '/content/colmap/images/image_103_bottom.jpeg', '/content/colmap/images/image_104_top.jpeg', '/content/colmap/images/image_104_bottom.jpeg', '/content/colmap/images/image_105_top.jpeg', '/content/colmap/images/image_105_bottom.jpeg', '/content/colmap/images/image_106_top.jpeg', '/content/colmap/images/image_106_bottom.jpeg', '/content/colmap/images/image_107_top.jpeg', '/content/colmap/images/image_107_bottom.jpeg', '/content/colmap/images/image_108_top.jpeg', '/content/colmap/images/image_108_bottom.jpeg', '/content/colmap/images/image_109_top.jpeg', '/content/colmap/images/image_109_bottom.jpeg', '/content/colmap/images/image_110_top.jpeg', '/content/colmap/images/image_110_bottom.jpeg', '/content/colmap/images/image_111_top.jpeg', '/content/colmap/images/image_111_bottom.jpeg', '/content/colmap/images/image_112_top.jpeg', '/content/colmap/images/image_112_bottom.jpeg', '/content/colmap/images/image_113_top.jpeg', '/content/colmap/images/image_113_bottom.jpeg', '/content/colmap/images/image_114_top.jpeg', '/content/colmap/images/image_114_bottom.jpeg', '/content/colmap/images/image_115_top.jpeg', '/content/colmap/images/image_115_bottom.jpeg', '/content/colmap/images/image_116_top.jpeg', '/content/colmap/images/image_116_bottom.jpeg', '/content/colmap/images/image_117_top.jpeg', '/content/colmap/images/image_117_bottom.jpeg', '/content/colmap/images/image_118_top.jpeg', '/content/colmap/images/image_118_bottom.jpeg', '/content/colmap/images/image_119_top.jpeg', '/content/colmap/images/image_119_bottom.jpeg', '/content/colmap/images/image_120_top.jpeg', '/content/colmap/images/image_120_bottom.jpeg']) images\n",
950
+ "============================================================\n",
951
+ "Step 2: Running COLMAP reconstruction\n",
952
+ "============================================================\n",
953
+ "Running SfM reconstruction with COLMAP...\n",
954
+ "1/4: Extracting features...\n",
955
+ "2/4: Matching features...\n",
956
+ "3/4: Sparse reconstruction...\n",
957
+ "4/4: Exporting to text format...\n",
958
+ "COLMAP reconstruction complete: /content/colmap/sparse/0\n",
959
+ "/content/colmap/images\n",
960
+ "/content/colmap/sparse/0\n",
961
+ "============================================================\n",
962
+ "Step 3: Preparing Gaussian Splatting data\n",
963
+ "============================================================\n",
964
+ "Preparing data for Gaussian Splatting...\n",
965
+ "Copying images...\n",
966
+ "Copied 40 images\n",
967
+ "Converting camera model to PINHOLE format...\n",
968
+ "Reading camera file: /content/colmap/sparse/0/cameras.txt\n",
969
+ "Converted 1 cameras to PINHOLE format\n",
970
+ "Copied images.txt\n",
971
+ "Copied points3D.txt\n",
972
+ "Data preparation complete: /content/mip-splatting/data/video\n",
973
+ "============================================================\n",
974
+ "Step 4: Training Gaussian Splatting model\n",
975
+ "============================================================\n",
976
+ "Training configuration:\n",
977
+ " Work dir: /content/mip-splatting\n",
978
+ " Data dir: /content/mip-splatting/data/video\n",
979
+ " Model path: /content/mip-splatting/output/video\n",
980
+ " Command: /usr/bin/python3 train.py -s /content/mip-splatting/data/video -m /content/mip-splatting/output/video --iterations 3000 --eval\n",
981
+ "\n",
982
+ "✅ Training completed successfully\n"
983
+ ]
984
+ }
985
+ ],
986
+ "source": [
987
+ "def main_pipeline(image_dir, output_dir,\n",
988
+ " square_size=1024, max_images=100):\n",
989
+ " \"\"\"Main execution function\"\"\"\n",
990
+ " try:\n",
991
+ " # Step 1: 画像の正規化と前処理\n",
992
+ " print(\"=\"*60)\n",
993
+ " print(\"Step 1: Normalizing and preprocessing images\")\n",
994
+ " print(\"=\"*60)\n",
995
+ "\n",
996
+ " frame_dir = os.path.join(COLMAP_DIR, \"images\")\n",
997
+ " os.makedirs(frame_dir, exist_ok=True)\n",
998
+ "\n",
999
+ " # 画像を正規化して直接COLMAPのディレクトリに保存\n",
1000
+ " num_processed = normalize_image_sizes_biplet(\n",
1001
+ " input_dir=image_dir,\n",
1002
+ " output_dir=frame_dir, # 直接colmap/imagesに保存\n",
1003
+ " size=square_size,\n",
1004
+ " max_images=max_images\n",
1005
+ " )\n",
1006
+ "\n",
1007
+ " print(f\"Processed {num_processed} images\")\n",
1008
+ "\n",
1009
+ " # Step 2: Estimate Camera Info with COLMAP\n",
1010
+ " print(\"=\"*60)\n",
1011
+ " print(\"Step 2: Running COLMAP reconstruction\")\n",
1012
+ " print(\"=\"*60)\n",
1013
+ " colmap_model_dir = run_colmap_reconstruction(frame_dir, COLMAP_DIR)\n",
1014
+ "\n",
1015
+ " print(frame_dir)\n",
1016
+ " print(colmap_model_dir)\n",
1017
+ "\n",
1018
+ " # Step 3: Prepare Data for Gaussian Splatting\n",
1019
+ " print(\"=\"*60)\n",
1020
+ " print(\"Step 3: Preparing Gaussian Splatting data\")\n",
1021
+ " print(\"=\"*60)\n",
1022
+ " data_dir = prepare_gaussian_splatting_data(frame_dir, colmap_model_dir)\n",
1023
+ "\n",
1024
+ " # Step 4: Train Model\n",
1025
+ " print(\"=\"*60)\n",
1026
+ " print(\"Step 4: Training Gaussian Splatting model\")\n",
1027
+ " print(\"=\"*60)\n",
1028
+ " model_path = train_gaussian_splatting(\n",
1029
+ " data_dir=data_dir,\n",
1030
+ " work_dir=work_dir, # 明示的に渡す\n",
1031
+ " iterations=3000\n",
1032
+ " )\n",
1033
+ "\n",
1034
+ " return ply_path\n",
1035
+ "\n",
1036
+ " except Exception as e:\n",
1037
+ " print(f\"Error: {str(e)}\")\n",
1038
+ " import traceback\n",
1039
+ " traceback.print_exc()\n",
1040
+ " return None, None\n",
1041
+ "\n",
1042
+ "\n",
1043
+ "\n",
1044
+ "\n",
1045
+ "if __name__ == \"__main__\":\n",
1046
+ " IMAGE_DIR = \"/content/drive/MyDrive/your_folder/fountain100\"\n",
1047
+ " OUTPUT_DIR = \"/content/output\"\n",
1048
+ " COLMAP_DIR = \"/content/colmap\"\n",
1049
+ "\n",
1050
+ " ply_path = main_pipeline(\n",
1051
+ " image_dir=IMAGE_DIR,\n",
1052
+ " output_dir=OUTPUT_DIR,\n",
1053
+ " square_size=1024,\n",
1054
+ " max_images=20\n",
1055
+ " )\n",
1056
+ "\n",
1057
+ "\n"
1058
+ ]
1059
+ },
1060
+ {
1061
+ "cell_type": "markdown",
1062
+ "id": "e17ec719",
1063
+ "metadata": {
1064
+ "papermill": {
1065
+ "duration": 0.49801,
1066
+ "end_time": "2026-01-11T00:00:18.165833",
1067
+ "exception": false,
1068
+ "start_time": "2026-01-11T00:00:17.667823",
1069
+ "status": "completed"
1070
+ },
1071
+ "tags": [],
1072
+ "id": "e17ec719"
1073
+ },
1074
+ "source": []
1075
+ },
1076
+ {
1077
+ "cell_type": "markdown",
1078
+ "id": "38b3974c",
1079
+ "metadata": {
1080
+ "papermill": {
1081
+ "duration": 0.427583,
1082
+ "end_time": "2026-01-11T00:00:19.008387",
1083
+ "exception": false,
1084
+ "start_time": "2026-01-11T00:00:18.580804",
1085
+ "status": "completed"
1086
+ },
1087
+ "tags": [],
1088
+ "id": "38b3974c"
1089
+ },
1090
+ "source": []
1091
+ }
1092
+ ],
1093
+ "metadata": {
1094
+ "kaggle": {
1095
+ "accelerator": "nvidiaTeslaT4",
1096
+ "dataSources": [
1097
+ {
1098
+ "databundleVersionId": 5447706,
1099
+ "sourceId": 49349,
1100
+ "sourceType": "competition"
1101
+ },
1102
+ {
1103
+ "datasetId": 1429416,
1104
+ "sourceId": 14451718,
1105
+ "sourceType": "datasetVersion"
1106
+ }
1107
+ ],
1108
+ "dockerImageVersionId": 31090,
1109
+ "isGpuEnabled": true,
1110
+ "isInternetEnabled": true,
1111
+ "language": "python",
1112
+ "sourceType": "notebook"
1113
+ },
1114
+ "kernelspec": {
1115
+ "display_name": "Python 3",
1116
+ "name": "python3"
1117
+ },
1118
+ "language_info": {
1119
+ "codemirror_mode": {
1120
+ "name": "ipython",
1121
+ "version": 3
1122
+ },
1123
+ "file_extension": ".py",
1124
+ "mimetype": "text/x-python",
1125
+ "name": "python",
1126
+ "nbconvert_exporter": "python",
1127
+ "pygments_lexer": "ipython3",
1128
+ "version": "3.11.13"
1129
+ },
1130
+ "papermill": {
1131
+ "default_parameters": {},
1132
+ "duration": 20573.990788,
1133
+ "end_time": "2026-01-11T00:00:22.081506",
1134
+ "environment_variables": {},
1135
+ "exception": null,
1136
+ "input_path": "__notebook__.ipynb",
1137
+ "output_path": "__notebook__.ipynb",
1138
+ "parameters": {},
1139
+ "start_time": "2026-01-10T18:17:28.090718",
1140
+ "version": "2.6.0"
1141
+ },
1142
+ "colab": {
1143
+ "provenance": [],
1144
+ "gpuType": "T4"
1145
+ },
1146
+ "accelerator": "GPU"
1147
+ },
1148
+ "nbformat": 4,
1149
+ "nbformat_minor": 5
1150
+ }