stpete2 commited on
Commit
66d232a
·
verified ·
1 Parent(s): ac58af5

Upload 2 files

Browse files
biplet_colmap_mipgs_colab_05.ipynb ADDED
@@ -0,0 +1,1422 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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": "1d0fd2f8-4f1e-43d3-9ab8-4738e392ce9e"
34
+ },
35
+ "id": "JON4rYSEOzCg",
36
+ "execution_count": 24,
37
+ "outputs": [
38
+ {
39
+ "output_type": "stream",
40
+ "name": "stdout",
41
+ "text": [
42
+ "Drive already mounted at /content/drive; to attempt to forcibly remount, call drive.mount(\"/content/drive\", force_remount=True).\n"
43
+ ]
44
+ }
45
+ ]
46
+ },
47
+ {
48
+ "cell_type": "code",
49
+ "execution_count": 25,
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": 25,
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": 26,
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": "48277509-8ff8-431b-ec5f-ef16b1282a7c",
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
+ " > /content/mip-splatting already exists, removing...\n",
148
+ " > Cloning mip-splatting...\n",
149
+ "Running: git clone https://github.com/autonomousvision/mip-splatting.git /content/mip-splatting\n",
150
+ "✅ Repository cloned\n",
151
+ "\n",
152
+ "STEP 2: Fix numpy compatibility\n",
153
+ "======================================================================\n",
154
+ " > Uninstalling numpy 2.x...\n",
155
+ "Running: /usr/bin/python3 -m pip uninstall numpy -y\n",
156
+ " > Installing numpy<2.0...\n",
157
+ "Running: /usr/bin/python3 -m pip install numpy<2.0\n",
158
+ "✅ numpy<2.0 installed\n",
159
+ "\n",
160
+ "STEP 3: Install core dependencies\n",
161
+ "======================================================================\n",
162
+ " > Installing open3d==0.17.0...\n",
163
+ "Running: /usr/bin/python3 -m pip install open3d==0.17.0\n",
164
+ "❌ Command failed with code 1\n",
165
+ " > Installing plyfile...\n",
166
+ "Running: /usr/bin/python3 -m pip install plyfile\n",
167
+ " > Installing tqdm...\n",
168
+ "Running: /usr/bin/python3 -m pip install tqdm\n",
169
+ " > Installing Pillow...\n",
170
+ "Running: /usr/bin/python3 -m pip install Pillow\n",
171
+ " > Installing opencv-python...\n",
172
+ "Running: /usr/bin/python3 -m pip install opencv-python\n",
173
+ "✅ Core dependencies installed\n",
174
+ "\n",
175
+ "STEP 4: Build Gaussian Splatting submodules\n",
176
+ "======================================================================\n",
177
+ "\n",
178
+ "======================================================================\n",
179
+ "Installing simple-knn\n",
180
+ "======================================================================\n",
181
+ " > Target path: /content/mip-splatting/submodules/simple-knn\n",
182
+ " > Removing old simple-knn...\n",
183
+ " > Cloning from https://github.com/tztechno/simple-knn.git...\n",
184
+ "Running: git clone https://github.com/tztechno/simple-knn.git /content/mip-splatting/submodules/simple-knn\n",
185
+ " > Checking cloned files...\n",
186
+ " > Files in simple-knn: ['README.md', 'ext.cpp', 'spatial.h', '.gitignore', 'simple_knn', 'simple_knn0.cu', 'spatial.cu', 'setup.py', '.git', 'simple_knn.cu']...\n",
187
+ " > Installing simple-knn (This may take a few minutes)...\n",
188
+ "✅ Successfully installed simple-knn\n",
189
+ "\n",
190
+ "======================================================================\n",
191
+ "Installing diff-gaussian-rasterization\n",
192
+ "======================================================================\n",
193
+ " > Target path: /content/mip-splatting/submodules/diff-gaussian-rasterization\n",
194
+ " > Removing old diff-gaussian-rasterization...\n",
195
+ " > Cloning from https://github.com/graphdeco-inria/diff-gaussian-rasterization.git...\n",
196
+ "Running: git clone https://github.com/graphdeco-inria/diff-gaussian-rasterization.git /content/mip-splatting/submodules/diff-gaussian-rasterization\n",
197
+ " > Checking cloned files...\n",
198
+ " > Files in diff-gaussian-rasterization: ['README.md', 'ext.cpp', 'diff_gaussian_rasterization', '.gitignore', 'cuda_rasterizer', 'rasterize_points.cu', 'third_party', 'CMakeLists.txt', '.gitmodules', 'setup.py']...\n",
199
+ " > Checking for submodules...\n",
200
+ " > Initializing submodules...\n",
201
+ "Running: git submodule update --init --recursive\n",
202
+ " > Installing diff-gaussian-rasterization (This may take a few minutes)...\n",
203
+ "✅ Successfully installed diff-gaussian-rasterization\n",
204
+ "\n",
205
+ "STEP 5: Verify installation\n",
206
+ "======================================================================\n",
207
+ "❌ simple_knn - FAILED: No module named 'simple_knn'\n",
208
+ "❌ diff_gaussian_rasterization - FAILED: No module named 'diff_gaussian_rasterization'\n",
209
+ "❌ open3d - FAILED: module 'numpy._core._multiarray_umath' has no attribute '_blas_supports_fpe'\n",
210
+ "\n",
211
+ "❌ Some modules failed to install\n"
212
+ ]
213
+ }
214
+ ],
215
+ "source": [
216
+ "def run_cmd(cmd, check=True, capture=False, cwd=None): # ← cwd=None を追加\n",
217
+ " \"\"\"Run command with better error handling\"\"\"\n",
218
+ " print(f\"Running: {' '.join(cmd)}\")\n",
219
+ " result = subprocess.run(\n",
220
+ " cmd,\n",
221
+ " capture_output=capture,\n",
222
+ " text=True,\n",
223
+ " check=False,\n",
224
+ " cwd=cwd # ← ここに渡す\n",
225
+ " )\n",
226
+ " if check and result.returncode != 0:\n",
227
+ " print(f\"❌ Command failed with code {result.returncode}\")\n",
228
+ " if capture:\n",
229
+ " print(f\"STDOUT: {result.stdout}\")\n",
230
+ " print(f\"STDERR: {result.stderr}\")\n",
231
+ " return result\n",
232
+ "\n",
233
+ "\n",
234
+ "def install_submodule(name, url, base_dir):\n",
235
+ " \"\"\"個別のサブモジュールをインストール\"\"\"\n",
236
+ " print(f\"\\n{'='*70}\")\n",
237
+ " print(f\"Installing {name}\")\n",
238
+ " print(f\"{'='*70}\")\n",
239
+ "\n",
240
+ " # 絶対パスを使用\n",
241
+ " path = os.path.abspath(os.path.join(base_dir, \"submodules\", name))\n",
242
+ " print(f\" > Target path: {path}\")\n",
243
+ "\n",
244
+ " # Step 1: 既存を削除\n",
245
+ " if os.path.exists(path):\n",
246
+ " print(f\" > Removing old {name}...\")\n",
247
+ " shutil.rmtree(path)\n",
248
+ "\n",
249
+ " # Step 2: クローン\n",
250
+ " print(f\" > Cloning from {url}...\")\n",
251
+ " os.makedirs(os.path.dirname(path), exist_ok=True)\n",
252
+ " try:\n",
253
+ " run_cmd([\"git\", \"clone\", url, path])\n",
254
+ " except subprocess.CalledProcessError as e:\n",
255
+ " print(f\"❌ Failed to clone {name}\")\n",
256
+ " print(e.stderr)\n",
257
+ " return False\n",
258
+ "\n",
259
+ " # Step 3: ファイル確認\n",
260
+ " print(f\" > Checking cloned files...\")\n",
261
+ " files = os.listdir(path)\n",
262
+ " print(f\" > Files in {name}: {files[:10]}...\")\n",
263
+ "\n",
264
+ " # Step 4: ビルドキャッシュ削除\n",
265
+ " build_dir = os.path.join(path, \"build\")\n",
266
+ " if os.path.exists(build_dir):\n",
267
+ " print(f\" > Cleaning build cache...\")\n",
268
+ " shutil.rmtree(build_dir)\n",
269
+ "\n",
270
+ " # Step 5: インストール\n",
271
+ " print(f\" > Installing {name} (This may take a few minutes)...\")\n",
272
+ "\n",
273
+ " # 環境変数を明示的に引き継ぐ\n",
274
+ " current_env = os.environ.copy()\n",
275
+ " result = subprocess.run(\n",
276
+ " [sys.executable, \"-m\", \"pip\", \"install\", \"-e\", \".\", \"--no-build-isolation\", \"-v\"],\n",
277
+ " cwd=path,\n",
278
+ " env=current_env,\n",
279
+ " capture_output=True,\n",
280
+ " text=True\n",
281
+ " )\n",
282
+ "\n",
283
+ " if result.returncode != 0:\n",
284
+ " print(f\"❌ Failed to install {name}\")\n",
285
+ " # C++/CUDAのビルドエラーは stdout に出ることが多いため、両方出力\n",
286
+ " print(\"\\n--- STDOUT (Build Logs) ---\")\n",
287
+ " stdout_lines = result.stdout.split('\\n')\n",
288
+ " print('\\n'.join(stdout_lines[-60:])) # 最後の60行を表示\n",
289
+ " print(\"\\n--- STDERR (Error Details) ---\")\n",
290
+ " print(result.stderr)\n",
291
+ " return False\n",
292
+ "\n",
293
+ " print(f\"✅ Successfully installed {name}\")\n",
294
+ " return True\n",
295
+ "\n",
296
+ "\n",
297
+ "def install_mipsplatting_submodule(name, base_dir):\n",
298
+ " \"\"\"mip-splattingに含まれるsubmoduleをインストール(クローン不要)\"\"\"\n",
299
+ " print(f\"\\n{'='*70}\")\n",
300
+ " print(f\"Installing {name} (from mip-splatting submodules)\")\n",
301
+ " print(f\"{'='*70}\")\n",
302
+ "\n",
303
+ " # submoduleのパス\n",
304
+ " path = os.path.abspath(os.path.join(base_dir, \"submodules\", name))\n",
305
+ " print(f\" > Target path: {path}\")\n",
306
+ "\n",
307
+ " # ファイルの存在確認\n",
308
+ " if not os.path.exists(path):\n",
309
+ " print(f\"❌ Path not found: {path}\")\n",
310
+ " return False\n",
311
+ "\n",
312
+ " # setup.pyの存在確認\n",
313
+ " setup_py = os.path.join(path, \"setup.py\")\n",
314
+ " if not os.path.exists(setup_py):\n",
315
+ " print(f\"❌ setup.py not found: {setup_py}\")\n",
316
+ " return False\n",
317
+ "\n",
318
+ " print(f\" > Checking files...\")\n",
319
+ " files = os.listdir(path)\n",
320
+ " print(f\" > Files in {name}: {files[:10]}...\")\n",
321
+ "\n",
322
+ " # ビルドキャッシュ削除\n",
323
+ " build_dir = os.path.join(path, \"build\")\n",
324
+ " if os.path.exists(build_dir):\n",
325
+ " print(f\" > Cleaning build cache...\")\n",
326
+ " shutil.rmtree(build_dir)\n",
327
+ "\n",
328
+ " # インストール\n",
329
+ " print(f\" > Installing {name} (This may take a few minutes)...\")\n",
330
+ "\n",
331
+ " current_env = os.environ.copy()\n",
332
+ " result = subprocess.run(\n",
333
+ " [sys.executable, \"-m\", \"pip\", \"install\", \"-e\", \".\", \"--no-build-isolation\", \"-v\"],\n",
334
+ " cwd=path,\n",
335
+ " env=current_env,\n",
336
+ " capture_output=True,\n",
337
+ " text=True\n",
338
+ " )\n",
339
+ "\n",
340
+ " if result.returncode != 0:\n",
341
+ " print(f\"❌ Failed to install {name}\")\n",
342
+ " print(\"\\n--- STDOUT (Build Logs) ---\")\n",
343
+ " stdout_lines = result.stdout.split('\\n')\n",
344
+ " print('\\n'.join(stdout_lines[-60:]))\n",
345
+ " print(\"\\n--- STDERR (Error Details) ---\")\n",
346
+ " print(result.stderr)\n",
347
+ " return False\n",
348
+ "\n",
349
+ " print(f\"✅ Successfully installed {name}\")\n",
350
+ " return True\n",
351
+ "\n",
352
+ "\n",
353
+ "def setup_environment():\n",
354
+ " \"\"\"Setup mip-splatting environment with correct submodules\"\"\"\n",
355
+ " print(\"=\"*70)\n",
356
+ " print(\"Setting up mip-splatting environment\")\n",
357
+ " print(\"=\"*70)\n",
358
+ "\n",
359
+ " WORK_DIR = \"/content/mip-splatting\"\n",
360
+ "\n",
361
+ " # =====================================================================\n",
362
+ " # STEP 1: Clone main repository with submodules\n",
363
+ " # =====================================================================\n",
364
+ " print(\"\\nSTEP 1: Clone mip-splatting repository\")\n",
365
+ " print(\"=\"*70)\n",
366
+ "\n",
367
+ " if os.path.exists(WORK_DIR):\n",
368
+ " print(f\" > {WORK_DIR} already exists, removing...\")\n",
369
+ " shutil.rmtree(WORK_DIR)\n",
370
+ "\n",
371
+ " print(f\" > Cloning mip-splatting with submodules...\")\n",
372
+ " # --recursive で submodules も一緒にクローン\n",
373
+ " run_cmd([\n",
374
+ " \"git\", \"clone\", \"--recursive\",\n",
375
+ " \"https://github.com/autonomousvision/mip-splatting.git\",\n",
376
+ " WORK_DIR\n",
377
+ " ])\n",
378
+ " print(\"✅ Repository cloned with submodules\")\n",
379
+ "\n",
380
+ " # submodulesが正しくクローンされたか確認\n",
381
+ " print(\"\\n > Verifying submodules...\")\n",
382
+ " submodules_dir = os.path.join(WORK_DIR, \"submodules\")\n",
383
+ " if os.path.exists(submodules_dir):\n",
384
+ " items = os.listdir(submodules_dir)\n",
385
+ " print(f\" > Found submodules: {items}\")\n",
386
+ "\n",
387
+ " # 空のsubmoduleディレクトリがある場合は初期化\n",
388
+ " for item in items:\n",
389
+ " item_path = os.path.join(submodules_dir, item)\n",
390
+ " if os.path.isdir(item_path):\n",
391
+ " item_files = os.listdir(item_path)\n",
392
+ " if not item_files or len(item_files) == 0:\n",
393
+ " print(f\" > {item} is empty, initializing...\")\n",
394
+ " run_cmd([\"git\", \"submodule\", \"update\", \"--init\", \"--recursive\"], cwd=WORK_DIR)\n",
395
+ " break\n",
396
+ "\n",
397
+ " # =====================================================================\n",
398
+ " # STEP 2: Fix numpy compatibility\n",
399
+ " # =====================================================================\n",
400
+ " print(\"\\nSTEP 2: Fix numpy compatibility\")\n",
401
+ " print(\"=\"*70)\n",
402
+ "\n",
403
+ " print(\" > Uninstalling numpy 2.x...\")\n",
404
+ " run_cmd([sys.executable, \"-m\", \"pip\", \"uninstall\", \"numpy\", \"-y\"], check=False)\n",
405
+ "\n",
406
+ " print(\" > Installing numpy<2.0...\")\n",
407
+ " run_cmd([sys.executable, \"-m\", \"pip\", \"install\", \"numpy<2.0\"])\n",
408
+ " print(\"✅ numpy<2.0 installed\")\n",
409
+ "\n",
410
+ " # =====================================================================\n",
411
+ " # STEP 3: Install core dependencies\n",
412
+ " # =====================================================================\n",
413
+ " print(\"\\nSTEP 3: Install core dependencies\")\n",
414
+ " print(\"=\"*70)\n",
415
+ "\n",
416
+ " core_packages = [\n",
417
+ " \"open3d==0.17.0\",\n",
418
+ " \"plyfile\",\n",
419
+ " \"tqdm\",\n",
420
+ " \"Pillow\",\n",
421
+ " \"opencv-python\"\n",
422
+ " ]\n",
423
+ "\n",
424
+ " for package in core_packages:\n",
425
+ " print(f\" > Installing {package}...\")\n",
426
+ " run_cmd([sys.executable, \"-m\", \"pip\", \"install\", package])\n",
427
+ " print(\"✅ Core dependencies installed\")\n",
428
+ "\n",
429
+ " # =====================================================================\n",
430
+ " # STEP 4: Build mip-splatting submodules\n",
431
+ " # =====================================================================\n",
432
+ " print(\"\\nSTEP 4: Build mip-splatting submodules\")\n",
433
+ " print(\"=\"*70)\n",
434
+ "\n",
435
+ " # simple-knn: 実績のあるfixed版を使用(クローンし直す)\n",
436
+ " success_knn = install_submodule(\n",
437
+ " \"simple-knn\",\n",
438
+ " \"https://github.com/tztechno/simple-knn.git\",\n",
439
+ " WORK_DIR\n",
440
+ " )\n",
441
+ "\n",
442
+ " if not success_knn:\n",
443
+ " print(\"❌ Failed to install simple-knn\")\n",
444
+ " return None\n",
445
+ "\n",
446
+ " # diff-gaussian-rasterization: mip-splattingに���まれているものを使用\n",
447
+ " # (kernel_size対応版なのでクローンし直さない)\n",
448
+ " success_rast = install_mipsplatting_submodule(\n",
449
+ " \"diff-gaussian-rasterization\",\n",
450
+ " WORK_DIR\n",
451
+ " )\n",
452
+ "\n",
453
+ " if not success_rast:\n",
454
+ " print(\"❌ Failed to install diff-gaussian-rasterization\")\n",
455
+ " return None\n",
456
+ "\n",
457
+ " # =====================================================================\n",
458
+ " # STEP 5: Verify installation\n",
459
+ " # =====================================================================\n",
460
+ " print(\"\\nSTEP 5: Verify installation\")\n",
461
+ " print(\"=\"*70)\n",
462
+ "\n",
463
+ " verification_tests = [\n",
464
+ " (\"simple_knn\", \"from simple_knn._C import distCUDA2; print('simple_knn OK')\"),\n",
465
+ " (\"diff_gaussian_rasterization\", \"from diff_gaussian_rasterization import GaussianRasterizationSettings; print('diff_gaussian_rasterization OK')\"),\n",
466
+ " (\"open3d\", \"import open3d as o3d; print(f'open3d {o3d.__version__}')\"),\n",
467
+ " (\"numpy\", \"import numpy as np; print(f'numpy {np.__version__}')\"),\n",
468
+ " ]\n",
469
+ "\n",
470
+ " all_ok = True\n",
471
+ " for module_name, test_code in verification_tests:\n",
472
+ " try:\n",
473
+ " exec(test_code)\n",
474
+ " print(f\"✅ {module_name} - OK\")\n",
475
+ " except Exception as e:\n",
476
+ " print(f\"❌ {module_name} - FAILED: {e}\")\n",
477
+ " all_ok = False\n",
478
+ "\n",
479
+ " # kernel_size対応の確認\n",
480
+ " print(\"\\n > Verifying kernel_size support...\")\n",
481
+ " try:\n",
482
+ " from diff_gaussian_rasterization import GaussianRasterizationSettings\n",
483
+ " import inspect\n",
484
+ " sig = inspect.signature(GaussianRasterizationSettings)\n",
485
+ " params = list(sig.parameters.keys())\n",
486
+ " if 'kernel_size' in params:\n",
487
+ " print(f\"✅ kernel_size parameter supported\")\n",
488
+ " else:\n",
489
+ " print(f\"❌ kernel_size parameter NOT found\")\n",
490
+ " print(f\" Available parameters: {params}\")\n",
491
+ " all_ok = False\n",
492
+ " except Exception as e:\n",
493
+ " print(f\"❌ Failed to check kernel_size: {e}\")\n",
494
+ " all_ok = False\n",
495
+ "\n",
496
+ " if not all_ok:\n",
497
+ " print(\"\\n❌ Some modules failed to install or verify\")\n",
498
+ " return None\n",
499
+ "\n",
500
+ " print(\"\\n\" + \"=\"*70)\n",
501
+ " print(\"✅ Environment setup complete!\")\n",
502
+ " print(\"=\"*70)\n",
503
+ "\n",
504
+ " return WORK_DIR\n",
505
+ "\n",
506
+ "\n",
507
+ "\n",
508
+ "WORK_DIR = setup_environment()\n",
509
+ "\n"
510
+ ]
511
+ },
512
+ {
513
+ "cell_type": "code",
514
+ "execution_count": 27,
515
+ "id": "b8690389",
516
+ "metadata": {
517
+ "execution": {
518
+ "iopub.execute_input": "2026-01-10T18:22:43.739411Z",
519
+ "iopub.status.busy": "2026-01-10T18:22:43.738855Z",
520
+ "iopub.status.idle": "2026-01-10T18:22:43.755664Z",
521
+ "shell.execute_reply": "2026-01-10T18:22:43.754865Z"
522
+ },
523
+ "papermill": {
524
+ "duration": 0.027297,
525
+ "end_time": "2026-01-10T18:22:43.756758",
526
+ "exception": false,
527
+ "start_time": "2026-01-10T18:22:43.729461",
528
+ "status": "completed"
529
+ },
530
+ "tags": [],
531
+ "id": "b8690389"
532
+ },
533
+ "outputs": [],
534
+ "source": [
535
+ "import os\n",
536
+ "import glob\n",
537
+ "import cv2\n",
538
+ "import numpy as np\n",
539
+ "from PIL import Image\n",
540
+ "\n",
541
+ "# =========================================================\n",
542
+ "# Utility: aspect ratio preserved + black padding\n",
543
+ "# =========================================================\n",
544
+ "\n",
545
+ "def normalize_image_sizes_biplet(input_dir, output_dir=None, size=1024, max_images=None):\n",
546
+ " \"\"\"\n",
547
+ " Generates two square crops (Left & Right or Top & Bottom)\n",
548
+ " from each image in a directory and returns the output directory\n",
549
+ " and the list of generated file paths.\n",
550
+ "\n",
551
+ " Args:\n",
552
+ " input_dir: Input directory containing source images\n",
553
+ " output_dir: Output directory for processed images\n",
554
+ " size: Target square size (default: 1024)\n",
555
+ " max_images: Maximum number of SOURCE images to process (default: None = all images)\n",
556
+ " \"\"\"\n",
557
+ " if output_dir is None:\n",
558
+ " output_dir = 'output/images_biplet'\n",
559
+ " os.makedirs(output_dir, exist_ok=True)\n",
560
+ "\n",
561
+ " print(f\"--- Step 1: Biplet-Square Normalization ---\")\n",
562
+ " print(f\"Generating 2 cropped squares (Left/Right or Top/Bottom) for each image...\")\n",
563
+ " print()\n",
564
+ "\n",
565
+ " generated_paths = []\n",
566
+ " converted_count = 0\n",
567
+ " size_stats = {}\n",
568
+ "\n",
569
+ " # Sort for consistent processing order\n",
570
+ " image_files = sorted([f for f in os.listdir(input_dir)\n",
571
+ " if f.lower().endswith(('.jpg', '.jpeg', '.png'))])\n",
572
+ "\n",
573
+ " # ★ max_images で元画像数を制限\n",
574
+ " if max_images is not None:\n",
575
+ " image_files = image_files[:max_images]\n",
576
+ " print(f\"Processing limited to {max_images} source images (will generate {max_images * 2} cropped images)\")\n",
577
+ "\n",
578
+ " for img_file in image_files:\n",
579
+ " input_path = os.path.join(input_dir, img_file)\n",
580
+ " try:\n",
581
+ " img = Image.open(input_path)\n",
582
+ " original_size = img.size\n",
583
+ "\n",
584
+ " # Tracking original aspect ratios\n",
585
+ " size_key = f\"{original_size[0]}x{original_size[1]}\"\n",
586
+ " size_stats[size_key] = size_stats.get(size_key, 0) + 1\n",
587
+ "\n",
588
+ " # Generate 2 crops using the helper function\n",
589
+ " crops = generate_two_crops(img, size)\n",
590
+ " base_name, ext = os.path.splitext(img_file)\n",
591
+ "\n",
592
+ " for mode, cropped_img in crops.items():\n",
593
+ " output_path = os.path.join(output_dir, f\"{base_name}_{mode}{ext}\")\n",
594
+ " cropped_img.save(output_path, quality=95)\n",
595
+ " generated_paths.append(output_path)\n",
596
+ "\n",
597
+ " converted_count += 1\n",
598
+ " print(f\" ✓ {img_file}: {original_size} → 2 square images generated\")\n",
599
+ "\n",
600
+ " except Exception as e:\n",
601
+ " print(f\" ✗ Error processing {img_file}: {e}\")\n",
602
+ "\n",
603
+ " print(f\"\\nProcessing complete: {converted_count} source images processed\")\n",
604
+ " print(f\"Total output images: {len(generated_paths)}\")\n",
605
+ " print(f\"Original size distribution: {size_stats}\")\n",
606
+ "\n",
607
+ " return output_dir, generated_paths\n",
608
+ "\n",
609
+ "\n",
610
+ "def generate_two_crops(img, size):\n",
611
+ " \"\"\"\n",
612
+ " Crops the image into a square and returns 2 variations\n",
613
+ " (Left/Right for landscape, Top/Bottom for portrait).\n",
614
+ " \"\"\"\n",
615
+ " width, height = img.size\n",
616
+ " crop_size = min(width, height)\n",
617
+ " crops = {}\n",
618
+ "\n",
619
+ " if width > height:\n",
620
+ " # Landscape → Left & Right\n",
621
+ " positions = {\n",
622
+ " 'left': 0,\n",
623
+ " 'right': width - crop_size\n",
624
+ " }\n",
625
+ " for mode, x_offset in positions.items():\n",
626
+ " box = (x_offset, 0, x_offset + crop_size, crop_size)\n",
627
+ " crops[mode] = img.crop(box).resize(\n",
628
+ " (size, size),\n",
629
+ " Image.Resampling.LANCZOS\n",
630
+ " )\n",
631
+ "\n",
632
+ " else:\n",
633
+ " # Portrait or Square → Top & Bottom\n",
634
+ " positions = {\n",
635
+ " 'top': 0,\n",
636
+ " 'bottom': height - crop_size\n",
637
+ " }\n",
638
+ " for mode, y_offset in positions.items():\n",
639
+ " box = (0, y_offset, crop_size, y_offset + crop_size)\n",
640
+ " crops[mode] = img.crop(box).resize(\n",
641
+ " (size, size),\n",
642
+ " Image.Resampling.LANCZOS\n",
643
+ " )\n",
644
+ "\n",
645
+ " return crops\n"
646
+ ]
647
+ },
648
+ {
649
+ "cell_type": "code",
650
+ "execution_count": 28,
651
+ "id": "7acc20b6",
652
+ "metadata": {
653
+ "execution": {
654
+ "iopub.execute_input": "2026-01-10T18:22:43.772525Z",
655
+ "iopub.status.busy": "2026-01-10T18:22:43.772303Z",
656
+ "iopub.status.idle": "2026-01-10T18:22:43.790574Z",
657
+ "shell.execute_reply": "2026-01-10T18:22:43.789515Z"
658
+ },
659
+ "papermill": {
660
+ "duration": 0.027612,
661
+ "end_time": "2026-01-10T18:22:43.791681",
662
+ "exception": false,
663
+ "start_time": "2026-01-10T18:22:43.764069",
664
+ "status": "completed"
665
+ },
666
+ "tags": [],
667
+ "id": "7acc20b6"
668
+ },
669
+ "outputs": [],
670
+ "source": [
671
+ "def run_colmap_reconstruction(image_dir, colmap_dir):\n",
672
+ " \"\"\"Estimate camera poses and 3D point cloud with COLMAP\"\"\"\n",
673
+ " print(\"Running SfM reconstruction with COLMAP...\")\n",
674
+ "\n",
675
+ " database_path = os.path.join(colmap_dir, \"database.db\")\n",
676
+ " sparse_dir = os.path.join(colmap_dir, \"sparse\")\n",
677
+ " os.makedirs(sparse_dir, exist_ok=True)\n",
678
+ "\n",
679
+ " # Set environment variable\n",
680
+ " env = os.environ.copy()\n",
681
+ " env['QT_QPA_PLATFORM'] = 'offscreen'\n",
682
+ "\n",
683
+ " # Feature extraction\n",
684
+ " print(\"1/4: Extracting features...\")\n",
685
+ " subprocess.run([\n",
686
+ " 'colmap', 'feature_extractor',\n",
687
+ " '--database_path', database_path,\n",
688
+ " '--image_path', image_dir,\n",
689
+ " '--ImageReader.single_camera', '1',\n",
690
+ " '--ImageReader.camera_model', 'OPENCV',\n",
691
+ " '--SiftExtraction.use_gpu', '0' # Use CPU\n",
692
+ " ], check=True, env=env)\n",
693
+ "\n",
694
+ " # Feature matching\n",
695
+ " print(\"2/4: Matching features...\")\n",
696
+ " subprocess.run([\n",
697
+ " 'colmap', 'exhaustive_matcher', # Use sequential_matcher instead of exhaustive_matcher\n",
698
+ " '--database_path', database_path,\n",
699
+ " '--SiftMatching.use_gpu', '0' # Use CPU\n",
700
+ " ], check=True, env=env)\n",
701
+ "\n",
702
+ " # Sparse reconstruction\n",
703
+ " print(\"3/4: Sparse reconstruction...\")\n",
704
+ " subprocess.run([\n",
705
+ " 'colmap', 'mapper',\n",
706
+ " '--database_path', database_path,\n",
707
+ " '--image_path', image_dir,\n",
708
+ " '--output_path', sparse_dir,\n",
709
+ " '--Mapper.ba_global_max_num_iterations', '20', # Speed up\n",
710
+ " '--Mapper.ba_local_max_num_iterations', '10'\n",
711
+ " ], check=True, env=env)\n",
712
+ "\n",
713
+ " # Export to text format\n",
714
+ " print(\"4/4: Exporting to text format...\")\n",
715
+ " model_dir = os.path.join(sparse_dir, '0')\n",
716
+ " if not os.path.exists(model_dir):\n",
717
+ " # Use the first model found\n",
718
+ " subdirs = [d for d in os.listdir(sparse_dir) if os.path.isdir(os.path.join(sparse_dir, d))]\n",
719
+ " if subdirs:\n",
720
+ " model_dir = os.path.join(sparse_dir, subdirs[0])\n",
721
+ " else:\n",
722
+ " raise FileNotFoundError(\"COLMAP reconstruction failed\")\n",
723
+ "\n",
724
+ " subprocess.run([\n",
725
+ " 'colmap', 'model_converter',\n",
726
+ " '--input_path', model_dir,\n",
727
+ " '--output_path', model_dir,\n",
728
+ " '--output_type', 'TXT'\n",
729
+ " ], check=True, env=env)\n",
730
+ "\n",
731
+ " print(f\"COLMAP reconstruction complete: {model_dir}\")\n",
732
+ " return model_dir\n",
733
+ "\n",
734
+ "\n",
735
+ "def convert_cameras_to_pinhole(input_file, output_file):\n",
736
+ " \"\"\"Convert camera model to PINHOLE format\"\"\"\n",
737
+ " print(f\"Reading camera file: {input_file}\")\n",
738
+ "\n",
739
+ " with open(input_file, 'r') as f:\n",
740
+ " lines = f.readlines()\n",
741
+ "\n",
742
+ " converted_count = 0\n",
743
+ " with open(output_file, 'w') as f:\n",
744
+ " for line in lines:\n",
745
+ " if line.startswith('#') or line.strip() == '':\n",
746
+ " f.write(line)\n",
747
+ " else:\n",
748
+ " parts = line.strip().split()\n",
749
+ " if len(parts) >= 4:\n",
750
+ " cam_id = parts[0]\n",
751
+ " model = parts[1]\n",
752
+ " width = parts[2]\n",
753
+ " height = parts[3]\n",
754
+ " params = parts[4:]\n",
755
+ "\n",
756
+ " # Convert to PINHOLE format\n",
757
+ " if model == \"PINHOLE\":\n",
758
+ " f.write(line)\n",
759
+ " elif model == \"OPENCV\":\n",
760
+ " # OPENCV: fx, fy, cx, cy, k1, k2, p1, p2\n",
761
+ " fx = params[0]\n",
762
+ " fy = params[1]\n",
763
+ " cx = params[2]\n",
764
+ " cy = params[3]\n",
765
+ " f.write(f\"{cam_id} PINHOLE {width} {height} {fx} {fy} {cx} {cy}\\n\")\n",
766
+ " converted_count += 1\n",
767
+ " else:\n",
768
+ " # Convert other models too\n",
769
+ " fx = fy = max(float(width), float(height))\n",
770
+ " cx = float(width) / 2\n",
771
+ " cy = float(height) / 2\n",
772
+ " f.write(f\"{cam_id} PINHOLE {width} {height} {fx} {fy} {cx} {cy}\\n\")\n",
773
+ " converted_count += 1\n",
774
+ " else:\n",
775
+ " f.write(line)\n",
776
+ "\n",
777
+ " print(f\"Converted {converted_count} cameras to PINHOLE format\")\n",
778
+ "\n",
779
+ "\n",
780
+ "def prepare_gaussian_splatting_data(image_dir, colmap_model_dir):\n",
781
+ " \"\"\"Prepare data for Gaussian Splatting\"\"\"\n",
782
+ " print(\"Preparing data for Gaussian Splatting...\")\n",
783
+ "\n",
784
+ " data_dir = f\"{WORK_DIR}/data/video\"\n",
785
+ " os.makedirs(f\"{data_dir}/sparse/0\", exist_ok=True)\n",
786
+ " os.makedirs(f\"{data_dir}/images\", exist_ok=True)\n",
787
+ "\n",
788
+ " # Copy images\n",
789
+ " print(\"Copying images...\")\n",
790
+ " img_count = 0\n",
791
+ " for img_file in os.listdir(image_dir):\n",
792
+ " if img_file.lower().endswith(('.jpg', '.jpeg', '.png')):\n",
793
+ " shutil.copy(\n",
794
+ " os.path.join(image_dir, img_file),\n",
795
+ " f\"{data_dir}/images/{img_file}\"\n",
796
+ " )\n",
797
+ " img_count += 1\n",
798
+ " print(f\"Copied {img_count} images\")\n",
799
+ "\n",
800
+ " # Convert and copy camera file to PINHOLE format\n",
801
+ " print(\"Converting camera model to PINHOLE format...\")\n",
802
+ " convert_cameras_to_pinhole(\n",
803
+ " os.path.join(colmap_model_dir, 'cameras.txt'),\n",
804
+ " f\"{data_dir}/sparse/0/cameras.txt\"\n",
805
+ " )\n",
806
+ "\n",
807
+ " # Copy other files\n",
808
+ " for filename in ['images.txt', 'points3D.txt']:\n",
809
+ " src = os.path.join(colmap_model_dir, filename)\n",
810
+ " dst = f\"{data_dir}/sparse/0/{filename}\"\n",
811
+ " if os.path.exists(src):\n",
812
+ " shutil.copy(src, dst)\n",
813
+ " print(f\"Copied {filename}\")\n",
814
+ " else:\n",
815
+ " print(f\"Warning: {filename} not found\")\n",
816
+ "\n",
817
+ " print(f\"Data preparation complete: {data_dir}\")\n",
818
+ " return data_dir\n",
819
+ "\n",
820
+ "\n",
821
+ "\n",
822
+ "\n",
823
+ "# After (mipGS) - Added Kernel Size and Multi-Scale Support\n",
824
+ "def train_gaussian_splatting(data_dir, iterations=3000,\n",
825
+ " kernel_size=0.1,\n",
826
+ " resolution_scale=1):\n",
827
+ " \"\"\"\n",
828
+ " Training function for mipGS with anti-aliasing support\n",
829
+ " \"\"\"\n",
830
+ " model_path = f\"{WORK_DIR}/output/video\"\n",
831
+ "\n",
832
+ " # mipGSの基本コマンド(resolution_scaleは使わない可能性)\n",
833
+ " cmd = [\n",
834
+ " sys.executable, 'train.py',\n",
835
+ " '-s', data_dir,\n",
836
+ " '-m', model_path,\n",
837
+ " '--iterations', str(iterations),\n",
838
+ " '--eval'\n",
839
+ " ]\n",
840
+ "\n",
841
+ " # kernel_sizeは実際には存在しない可能性があるため、オプショナルに\n",
842
+ " # mipGSは内部的にkernel_sizeを計算するため、パラメータとして渡さない\n",
843
+ "\n",
844
+ " print(f\"Training command: {' '.join(cmd)}\")\n",
845
+ "\n",
846
+ " # エラー詳細を取得するため、stdout/stderrをキャプチャ\n",
847
+ " try:\n",
848
+ " result = subprocess.run(\n",
849
+ " cmd,\n",
850
+ " cwd=WORK_DIR,\n",
851
+ " check=True,\n",
852
+ " capture_output=True,\n",
853
+ " text=True\n",
854
+ " )\n",
855
+ " print(\"Training completed successfully\")\n",
856
+ " print(result.stdout)\n",
857
+ " except subprocess.CalledProcessError as e:\n",
858
+ " print(f\"Training failed with exit code {e.returncode}\")\n",
859
+ " print(\"STDOUT:\")\n",
860
+ " print(e.stdout)\n",
861
+ " print(\"STDERR:\")\n",
862
+ " print(e.stderr)\n",
863
+ " raise\n",
864
+ "\n",
865
+ " return model_path\n",
866
+ "\n",
867
+ "\n",
868
+ "\n",
869
+ "\n",
870
+ "# After (mipGS) - Added Multi-Scale Testing Support\n",
871
+ "def render_video(model_path, output_video_path, iteration=3000,\n",
872
+ " multiscale=False, scale_factors=None):\n",
873
+ " \"\"\"\n",
874
+ " Generate video from the trained model (mipGS version)\n",
875
+ "\n",
876
+ " Args:\n",
877
+ " model_path: Path to the trained model\n",
878
+ " output_video_path: Output video file path\n",
879
+ " iteration: Iteration number to render\n",
880
+ " multiscale: If True, render at multiple scales\n",
881
+ " scale_factors: List of scale factors [1.0, 2.0, 4.0, 8.0] or None for default\n",
882
+ " \"\"\"\n",
883
+ " print(\"Rendering video...\")\n",
884
+ "\n",
885
+ " # Default scale factors for multi-scale testing\n",
886
+ " if multiscale and scale_factors is None:\n",
887
+ " scale_factors = [1.0, 2.0, 4.0, 8.0]\n",
888
+ " elif not multiscale:\n",
889
+ " scale_factors = [1.0] # Single scale only\n",
890
+ "\n",
891
+ " # Render at each scale\n",
892
+ " for scale in scale_factors:\n",
893
+ " scale_str = f\"scale_{scale:.1f}\" if multiscale else \"\"\n",
894
+ " print(f\"Rendering at scale {scale}x...\")\n",
895
+ "\n",
896
+ " # Execute rendering with scale factor\n",
897
+ " cmd = [\n",
898
+ " sys.executable, 'render.py',\n",
899
+ " '-m', model_path,\n",
900
+ " '--iteration', str(iteration)\n",
901
+ " ]\n",
902
+ "\n",
903
+ " # Add scale factor parameter for mipGS\n",
904
+ " if scale != 1.0:\n",
905
+ " cmd.extend(['--scale_factor', str(scale)])\n",
906
+ "\n",
907
+ " subprocess.run(cmd, cwd=WORK_DIR, check=True)\n",
908
+ "\n",
909
+ " # Find the rendering directory (use original scale for video)\n",
910
+ " possible_dirs = [\n",
911
+ " f\"{model_path}/test/ours_{iteration}/renders\",\n",
912
+ " f\"{model_path}/train/ours_{iteration}/renders\",\n",
913
+ " ]\n",
914
+ "\n",
915
+ " render_dir = None\n",
916
+ " for test_dir in possible_dirs:\n",
917
+ " if os.path.exists(test_dir):\n",
918
+ " render_dir = test_dir\n",
919
+ " print(f\"Rendering directory found: {render_dir}\")\n",
920
+ " break\n",
921
+ "\n",
922
+ " if render_dir and os.path.exists(render_dir):\n",
923
+ " render_imgs = sorted([f for f in os.listdir(render_dir) if f.endswith('.png')])\n",
924
+ "\n",
925
+ " if render_imgs:\n",
926
+ " print(f\"Found {len(render_imgs)} rendered images\")\n",
927
+ "\n",
928
+ " # Create video with ffmpeg\n",
929
+ " subprocess.run([\n",
930
+ " 'ffmpeg', '-y',\n",
931
+ " '-framerate', '30',\n",
932
+ " '-pattern_type', 'glob',\n",
933
+ " '-i', f\"{render_dir}/*.png\",\n",
934
+ " '-c:v', 'libx264',\n",
935
+ " '-pix_fmt', 'yuv420p',\n",
936
+ " '-crf', '18',\n",
937
+ " output_video_path\n",
938
+ " ], check=True)\n",
939
+ "\n",
940
+ " print(f\"Video saved: {output_video_path}\")\n",
941
+ "\n",
942
+ " # If multiscale, save additional scale videos\n",
943
+ " if multiscale:\n",
944
+ " for scale in scale_factors:\n",
945
+ " if scale != 1.0:\n",
946
+ " scale_render_dir = render_dir.replace('renders', f'renders_scale_{scale:.1f}')\n",
947
+ " if os.path.exists(scale_render_dir):\n",
948
+ " scale_video_path = output_video_path.replace('.mp4', f'_scale_{scale:.1f}x.mp4')\n",
949
+ " subprocess.run([\n",
950
+ " 'ffmpeg', '-y',\n",
951
+ " '-framerate', '30',\n",
952
+ " '-pattern_type', 'glob',\n",
953
+ " '-i', f\"{scale_render_dir}/*.png\",\n",
954
+ " '-c:v', 'libx264',\n",
955
+ " '-pix_fmt', 'yuv420p',\n",
956
+ " '-crf', '18',\n",
957
+ " scale_video_path\n",
958
+ " ], check=True)\n",
959
+ " print(f\"Multi-scale video saved: {scale_video_path}\")\n",
960
+ "\n",
961
+ " return True\n",
962
+ "\n",
963
+ " print(\"Error: Rendering directory not found\")\n",
964
+ " return False\n",
965
+ "\n",
966
+ "\n",
967
+ "\n",
968
+ "\n",
969
+ "\n",
970
+ "\n",
971
+ "\n",
972
+ "def create_gif(video_path, gif_path):\n",
973
+ " \"\"\"Create GIF from MP4\"\"\"\n",
974
+ " print(\"Creating animated GIF...\")\n",
975
+ "\n",
976
+ " subprocess.run([\n",
977
+ " 'ffmpeg', '-y',\n",
978
+ " '-i', video_path,\n",
979
+ " '-vf', 'setpts=8*PTS,fps=10,scale=720:-1:flags=lanczos',\n",
980
+ " '-loop', '0',\n",
981
+ " gif_path\n",
982
+ " ], check=True)\n",
983
+ "\n",
984
+ " if os.path.exists(gif_path):\n",
985
+ " size_mb = os.path.getsize(gif_path) / (1024 * 1024)\n",
986
+ " print(f\"GIF creation complete: {gif_path} ({size_mb:.2f} MB)\")\n",
987
+ " return True\n",
988
+ "\n",
989
+ " return False"
990
+ ]
991
+ },
992
+ {
993
+ "cell_type": "code",
994
+ "source": [
995
+ "# New function for mipGS - Fuse 3D filter into Gaussian parameters\n",
996
+ "def create_fused_ply(model_path, scene_name, output_dir=\"fused\"):\n",
997
+ " \"\"\"\n",
998
+ " Fuse the 3D smoothing filter to Gaussian parameters for deployment\n",
999
+ " This creates a .ply file that can be used in online viewers\n",
1000
+ "\n",
1001
+ " Args:\n",
1002
+ " model_path: Path to trained model\n",
1003
+ " scene_name: Name of the scene\n",
1004
+ " output_dir: Directory to save fused .ply file\n",
1005
+ " \"\"\"\n",
1006
+ " os.makedirs(output_dir, exist_ok=True)\n",
1007
+ " output_ply = f\"{output_dir}/{scene_name}_fused.ply\"\n",
1008
+ "\n",
1009
+ " cmd = [\n",
1010
+ " sys.executable, 'create_fused_ply.py',\n",
1011
+ " '-m', f\"{model_path}/{scene_name}\",\n",
1012
+ " '--output_ply', output_ply\n",
1013
+ " ]\n",
1014
+ " subprocess.run(cmd, cwd=WORK_DIR, check=True)\n",
1015
+ " return output_ply"
1016
+ ],
1017
+ "metadata": {
1018
+ "id": "-Cwgr3I0b57O"
1019
+ },
1020
+ "id": "-Cwgr3I0b57O",
1021
+ "execution_count": 29,
1022
+ "outputs": []
1023
+ },
1024
+ {
1025
+ "cell_type": "code",
1026
+ "execution_count": 30,
1027
+ "id": "f75233a8",
1028
+ "metadata": {
1029
+ "execution": {
1030
+ "iopub.execute_input": "2026-01-10T18:22:43.807508Z",
1031
+ "iopub.status.busy": "2026-01-10T18:22:43.807294Z",
1032
+ "iopub.status.idle": "2026-01-11T00:00:17.030890Z",
1033
+ "shell.execute_reply": "2026-01-11T00:00:17.029927Z"
1034
+ },
1035
+ "papermill": {
1036
+ "duration": 20253.434865,
1037
+ "end_time": "2026-01-11T00:00:17.234174",
1038
+ "exception": false,
1039
+ "start_time": "2026-01-10T18:22:43.799309",
1040
+ "status": "completed"
1041
+ },
1042
+ "tags": [],
1043
+ "id": "f75233a8",
1044
+ "outputId": "ec7066ed-815a-4dd9-8d46-d657849f7d50",
1045
+ "colab": {
1046
+ "base_uri": "https://localhost:8080/"
1047
+ }
1048
+ },
1049
+ "outputs": [
1050
+ {
1051
+ "output_type": "stream",
1052
+ "name": "stdout",
1053
+ "text": [
1054
+ "============================================================\n",
1055
+ "Step 1: Normalizing and preprocessing images\n",
1056
+ "============================================================\n",
1057
+ "--- Step 1: Biplet-Square Normalization ---\n",
1058
+ "Generating 2 cropped squares (Left/Right or Top/Bottom) for each image...\n",
1059
+ "\n",
1060
+ "Processing limited to 30 source images (will generate 60 cropped images)\n",
1061
+ " ✓ image_101.jpeg: (1440, 1920) → 2 square images generated\n",
1062
+ " ✓ image_102.jpeg: (1440, 1920) → 2 square images generated\n",
1063
+ " ✓ image_103.jpeg: (1440, 1920) → 2 square images generated\n",
1064
+ " ✓ image_104.jpeg: (1440, 1920) → 2 square images generated\n",
1065
+ " ✓ image_105.jpeg: (1440, 1920) → 2 square images generated\n",
1066
+ " ✓ image_106.jpeg: (1440, 1920) → 2 square images generated\n",
1067
+ " ✓ image_107.jpeg: (1440, 1920) → 2 square images generated\n",
1068
+ " ✓ image_108.jpeg: (1440, 1920) → 2 square images generated\n",
1069
+ " ✓ image_109.jpeg: (1440, 1920) → 2 square images generated\n",
1070
+ " ✓ image_110.jpeg: (1440, 1920) → 2 square images generated\n",
1071
+ " ✓ image_111.jpeg: (1440, 1920) → 2 square images generated\n",
1072
+ " ✓ image_112.jpeg: (1440, 1920) → 2 square images generated\n",
1073
+ " ✓ image_113.jpeg: (1440, 1920) → 2 square images generated\n",
1074
+ " ✓ image_114.jpeg: (1440, 1920) → 2 square images generated\n",
1075
+ " ✓ image_115.jpeg: (1440, 1920) → 2 square images generated\n",
1076
+ " ✓ image_116.jpeg: (1440, 1920) → 2 square images generated\n",
1077
+ " ✓ image_117.jpeg: (1440, 1920) → 2 square images generated\n",
1078
+ " ✓ image_118.jpeg: (1440, 1920) → 2 square images generated\n",
1079
+ " ✓ image_119.jpeg: (1440, 1920) → 2 square images generated\n",
1080
+ " ✓ image_120.jpeg: (1440, 1920) → 2 square images generated\n",
1081
+ " ✓ image_121.jpeg: (1440, 1920) → 2 square images generated\n",
1082
+ " ✓ image_122.jpeg: (1440, 1920) → 2 square images generated\n",
1083
+ " ✓ image_123.jpeg: (1440, 1920) → 2 square images generated\n",
1084
+ " ✓ image_124.jpeg: (1440, 1920) → 2 square images generated\n",
1085
+ " ✓ image_125.jpeg: (1440, 1920) → 2 square images generated\n",
1086
+ " ✓ image_126.jpeg: (1440, 1920) → 2 square images generated\n",
1087
+ " ✓ image_127.jpeg: (1440, 1920) → 2 square images generated\n",
1088
+ " ✓ image_128.jpeg: (1440, 1920) → 2 square images generated\n",
1089
+ " ✓ image_129.jpeg: (1440, 1920) → 2 square images generated\n",
1090
+ " ✓ image_130.jpeg: (1440, 1920) → 2 square images generated\n",
1091
+ "\n",
1092
+ "Processing complete: 30 source images processed\n",
1093
+ "Total output images: 60\n",
1094
+ "Original size distribution: {'1440x1920': 30}\n",
1095
+ "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', '/content/colmap_workspace/images/image_121_top.jpeg', '/content/colmap_workspace/images/image_121_bottom.jpeg', '/content/colmap_workspace/images/image_122_top.jpeg', '/content/colmap_workspace/images/image_122_bottom.jpeg', '/content/colmap_workspace/images/image_123_top.jpeg', '/content/colmap_workspace/images/image_123_bottom.jpeg', '/content/colmap_workspace/images/image_124_top.jpeg', '/content/colmap_workspace/images/image_124_bottom.jpeg', '/content/colmap_workspace/images/image_125_top.jpeg', '/content/colmap_workspace/images/image_125_bottom.jpeg', '/content/colmap_workspace/images/image_126_top.jpeg', '/content/colmap_workspace/images/image_126_bottom.jpeg', '/content/colmap_workspace/images/image_127_top.jpeg', '/content/colmap_workspace/images/image_127_bottom.jpeg', '/content/colmap_workspace/images/image_128_top.jpeg', '/content/colmap_workspace/images/image_128_bottom.jpeg', '/content/colmap_workspace/images/image_129_top.jpeg', '/content/colmap_workspace/images/image_129_bottom.jpeg', '/content/colmap_workspace/images/image_130_top.jpeg', '/content/colmap_workspace/images/image_130_bottom.jpeg']) images\n",
1096
+ "============================================================\n",
1097
+ "Step 2: Running COLMAP reconstruction\n",
1098
+ "============================================================\n",
1099
+ "Running SfM reconstruction with COLMAP...\n",
1100
+ "1/4: Extracting features...\n",
1101
+ "2/4: Matching features...\n",
1102
+ "3/4: Sparse reconstruction...\n",
1103
+ "4/4: Exporting to text format...\n",
1104
+ "COLMAP reconstruction complete: /content/colmap_workspace/sparse/0\n",
1105
+ "============================================================\n",
1106
+ "Step 3: Preparing Gaussian Splatting data\n",
1107
+ "============================================================\n",
1108
+ "Preparing data for Gaussian Splatting...\n",
1109
+ "Copying images...\n",
1110
+ "Copied 60 images\n",
1111
+ "Converting camera model to PINHOLE format...\n",
1112
+ "Reading camera file: /content/colmap_workspace/sparse/0/cameras.txt\n",
1113
+ "Converted 1 cameras to PINHOLE format\n",
1114
+ "Copied images.txt\n",
1115
+ "Copied points3D.txt\n",
1116
+ "Data preparation complete: /content/mip-splatting/data/video\n",
1117
+ "============================================================\n",
1118
+ "Step 4: Training Gaussian Splatting model\n",
1119
+ "============================================================\n",
1120
+ "Training command: /usr/bin/python3 train.py -s /content/mip-splatting/data/video -m /content/mip-splatting/output/video --iterations 3000 --eval\n",
1121
+ "Training failed with exit code 1\n",
1122
+ "STDOUT:\n",
1123
+ "Optimizing /content/mip-splatting/output/video\n",
1124
+ "Output folder: /content/mip-splatting/output/video [13/02 14:03:49]\n",
1125
+ "\n",
1126
+ "Reading camera 1/60\n",
1127
+ "Reading camera 2/60\n",
1128
+ "Reading camera 3/60\n",
1129
+ "Reading camera 4/60\n",
1130
+ "Reading camera 5/60\n",
1131
+ "Reading camera 6/60\n",
1132
+ "Reading camera 7/60\n",
1133
+ "Reading camera 8/60\n",
1134
+ "Reading camera 9/60\n",
1135
+ "Reading camera 10/60\n",
1136
+ "Reading camera 11/60\n",
1137
+ "Reading camera 12/60\n",
1138
+ "Reading camera 13/60\n",
1139
+ "Reading camera 14/60\n",
1140
+ "Reading camera 15/60\n",
1141
+ "Reading camera 16/60\n",
1142
+ "Reading camera 17/60\n",
1143
+ "Reading camera 18/60\n",
1144
+ "Reading camera 19/60\n",
1145
+ "Reading camera 20/60\n",
1146
+ "Reading camera 21/60\n",
1147
+ "Reading camera 22/60\n",
1148
+ "Reading camera 23/60\n",
1149
+ "Reading camera 24/60\n",
1150
+ "Reading camera 25/60\n",
1151
+ "Reading camera 26/60\n",
1152
+ "Reading camera 27/60\n",
1153
+ "Reading camera 28/60\n",
1154
+ "Reading camera 29/60\n",
1155
+ "Reading camera 30/60\n",
1156
+ "Reading camera 31/60\n",
1157
+ "Reading camera 32/60\n",
1158
+ "Reading camera 33/60\n",
1159
+ "Reading camera 34/60\n",
1160
+ "Reading camera 35/60\n",
1161
+ "Reading camera 36/60\n",
1162
+ "Reading camera 37/60\n",
1163
+ "Reading camera 38/60\n",
1164
+ "Reading camera 39/60\n",
1165
+ "Reading camera 40/60\n",
1166
+ "Reading camera 41/60\n",
1167
+ "Reading camera 42/60\n",
1168
+ "Reading camera 43/60\n",
1169
+ "Reading camera 44/60\n",
1170
+ "Reading camera 45/60\n",
1171
+ "Reading camera 46/60\n",
1172
+ "Reading camera 47/60\n",
1173
+ "Reading camera 48/60\n",
1174
+ "Reading camera 49/60\n",
1175
+ "Reading camera 50/60\n",
1176
+ "Reading camera 51/60\n",
1177
+ "Reading camera 52/60\n",
1178
+ "Reading camera 53/60\n",
1179
+ "Reading camera 54/60\n",
1180
+ "Reading camera 55/60\n",
1181
+ "Reading camera 56/60\n",
1182
+ "Reading camera 57/60\n",
1183
+ "Reading camera 58/60\n",
1184
+ "Reading camera 59/60\n",
1185
+ "Reading camera 60/60 [13/02 14:03:50]\n",
1186
+ "Converting point3d.bin to .ply, will happen only the first time you open the scene. [13/02 14:03:50]\n",
1187
+ "Loading Training Cameras [13/02 14:03:51]\n",
1188
+ "Loading Test Cameras [13/02 14:03:53]\n",
1189
+ "Number of points at initialisation : 66037 [13/02 14:03:53]\n",
1190
+ "Computing 3D filter [13/02 14:03:54]\n",
1191
+ "\n",
1192
+ "STDERR:\n",
1193
+ "2026-02-13 14:03:41.027252: E external/local_xla/xla/stream_executor/cuda/cuda_fft.cc:467] Unable to register cuFFT factory: Attempting to register factory for plugin cuFFT when one has already been registered\n",
1194
+ "WARNING: All log messages before absl::InitializeLog() is called are written to STDERR\n",
1195
+ "E0000 00:00:1770991421.271073 66647 cuda_dnn.cc:8579] Unable to register cuDNN factory: Attempting to register factory for plugin cuDNN when one has already been registered\n",
1196
+ "E0000 00:00:1770991421.337120 66647 cuda_blas.cc:1407] Unable to register cuBLAS factory: Attempting to register factory for plugin cuBLAS when one has already been registered\n",
1197
+ "W0000 00:00:1770991421.874633 66647 computation_placer.cc:177] computation placer already registered. Please check linkage and avoid linking the same target more than once.\n",
1198
+ "W0000 00:00:1770991421.874668 66647 computation_placer.cc:177] computation placer already registered. Please check linkage and avoid linking the same target more than once.\n",
1199
+ "W0000 00:00:1770991421.874672 66647 computation_placer.cc:177] computation placer already registered. Please check linkage and avoid linking the same target more than once.\n",
1200
+ "W0000 00:00:1770991421.874675 66647 computation_placer.cc:177] computation placer already registered. Please check linkage and avoid linking the same target more than once.\n",
1201
+ "\n",
1202
+ "Training progress: 0%| | 0/3000 [00:00<?, ?it/s]Traceback (most recent call last):\n",
1203
+ " File \"/content/mip-splatting/train.py\", line 268, in <module>\n",
1204
+ " training(lp.extract(args), op.extract(args), pp.extract(args), args.test_iterations, args.save_iterations, args.checkpoint_iterations, args.start_checkpoint, args.debug_from)\n",
1205
+ " File \"/content/mip-splatting/train.py\", line 125, in training\n",
1206
+ " render_pkg = render(viewpoint_cam, gaussians, pipe, background, kernel_size=dataset.kernel_size, subpixel_offset=subpixel_offset)\n",
1207
+ " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n",
1208
+ " File \"/content/mip-splatting/gaussian_renderer/__init__.py\", line 39, in render\n",
1209
+ " raster_settings = GaussianRasterizationSettings(\n",
1210
+ " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n",
1211
+ "TypeError: GaussianRasterizationSettings.__new__() got an unexpected keyword argument 'kernel_size'\n",
1212
+ "\n",
1213
+ "Training progress: 0%| | 0/3000 [00:00<?, ?it/s]\n",
1214
+ "\n",
1215
+ "Error: Command '['/usr/bin/python3', 'train.py', '-s', '/content/mip-splatting/data/video', '-m', '/content/mip-splatting/output/video', '--iterations', '3000', '--eval']' returned non-zero exit status 1.\n"
1216
+ ]
1217
+ },
1218
+ {
1219
+ "output_type": "stream",
1220
+ "name": "stderr",
1221
+ "text": [
1222
+ "Traceback (most recent call last):\n",
1223
+ " File \"/tmp/ipython-input-756757153.py\", line 38, in main_pipeline\n",
1224
+ " model_path = train_gaussian_splatting(data_dir, iterations=3000)\n",
1225
+ " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n",
1226
+ " File \"/tmp/ipython-input-3665676147.py\", line 178, in train_gaussian_splatting\n",
1227
+ " result = subprocess.run(\n",
1228
+ " ^^^^^^^^^^^^^^^\n",
1229
+ " File \"/usr/lib/python3.12/subprocess.py\", line 571, in run\n",
1230
+ " raise CalledProcessError(retcode, process.args,\n",
1231
+ "subprocess.CalledProcessError: Command '['/usr/bin/python3', 'train.py', '-s', '/content/mip-splatting/data/video', '-m', '/content/mip-splatting/output/video', '--iterations', '3000', '--eval']' returned non-zero exit status 1.\n"
1232
+ ]
1233
+ }
1234
+ ],
1235
+ "source": [
1236
+ "def main_pipeline(image_dir, output_dir, square_size=1024, max_images=100):\n",
1237
+ " \"\"\"Main execution function\"\"\"\n",
1238
+ " try:\n",
1239
+ " # Step 1: 画像の正規化と前処理\n",
1240
+ " print(\"=\"*60)\n",
1241
+ " print(\"Step 1: Normalizing and preprocessing images\")\n",
1242
+ " print(\"=\"*60)\n",
1243
+ "\n",
1244
+ " frame_dir = os.path.join(COLMAP_DIR, \"images\")\n",
1245
+ " os.makedirs(frame_dir, exist_ok=True)\n",
1246
+ "\n",
1247
+ " # 画像を正規化して直接COLMAPのディレクトリに保存\n",
1248
+ " num_processed = normalize_image_sizes_biplet(\n",
1249
+ " input_dir=image_dir,\n",
1250
+ " output_dir=frame_dir, # 直接colmap/imagesに保存\n",
1251
+ " size=square_size,\n",
1252
+ " max_images=max_images\n",
1253
+ " )\n",
1254
+ "\n",
1255
+ " print(f\"Processed {num_processed} images\")\n",
1256
+ "\n",
1257
+ " # Step 2: Estimate Camera Info with COLMAP\n",
1258
+ " print(\"=\"*60)\n",
1259
+ " print(\"Step 2: Running COLMAP reconstruction\")\n",
1260
+ " print(\"=\"*60)\n",
1261
+ " colmap_model_dir = run_colmap_reconstruction(frame_dir, COLMAP_DIR)\n",
1262
+ "\n",
1263
+ " # Step 3: Prepare Data for Gaussian Splatting\n",
1264
+ " print(\"=\"*60)\n",
1265
+ " print(\"Step 3: Preparing Gaussian Splatting data\")\n",
1266
+ " print(\"=\"*60)\n",
1267
+ " data_dir = prepare_gaussian_splatting_data(frame_dir, colmap_model_dir)\n",
1268
+ "\n",
1269
+ " # Step 4: Train Model\n",
1270
+ " print(\"=\"*60)\n",
1271
+ " print(\"Step 4: Training Gaussian Splatting model\")\n",
1272
+ " print(\"=\"*60)\n",
1273
+ " model_path = train_gaussian_splatting(data_dir, iterations=3000)\n",
1274
+ "\n",
1275
+ " # Step 5: Render Video\n",
1276
+ " print(\"=\"*60)\n",
1277
+ " print(\"Step 5: Rendering video\")\n",
1278
+ " print(\"=\"*60)\n",
1279
+ " os.makedirs(OUTPUT_DIR, exist_ok=True)\n",
1280
+ " output_video = os.path.join(OUTPUT_DIR, \"gaussian_splatting_video.mp4\")\n",
1281
+ "\n",
1282
+ " # 2. マルチスケールレンダリング(mipGSの特徴を活用)\n",
1283
+ " success = render_video(\n",
1284
+ " model_path=\"output/video\",\n",
1285
+ " output_video_path=\"output.mp4\",\n",
1286
+ " iteration=3000,\n",
1287
+ " multiscale=True, # マルチスケールを有効化\n",
1288
+ " scale_factors=[1.0, 2.0, 4.0] # カスタムスケール\n",
1289
+ " )\n",
1290
+ "\n",
1291
+ " if success:\n",
1292
+ " print(\"=\"*60)\n",
1293
+ " print(f\"Success! Video generation complete: {output_video}\")\n",
1294
+ " print(\"=\"*60)\n",
1295
+ "\n",
1296
+ " # Create GIF\n",
1297
+ " output_gif = os.path.join(OUTPUT_DIR, \"gaussian_splatting_video.gif\")\n",
1298
+ " create_gif(output_video, output_gif)\n",
1299
+ "\n",
1300
+ " # Display result\n",
1301
+ " from IPython.display import Image, display\n",
1302
+ " display(Image(open(output_gif, 'rb').read()))\n",
1303
+ "\n",
1304
+ " return output_video, output_gif\n",
1305
+ " else:\n",
1306
+ " print(\"Warning: Rendering complete, but video was not generated\")\n",
1307
+ " return None, None\n",
1308
+ "\n",
1309
+ " except Exception as e:\n",
1310
+ " print(f\"Error: {str(e)}\")\n",
1311
+ " import traceback\n",
1312
+ " traceback.print_exc()\n",
1313
+ " return None, None\n",
1314
+ "\n",
1315
+ "\n",
1316
+ "\n",
1317
+ "if __name__ == \"__main__\":\n",
1318
+ " IMAGE_DIR = \"/content/drive/MyDrive/your_folder/fountain100\"\n",
1319
+ " OUTPUT_DIR = \"/content/output\"\n",
1320
+ " COLMAP_DIR = \"/content/colmap_workspace\"\n",
1321
+ "\n",
1322
+ " video_path, gif_path = main_pipeline(\n",
1323
+ " image_dir=IMAGE_DIR,\n",
1324
+ " output_dir=OUTPUT_DIR,\n",
1325
+ " square_size=1024,\n",
1326
+ " max_images=30\n",
1327
+ " )\n",
1328
+ "\n",
1329
+ "\n"
1330
+ ]
1331
+ },
1332
+ {
1333
+ "cell_type": "markdown",
1334
+ "id": "e17ec719",
1335
+ "metadata": {
1336
+ "papermill": {
1337
+ "duration": 0.49801,
1338
+ "end_time": "2026-01-11T00:00:18.165833",
1339
+ "exception": false,
1340
+ "start_time": "2026-01-11T00:00:17.667823",
1341
+ "status": "completed"
1342
+ },
1343
+ "tags": [],
1344
+ "id": "e17ec719"
1345
+ },
1346
+ "source": []
1347
+ },
1348
+ {
1349
+ "cell_type": "markdown",
1350
+ "id": "38b3974c",
1351
+ "metadata": {
1352
+ "papermill": {
1353
+ "duration": 0.427583,
1354
+ "end_time": "2026-01-11T00:00:19.008387",
1355
+ "exception": false,
1356
+ "start_time": "2026-01-11T00:00:18.580804",
1357
+ "status": "completed"
1358
+ },
1359
+ "tags": [],
1360
+ "id": "38b3974c"
1361
+ },
1362
+ "source": []
1363
+ }
1364
+ ],
1365
+ "metadata": {
1366
+ "kaggle": {
1367
+ "accelerator": "nvidiaTeslaT4",
1368
+ "dataSources": [
1369
+ {
1370
+ "databundleVersionId": 5447706,
1371
+ "sourceId": 49349,
1372
+ "sourceType": "competition"
1373
+ },
1374
+ {
1375
+ "datasetId": 1429416,
1376
+ "sourceId": 14451718,
1377
+ "sourceType": "datasetVersion"
1378
+ }
1379
+ ],
1380
+ "dockerImageVersionId": 31090,
1381
+ "isGpuEnabled": true,
1382
+ "isInternetEnabled": true,
1383
+ "language": "python",
1384
+ "sourceType": "notebook"
1385
+ },
1386
+ "kernelspec": {
1387
+ "display_name": "Python 3",
1388
+ "name": "python3"
1389
+ },
1390
+ "language_info": {
1391
+ "codemirror_mode": {
1392
+ "name": "ipython",
1393
+ "version": 3
1394
+ },
1395
+ "file_extension": ".py",
1396
+ "mimetype": "text/x-python",
1397
+ "name": "python",
1398
+ "nbconvert_exporter": "python",
1399
+ "pygments_lexer": "ipython3",
1400
+ "version": "3.11.13"
1401
+ },
1402
+ "papermill": {
1403
+ "default_parameters": {},
1404
+ "duration": 20573.990788,
1405
+ "end_time": "2026-01-11T00:00:22.081506",
1406
+ "environment_variables": {},
1407
+ "exception": null,
1408
+ "input_path": "__notebook__.ipynb",
1409
+ "output_path": "__notebook__.ipynb",
1410
+ "parameters": {},
1411
+ "start_time": "2026-01-10T18:17:28.090718",
1412
+ "version": "2.6.0"
1413
+ },
1414
+ "colab": {
1415
+ "provenance": [],
1416
+ "gpuType": "T4"
1417
+ },
1418
+ "accelerator": "GPU"
1419
+ },
1420
+ "nbformat": 4,
1421
+ "nbformat_minor": 5
1422
+ }
biplet_colmap_mipgs_colab_06.ipynb ADDED
@@ -0,0 +1,1304 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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": "cf4afc9c-d15e-414c-a43c-831d056f80b8"
34
+ },
35
+ "id": "JON4rYSEOzCg",
36
+ "execution_count": 19,
37
+ "outputs": [
38
+ {
39
+ "output_type": "stream",
40
+ "name": "stdout",
41
+ "text": [
42
+ "Drive already mounted at /content/drive; to attempt to forcibly remount, call drive.mount(\"/content/drive\", force_remount=True).\n"
43
+ ]
44
+ }
45
+ ]
46
+ },
47
+ {
48
+ "cell_type": "code",
49
+ "execution_count": 20,
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": 20,
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": 21,
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": "a130b9ff-fad4-45f8-e2c7-8a74e5a48aa6",
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
+ " > /content/mip-splatting already exists, removing...\n",
148
+ " > Cloning mip-splatting with submodules...\n",
149
+ "Running: git clone --recursive https://github.com/autonomousvision/mip-splatting.git /content/mip-splatting\n",
150
+ "✅ Repository cloned with submodules\n",
151
+ "\n",
152
+ " > Verifying submodules...\n",
153
+ " > Found submodules: ['simple-knn', 'diff-gaussian-rasterization']\n",
154
+ "\n",
155
+ "======================================================================\n",
156
+ "STEP 1: System packages\n",
157
+ "======================================================================\n",
158
+ "Running: apt-get update -qq\n",
159
+ "Running: apt-get install -y -qq colmap build-essential cmake git libopenblas-dev xvfb\n",
160
+ "\n",
161
+ "STEP 2: Fix numpy compatibility\n",
162
+ "======================================================================\n",
163
+ " > Uninstalling numpy 2.x...\n",
164
+ "Running: /usr/bin/python3 -m pip uninstall numpy -y\n",
165
+ " > Installing numpy<2.0...\n",
166
+ "Running: /usr/bin/python3 -m pip install numpy<2.0\n",
167
+ "✅ numpy<2.0 installed\n",
168
+ "\n",
169
+ "STEP 3: Install core dependencies\n",
170
+ "======================================================================\n",
171
+ " > Installing open3d...\n",
172
+ "Running: /usr/bin/python3 -m pip install open3d\n",
173
+ " > Installing plyfile...\n",
174
+ "Running: /usr/bin/python3 -m pip install plyfile\n",
175
+ " > Installing tqdm...\n",
176
+ "Running: /usr/bin/python3 -m pip install tqdm\n",
177
+ " > Installing Pillow...\n",
178
+ "Running: /usr/bin/python3 -m pip install Pillow\n",
179
+ " > Installing opencv-python...\n",
180
+ "Running: /usr/bin/python3 -m pip install opencv-python\n",
181
+ "✅ Core dependencies installed\n",
182
+ "\n",
183
+ "STEP 4: Build mip-splatting submodules\n",
184
+ "======================================================================\n",
185
+ "\n",
186
+ "======================================================================\n",
187
+ "Installing simple-knn\n",
188
+ "======================================================================\n",
189
+ " > Target path: /content/mip-splatting/submodules/simple-knn\n",
190
+ " > Removing old simple-knn...\n",
191
+ " > Cloning from https://github.com/tztechno/simple-knn.git...\n",
192
+ "Running: git clone https://github.com/tztechno/simple-knn.git /content/mip-splatting/submodules/simple-knn\n",
193
+ " > Checking cloned files...\n",
194
+ " > Files in simple-knn: ['README.md', 'ext.cpp', 'spatial.h', '.gitignore', 'simple_knn', 'simple_knn0.cu', 'spatial.cu', 'setup.py', '.git', 'simple_knn.cu']...\n",
195
+ " > Installing simple-knn (This may take a few minutes)...\n",
196
+ "✅ Successfully installed simple-knn\n",
197
+ "\n",
198
+ "======================================================================\n",
199
+ "Installing diff-gaussian-rasterization (from mip-splatting submodules)\n",
200
+ "======================================================================\n",
201
+ " > Target path: /content/mip-splatting/submodules/diff-gaussian-rasterization\n",
202
+ " > Checking files...\n",
203
+ " > Files in diff-gaussian-rasterization: ['README.md', 'ext.cpp', 'diff_gaussian_rasterization', 'cuda_rasterizer', 'diff_gaussian_rasterization.egg-info', 'rasterize_points.cu', 'third_party', 'CMakeLists.txt', 'setup.py', 'LICENSE.md']...\n",
204
+ " > Installing diff-gaussian-rasterization (This may take a few minutes)...\n",
205
+ "✅ Successfully installed diff-gaussian-rasterization\n"
206
+ ]
207
+ }
208
+ ],
209
+ "source": [
210
+ "def run_cmd(cmd, check=True, capture=False, cwd=None): # ← cwd=None を追加\n",
211
+ " \"\"\"Run command with better error handling\"\"\"\n",
212
+ " print(f\"Running: {' '.join(cmd)}\")\n",
213
+ " result = subprocess.run(\n",
214
+ " cmd,\n",
215
+ " capture_output=capture,\n",
216
+ " text=True,\n",
217
+ " check=False,\n",
218
+ " cwd=cwd # ← ここに渡す\n",
219
+ " )\n",
220
+ " if check and result.returncode != 0:\n",
221
+ " print(f\"❌ Command failed with code {result.returncode}\")\n",
222
+ " if capture:\n",
223
+ " print(f\"STDOUT: {result.stdout}\")\n",
224
+ " print(f\"STDERR: {result.stderr}\")\n",
225
+ " return result\n",
226
+ "\n",
227
+ "\n",
228
+ "def install_submodule(name, url, base_dir):\n",
229
+ " \"\"\"個別のサブモジュールをインストール\"\"\"\n",
230
+ " print(f\"\\n{'='*70}\")\n",
231
+ " print(f\"Installing {name}\")\n",
232
+ " print(f\"{'='*70}\")\n",
233
+ "\n",
234
+ " # 絶対パスを使用\n",
235
+ " path = os.path.abspath(os.path.join(base_dir, \"submodules\", name))\n",
236
+ " print(f\" > Target path: {path}\")\n",
237
+ "\n",
238
+ " # Step 1: 既存を削除\n",
239
+ " if os.path.exists(path):\n",
240
+ " print(f\" > Removing old {name}...\")\n",
241
+ " shutil.rmtree(path)\n",
242
+ "\n",
243
+ " # Step 2: クローン\n",
244
+ " print(f\" > Cloning from {url}...\")\n",
245
+ " os.makedirs(os.path.dirname(path), exist_ok=True)\n",
246
+ " try:\n",
247
+ " run_cmd([\"git\", \"clone\", url, path])\n",
248
+ " except subprocess.CalledProcessError as e:\n",
249
+ " print(f\"❌ Failed to clone {name}\")\n",
250
+ " print(e.stderr)\n",
251
+ " return False\n",
252
+ "\n",
253
+ " # Step 3: ファイル確認\n",
254
+ " print(f\" > Checking cloned files...\")\n",
255
+ " files = os.listdir(path)\n",
256
+ " print(f\" > Files in {name}: {files[:10]}...\")\n",
257
+ "\n",
258
+ " # Step 4: ビルドキャッシュ削除\n",
259
+ " build_dir = os.path.join(path, \"build\")\n",
260
+ " if os.path.exists(build_dir):\n",
261
+ " print(f\" > Cleaning build cache...\")\n",
262
+ " shutil.rmtree(build_dir)\n",
263
+ "\n",
264
+ " # Step 5: インストール\n",
265
+ " print(f\" > Installing {name} (This may take a few minutes)...\")\n",
266
+ "\n",
267
+ " # 環境変数を明示的に引き継ぐ\n",
268
+ " current_env = os.environ.copy()\n",
269
+ " result = subprocess.run(\n",
270
+ " [sys.executable, \"-m\", \"pip\", \"install\", \"-e\", \".\", \"--no-build-isolation\", \"-v\"],\n",
271
+ " cwd=path,\n",
272
+ " env=current_env,\n",
273
+ " capture_output=True,\n",
274
+ " text=True\n",
275
+ " )\n",
276
+ "\n",
277
+ " if result.returncode != 0:\n",
278
+ " print(f\"❌ Failed to install {name}\")\n",
279
+ " # C++/CUDAのビルドエラーは stdout に出ることが多いため、両方出力\n",
280
+ " print(\"\\n--- STDOUT (Build Logs) ---\")\n",
281
+ " stdout_lines = result.stdout.split('\\n')\n",
282
+ " print('\\n'.join(stdout_lines[-60:])) # 最後の60行を表示\n",
283
+ " print(\"\\n--- STDERR (Error Details) ---\")\n",
284
+ " print(result.stderr)\n",
285
+ " return False\n",
286
+ "\n",
287
+ " print(f\"✅ Successfully installed {name}\")\n",
288
+ " return True\n",
289
+ "\n",
290
+ "\n",
291
+ "def install_mipsplatting_submodule(name, base_dir):\n",
292
+ " \"\"\"mip-splattingに含まれるsubmoduleをインストール(クローン不要)\"\"\"\n",
293
+ " print(f\"\\n{'='*70}\")\n",
294
+ " print(f\"Installing {name} (from mip-splatting submodules)\")\n",
295
+ " print(f\"{'='*70}\")\n",
296
+ "\n",
297
+ " # submoduleのパス\n",
298
+ " path = os.path.abspath(os.path.join(base_dir, \"submodules\", name))\n",
299
+ " print(f\" > Target path: {path}\")\n",
300
+ "\n",
301
+ " # ファイルの存在確認\n",
302
+ " if not os.path.exists(path):\n",
303
+ " print(f\"❌ Path not found: {path}\")\n",
304
+ " return False\n",
305
+ "\n",
306
+ " # setup.pyの存在確認\n",
307
+ " setup_py = os.path.join(path, \"setup.py\")\n",
308
+ " if not os.path.exists(setup_py):\n",
309
+ " print(f\"❌ setup.py not found: {setup_py}\")\n",
310
+ " return False\n",
311
+ "\n",
312
+ " print(f\" > Checking files...\")\n",
313
+ " files = os.listdir(path)\n",
314
+ " print(f\" > Files in {name}: {files[:10]}...\")\n",
315
+ "\n",
316
+ " # ビルドキャッシュ削除\n",
317
+ " build_dir = os.path.join(path, \"build\")\n",
318
+ " if os.path.exists(build_dir):\n",
319
+ " print(f\" > Cleaning build cache...\")\n",
320
+ " shutil.rmtree(build_dir)\n",
321
+ "\n",
322
+ " # インストール\n",
323
+ " print(f\" > Installing {name} (This may take a few minutes)...\")\n",
324
+ "\n",
325
+ " current_env = os.environ.copy()\n",
326
+ " result = subprocess.run(\n",
327
+ " [sys.executable, \"-m\", \"pip\", \"install\", \"-e\", \".\", \"--no-build-isolation\", \"-v\"],\n",
328
+ " cwd=path,\n",
329
+ " env=current_env,\n",
330
+ " capture_output=True,\n",
331
+ " text=True\n",
332
+ " )\n",
333
+ "\n",
334
+ " if result.returncode != 0:\n",
335
+ " print(f\"❌ Failed to install {name}\")\n",
336
+ " print(\"\\n--- STDOUT (Build Logs) ---\")\n",
337
+ " stdout_lines = result.stdout.split('\\n')\n",
338
+ " print('\\n'.join(stdout_lines[-60:]))\n",
339
+ " print(\"\\n--- STDERR (Error Details) ---\")\n",
340
+ " print(result.stderr)\n",
341
+ " return False\n",
342
+ "\n",
343
+ " print(f\"✅ Successfully installed {name}\")\n",
344
+ " return True\n",
345
+ "\n",
346
+ "\n",
347
+ "def setup_environment():\n",
348
+ " \"\"\"Setup mip-splatting environment with correct submodules\"\"\"\n",
349
+ " print(\"=\"*70)\n",
350
+ " print(\"Setting up mip-splatting environment\")\n",
351
+ " print(\"=\"*70)\n",
352
+ "\n",
353
+ " WORK_DIR = \"/content/mip-splatting\"\n",
354
+ "\n",
355
+ " # =====================================================================\n",
356
+ " # STEP 1: Clone main repository with submodules\n",
357
+ " # =====================================================================\n",
358
+ " print(\"\\nSTEP 1: Clone mip-splatting repository\")\n",
359
+ " print(\"=\"*70)\n",
360
+ "\n",
361
+ " if os.path.exists(WORK_DIR):\n",
362
+ " print(f\" > {WORK_DIR} already exists, removing...\")\n",
363
+ " shutil.rmtree(WORK_DIR)\n",
364
+ "\n",
365
+ " print(f\" > Cloning mip-splatting with submodules...\")\n",
366
+ " # --recursive で submodules も一緒にクローン\n",
367
+ " run_cmd([\n",
368
+ " \"git\", \"clone\", \"--recursive\",\n",
369
+ " \"https://github.com/autonomousvision/mip-splatting.git\",\n",
370
+ " WORK_DIR\n",
371
+ " ])\n",
372
+ " print(\"✅ Repository cloned with submodules\")\n",
373
+ "\n",
374
+ " # submodulesが正しくクローンされたか確認\n",
375
+ " print(\"\\n > Verifying submodules...\")\n",
376
+ " submodules_dir = os.path.join(WORK_DIR, \"submodules\")\n",
377
+ " if os.path.exists(submodules_dir):\n",
378
+ " items = os.listdir(submodules_dir)\n",
379
+ " print(f\" > Found submodules: {items}\")\n",
380
+ "\n",
381
+ " # 空のsubmoduleディレクトリがある場合は初期化\n",
382
+ " for item in items:\n",
383
+ " item_path = os.path.join(submodules_dir, item)\n",
384
+ " if os.path.isdir(item_path):\n",
385
+ " item_files = os.listdir(item_path)\n",
386
+ " if not item_files or len(item_files) == 0:\n",
387
+ " print(f\" > {item} is empty, initializing...\")\n",
388
+ " run_cmd([\"git\", \"submodule\", \"update\", \"--init\", \"--recursive\"], cwd=WORK_DIR)\n",
389
+ " break\n",
390
+ " # =====================================================================\n",
391
+ " # STEP 1: System packages (Colab)\n",
392
+ " # =====================================================================\n",
393
+ " print(\"\\n\" + \"=\"*70)\n",
394
+ " print(\"STEP 1: System packages\")\n",
395
+ " print(\"=\"*70)\n",
396
+ "\n",
397
+ " run_cmd([\"apt-get\", \"update\", \"-qq\"])\n",
398
+ " run_cmd([\n",
399
+ " \"apt-get\", \"install\", \"-y\", \"-qq\",\n",
400
+ " \"colmap\",\n",
401
+ " \"build-essential\",\n",
402
+ " \"cmake\",\n",
403
+ " \"git\",\n",
404
+ " \"libopenblas-dev\",\n",
405
+ " \"xvfb\"\n",
406
+ " ])\n",
407
+ "\n",
408
+ " # virtual display (COLMAP / OpenCV safety)\n",
409
+ " os.environ[\"QT_QPA_PLATFORM\"] = \"offscreen\"\n",
410
+ " os.environ[\"DISPLAY\"] = \":99\"\n",
411
+ " subprocess.Popen(\n",
412
+ " [\"Xvfb\", \":99\", \"-screen\", \"0\", \"1024x768x24\"],\n",
413
+ " stdout=subprocess.DEVNULL,\n",
414
+ " stderr=subprocess.DEVNULL\n",
415
+ " )\n",
416
+ "\n",
417
+ " # =====================================================================\n",
418
+ " # STEP 2: Fix numpy compatibility\n",
419
+ " # =====================================================================\n",
420
+ " print(\"\\nSTEP 2: Fix numpy compatibility\")\n",
421
+ " print(\"=\"*70)\n",
422
+ "\n",
423
+ " print(\" > Uninstalling numpy 2.x...\")\n",
424
+ " run_cmd([sys.executable, \"-m\", \"pip\", \"uninstall\", \"numpy\", \"-y\"], check=False)\n",
425
+ "\n",
426
+ " print(\" > Installing numpy<2.0...\")\n",
427
+ " run_cmd([sys.executable, \"-m\", \"pip\", \"install\", \"numpy<2.0\"])\n",
428
+ " print(\"✅ numpy<2.0 installed\")\n",
429
+ "\n",
430
+ " # =====================================================================\n",
431
+ " # STEP 3: Install core dependencies\n",
432
+ " # =====================================================================\n",
433
+ " print(\"\\nSTEP 3: Install core dependencies\")\n",
434
+ " print(\"=\"*70)\n",
435
+ "\n",
436
+ " core_packages = [\n",
437
+ " \"open3d\",\n",
438
+ " \"plyfile\",\n",
439
+ " \"tqdm\",\n",
440
+ " \"Pillow\",\n",
441
+ " \"opencv-python\"\n",
442
+ " ]\n",
443
+ "\n",
444
+ " for package in core_packages:\n",
445
+ " print(f\" > Installing {package}...\")\n",
446
+ " run_cmd([sys.executable, \"-m\", \"pip\", \"install\", package])\n",
447
+ " print(\"✅ Core dependencies installed\")\n",
448
+ "\n",
449
+ " # =====================================================================\n",
450
+ " # STEP 4: Build mip-splatting submodules\n",
451
+ " # =====================================================================\n",
452
+ " print(\"\\nSTEP 4: Build mip-splatting submodules\")\n",
453
+ " print(\"=\"*70)\n",
454
+ "\n",
455
+ " # simple-knn: 実績のあるfixed版を使用(クローンし直す)\n",
456
+ " success_knn = install_submodule(\n",
457
+ " \"simple-knn\",\n",
458
+ " \"https://github.com/tztechno/simple-knn.git\",\n",
459
+ " WORK_DIR\n",
460
+ " )\n",
461
+ "\n",
462
+ " if not success_knn:\n",
463
+ " print(\"❌ Failed to install simple-knn\")\n",
464
+ " return None\n",
465
+ "\n",
466
+ " # diff-gaussian-rasterization: mip-splattingに含まれているものを使用\n",
467
+ " # (kernel_size対応版なのでクローンし直さない)\n",
468
+ " success_rast = install_mipsplatting_submodule(\n",
469
+ " \"diff-gaussian-rasterization\",\n",
470
+ " WORK_DIR\n",
471
+ " )\n",
472
+ "\n",
473
+ " if not success_rast:\n",
474
+ " print(\"❌ Failed to install diff-gaussian-rasterization\")\n",
475
+ " return None\n",
476
+ "\n",
477
+ "\n",
478
+ " return WORK_DIR\n",
479
+ "\n",
480
+ "\n",
481
+ "\n",
482
+ "work_dir = setup_environment()\n",
483
+ "\n"
484
+ ]
485
+ },
486
+ {
487
+ "cell_type": "code",
488
+ "execution_count": 22,
489
+ "id": "b8690389",
490
+ "metadata": {
491
+ "execution": {
492
+ "iopub.execute_input": "2026-01-10T18:22:43.739411Z",
493
+ "iopub.status.busy": "2026-01-10T18:22:43.738855Z",
494
+ "iopub.status.idle": "2026-01-10T18:22:43.755664Z",
495
+ "shell.execute_reply": "2026-01-10T18:22:43.754865Z"
496
+ },
497
+ "papermill": {
498
+ "duration": 0.027297,
499
+ "end_time": "2026-01-10T18:22:43.756758",
500
+ "exception": false,
501
+ "start_time": "2026-01-10T18:22:43.729461",
502
+ "status": "completed"
503
+ },
504
+ "tags": [],
505
+ "id": "b8690389"
506
+ },
507
+ "outputs": [],
508
+ "source": [
509
+ "import os\n",
510
+ "import glob\n",
511
+ "import cv2\n",
512
+ "import numpy as np\n",
513
+ "from PIL import Image\n",
514
+ "\n",
515
+ "# =========================================================\n",
516
+ "# Utility: aspect ratio preserved + black padding\n",
517
+ "# =========================================================\n",
518
+ "\n",
519
+ "def normalize_image_sizes_biplet(input_dir, output_dir=None, size=1024, max_images=None):\n",
520
+ " \"\"\"\n",
521
+ " Generates two square crops (Left & Right or Top & Bottom)\n",
522
+ " from each image in a directory and returns the output directory\n",
523
+ " and the list of generated file paths.\n",
524
+ "\n",
525
+ " Args:\n",
526
+ " input_dir: Input directory containing source images\n",
527
+ " output_dir: Output directory for processed images\n",
528
+ " size: Target square size (default: 1024)\n",
529
+ " max_images: Maximum number of SOURCE images to process (default: None = all images)\n",
530
+ " \"\"\"\n",
531
+ " if output_dir is None:\n",
532
+ " output_dir = 'output/images_biplet'\n",
533
+ " os.makedirs(output_dir, exist_ok=True)\n",
534
+ "\n",
535
+ " print(f\"--- Step 1: Biplet-Square Normalization ---\")\n",
536
+ " print(f\"Generating 2 cropped squares (Left/Right or Top/Bottom) for each image...\")\n",
537
+ " print()\n",
538
+ "\n",
539
+ " generated_paths = []\n",
540
+ " converted_count = 0\n",
541
+ " size_stats = {}\n",
542
+ "\n",
543
+ " # Sort for consistent processing order\n",
544
+ " image_files = sorted([f for f in os.listdir(input_dir)\n",
545
+ " if f.lower().endswith(('.jpg', '.jpeg', '.png'))])\n",
546
+ "\n",
547
+ " # ★ max_images で元画像数を制限\n",
548
+ " if max_images is not None:\n",
549
+ " image_files = image_files[:max_images]\n",
550
+ " print(f\"Processing limited to {max_images} source images (will generate {max_images * 2} cropped images)\")\n",
551
+ "\n",
552
+ " for img_file in image_files:\n",
553
+ " input_path = os.path.join(input_dir, img_file)\n",
554
+ " try:\n",
555
+ " img = Image.open(input_path)\n",
556
+ " original_size = img.size\n",
557
+ "\n",
558
+ " # Tracking original aspect ratios\n",
559
+ " size_key = f\"{original_size[0]}x{original_size[1]}\"\n",
560
+ " size_stats[size_key] = size_stats.get(size_key, 0) + 1\n",
561
+ "\n",
562
+ " # Generate 2 crops using the helper function\n",
563
+ " crops = generate_two_crops(img, size)\n",
564
+ " base_name, ext = os.path.splitext(img_file)\n",
565
+ "\n",
566
+ " for mode, cropped_img in crops.items():\n",
567
+ " output_path = os.path.join(output_dir, f\"{base_name}_{mode}{ext}\")\n",
568
+ " cropped_img.save(output_path, quality=95)\n",
569
+ " generated_paths.append(output_path)\n",
570
+ "\n",
571
+ " converted_count += 1\n",
572
+ " print(f\" ✓ {img_file}: {original_size} → 2 square images generated\")\n",
573
+ "\n",
574
+ " except Exception as e:\n",
575
+ " print(f\" ✗ Error processing {img_file}: {e}\")\n",
576
+ "\n",
577
+ " print(f\"\\nProcessing complete: {converted_count} source images processed\")\n",
578
+ " print(f\"Total output images: {len(generated_paths)}\")\n",
579
+ " print(f\"Original size distribution: {size_stats}\")\n",
580
+ "\n",
581
+ " return output_dir, generated_paths\n",
582
+ "\n",
583
+ "\n",
584
+ "def generate_two_crops(img, size):\n",
585
+ " \"\"\"\n",
586
+ " Crops the image into a square and returns 2 variations\n",
587
+ " (Left/Right for landscape, Top/Bottom for portrait).\n",
588
+ " \"\"\"\n",
589
+ " width, height = img.size\n",
590
+ " crop_size = min(width, height)\n",
591
+ " crops = {}\n",
592
+ "\n",
593
+ " if width > height:\n",
594
+ " # Landscape → Left & Right\n",
595
+ " positions = {\n",
596
+ " 'left': 0,\n",
597
+ " 'right': width - crop_size\n",
598
+ " }\n",
599
+ " for mode, x_offset in positions.items():\n",
600
+ " box = (x_offset, 0, x_offset + crop_size, crop_size)\n",
601
+ " crops[mode] = img.crop(box).resize(\n",
602
+ " (size, size),\n",
603
+ " Image.Resampling.LANCZOS\n",
604
+ " )\n",
605
+ "\n",
606
+ " else:\n",
607
+ " # Portrait or Square → Top & Bottom\n",
608
+ " positions = {\n",
609
+ " 'top': 0,\n",
610
+ " 'bottom': height - crop_size\n",
611
+ " }\n",
612
+ " for mode, y_offset in positions.items():\n",
613
+ " box = (0, y_offset, crop_size, y_offset + crop_size)\n",
614
+ " crops[mode] = img.crop(box).resize(\n",
615
+ " (size, size),\n",
616
+ " Image.Resampling.LANCZOS\n",
617
+ " )\n",
618
+ "\n",
619
+ " return crops\n"
620
+ ]
621
+ },
622
+ {
623
+ "cell_type": "code",
624
+ "execution_count": 23,
625
+ "id": "7acc20b6",
626
+ "metadata": {
627
+ "execution": {
628
+ "iopub.execute_input": "2026-01-10T18:22:43.772525Z",
629
+ "iopub.status.busy": "2026-01-10T18:22:43.772303Z",
630
+ "iopub.status.idle": "2026-01-10T18:22:43.790574Z",
631
+ "shell.execute_reply": "2026-01-10T18:22:43.789515Z"
632
+ },
633
+ "papermill": {
634
+ "duration": 0.027612,
635
+ "end_time": "2026-01-10T18:22:43.791681",
636
+ "exception": false,
637
+ "start_time": "2026-01-10T18:22:43.764069",
638
+ "status": "completed"
639
+ },
640
+ "tags": [],
641
+ "id": "7acc20b6"
642
+ },
643
+ "outputs": [],
644
+ "source": [
645
+ "def run_colmap_reconstruction(image_dir, colmap_dir):\n",
646
+ " \"\"\"Estimate camera poses and 3D point cloud with COLMAP\"\"\"\n",
647
+ " print(\"Running SfM reconstruction with COLMAP...\")\n",
648
+ "\n",
649
+ " database_path = os.path.join(colmap_dir, \"database.db\")\n",
650
+ " sparse_dir = os.path.join(colmap_dir, \"sparse\")\n",
651
+ " os.makedirs(sparse_dir, exist_ok=True)\n",
652
+ "\n",
653
+ " # Set environment variable\n",
654
+ " env = os.environ.copy()\n",
655
+ " env['QT_QPA_PLATFORM'] = 'offscreen'\n",
656
+ "\n",
657
+ " # Feature extraction\n",
658
+ " print(\"1/4: Extracting features...\")\n",
659
+ " subprocess.run([\n",
660
+ " 'colmap', 'feature_extractor',\n",
661
+ " '--database_path', database_path,\n",
662
+ " '--image_path', image_dir,\n",
663
+ " '--ImageReader.single_camera', '1',\n",
664
+ " '--ImageReader.camera_model', 'OPENCV',\n",
665
+ " '--SiftExtraction.use_gpu', '0' # Use CPU\n",
666
+ " ], check=True, env=env)\n",
667
+ "\n",
668
+ " # Feature matching\n",
669
+ " print(\"2/4: Matching features...\")\n",
670
+ " subprocess.run([\n",
671
+ " 'colmap', 'exhaustive_matcher', # Use sequential_matcher instead of exhaustive_matcher\n",
672
+ " '--database_path', database_path,\n",
673
+ " '--SiftMatching.use_gpu', '0' # Use CPU\n",
674
+ " ], check=True, env=env)\n",
675
+ "\n",
676
+ " # Sparse reconstruction\n",
677
+ " print(\"3/4: Sparse reconstruction...\")\n",
678
+ " subprocess.run([\n",
679
+ " 'colmap', 'mapper',\n",
680
+ " '--database_path', database_path,\n",
681
+ " '--image_path', image_dir,\n",
682
+ " '--output_path', sparse_dir,\n",
683
+ " '--Mapper.ba_global_max_num_iterations', '20', # Speed up\n",
684
+ " '--Mapper.ba_local_max_num_iterations', '10'\n",
685
+ " ], check=True, env=env)\n",
686
+ "\n",
687
+ " # Export to text format\n",
688
+ " print(\"4/4: Exporting to text format...\")\n",
689
+ " model_dir = os.path.join(sparse_dir, '0')\n",
690
+ " if not os.path.exists(model_dir):\n",
691
+ " # Use the first model found\n",
692
+ " subdirs = [d for d in os.listdir(sparse_dir) if os.path.isdir(os.path.join(sparse_dir, d))]\n",
693
+ " if subdirs:\n",
694
+ " model_dir = os.path.join(sparse_dir, subdirs[0])\n",
695
+ " else:\n",
696
+ " raise FileNotFoundError(\"COLMAP reconstruction failed\")\n",
697
+ "\n",
698
+ " subprocess.run([\n",
699
+ " 'colmap', 'model_converter',\n",
700
+ " '--input_path', model_dir,\n",
701
+ " '--output_path', model_dir,\n",
702
+ " '--output_type', 'TXT'\n",
703
+ " ], check=True, env=env)\n",
704
+ "\n",
705
+ " print(f\"COLMAP reconstruction complete: {model_dir}\")\n",
706
+ " return model_dir\n",
707
+ "\n",
708
+ "\n",
709
+ "def convert_cameras_to_pinhole(input_file, output_file):\n",
710
+ " \"\"\"Convert camera model to PINHOLE format\"\"\"\n",
711
+ " print(f\"Reading camera file: {input_file}\")\n",
712
+ "\n",
713
+ " with open(input_file, 'r') as f:\n",
714
+ " lines = f.readlines()\n",
715
+ "\n",
716
+ " converted_count = 0\n",
717
+ " with open(output_file, 'w') as f:\n",
718
+ " for line in lines:\n",
719
+ " if line.startswith('#') or line.strip() == '':\n",
720
+ " f.write(line)\n",
721
+ " else:\n",
722
+ " parts = line.strip().split()\n",
723
+ " if len(parts) >= 4:\n",
724
+ " cam_id = parts[0]\n",
725
+ " model = parts[1]\n",
726
+ " width = parts[2]\n",
727
+ " height = parts[3]\n",
728
+ " params = parts[4:]\n",
729
+ "\n",
730
+ " # Convert to PINHOLE format\n",
731
+ " if model == \"PINHOLE\":\n",
732
+ " f.write(line)\n",
733
+ " elif model == \"OPENCV\":\n",
734
+ " # OPENCV: fx, fy, cx, cy, k1, k2, p1, p2\n",
735
+ " fx = params[0]\n",
736
+ " fy = params[1]\n",
737
+ " cx = params[2]\n",
738
+ " cy = params[3]\n",
739
+ " f.write(f\"{cam_id} PINHOLE {width} {height} {fx} {fy} {cx} {cy}\\n\")\n",
740
+ " converted_count += 1\n",
741
+ " else:\n",
742
+ " # Convert other models too\n",
743
+ " fx = fy = max(float(width), float(height))\n",
744
+ " cx = float(width) / 2\n",
745
+ " cy = float(height) / 2\n",
746
+ " f.write(f\"{cam_id} PINHOLE {width} {height} {fx} {fy} {cx} {cy}\\n\")\n",
747
+ " converted_count += 1\n",
748
+ " else:\n",
749
+ " f.write(line)\n",
750
+ "\n",
751
+ " print(f\"Converted {converted_count} cameras to PINHOLE format\")\n",
752
+ "\n",
753
+ "\n",
754
+ "def prepare_gaussian_splatting_data(image_dir, colmap_model_dir):\n",
755
+ " \"\"\"Prepare data for Gaussian Splatting\"\"\"\n",
756
+ " print(\"Preparing data for Gaussian Splatting...\")\n",
757
+ "\n",
758
+ " data_dir = f\"{WORK_DIR}/data/video\"\n",
759
+ " os.makedirs(f\"{data_dir}/sparse/0\", exist_ok=True)\n",
760
+ " os.makedirs(f\"{data_dir}/images\", exist_ok=True)\n",
761
+ "\n",
762
+ " # Copy images\n",
763
+ " print(\"Copying images...\")\n",
764
+ " img_count = 0\n",
765
+ " for img_file in os.listdir(image_dir):\n",
766
+ " if img_file.lower().endswith(('.jpg', '.jpeg', '.png')):\n",
767
+ " shutil.copy(\n",
768
+ " os.path.join(image_dir, img_file),\n",
769
+ " f\"{data_dir}/images/{img_file}\"\n",
770
+ " )\n",
771
+ " img_count += 1\n",
772
+ " print(f\"Copied {img_count} images\")\n",
773
+ "\n",
774
+ " # Convert and copy camera file to PINHOLE format\n",
775
+ " print(\"Converting camera model to PINHOLE format...\")\n",
776
+ " convert_cameras_to_pinhole(\n",
777
+ " os.path.join(colmap_model_dir, 'cameras.txt'),\n",
778
+ " f\"{data_dir}/sparse/0/cameras.txt\"\n",
779
+ " )\n",
780
+ "\n",
781
+ " # Copy other files\n",
782
+ " for filename in ['images.txt', 'points3D.txt']:\n",
783
+ " src = os.path.join(colmap_model_dir, filename)\n",
784
+ " dst = f\"{data_dir}/sparse/0/{filename}\"\n",
785
+ " if os.path.exists(src):\n",
786
+ " shutil.copy(src, dst)\n",
787
+ " print(f\"Copied {filename}\")\n",
788
+ " else:\n",
789
+ " print(f\"Warning: {filename} not found\")\n",
790
+ "\n",
791
+ " print(f\"Data preparation complete: {data_dir}\")\n",
792
+ " return data_dir\n",
793
+ "\n",
794
+ "\n",
795
+ "\n",
796
+ "\n",
797
+ "# After (mipGS) - Added Kernel Size and Multi-Scale Support\n",
798
+ "def train_gaussian_splatting(data_dir, work_dir, iterations=3000):\n",
799
+ " \"\"\"Training function for mipGS with comprehensive error handling\"\"\"\n",
800
+ "\n",
801
+ " # 入力検証\n",
802
+ " if not work_dir:\n",
803
+ " raise ValueError(\"work_dir cannot be None or empty\")\n",
804
+ "\n",
805
+ " if not os.path.exists(work_dir):\n",
806
+ " raise FileNotFoundError(f\"Work directory not found: {work_dir}\")\n",
807
+ "\n",
808
+ " if not os.path.exists(data_dir):\n",
809
+ " raise FileNotFoundError(f\"Data directory not found: {data_dir}\")\n",
810
+ "\n",
811
+ " train_py_path = os.path.join(work_dir, \"train.py\")\n",
812
+ " if not os.path.exists(train_py_path):\n",
813
+ " raise FileNotFoundError(f\"train.py not found: {train_py_path}\")\n",
814
+ "\n",
815
+ " # モデル保存パス\n",
816
+ " model_path = os.path.join(work_dir, \"output\", \"video\")\n",
817
+ " os.makedirs(model_path, exist_ok=True)\n",
818
+ "\n",
819
+ " # コマンド構築\n",
820
+ " cmd = [\n",
821
+ " sys.executable, 'train.py',\n",
822
+ " '-s', data_dir,\n",
823
+ " '-m', model_path,\n",
824
+ " '--iterations', str(iterations),\n",
825
+ " '--eval'\n",
826
+ " ]\n",
827
+ "\n",
828
+ " print(f\"Training configuration:\")\n",
829
+ " print(f\" Work dir: {work_dir}\")\n",
830
+ " print(f\" Data dir: {data_dir}\")\n",
831
+ " print(f\" Model path: {model_path}\")\n",
832
+ " print(f\" Command: {' '.join(cmd)}\")\n",
833
+ "\n",
834
+ " # 実行\n",
835
+ " result = subprocess.run(\n",
836
+ " cmd,\n",
837
+ " cwd=work_dir,\n",
838
+ " capture_output=True,\n",
839
+ " text=True\n",
840
+ " )\n",
841
+ "\n",
842
+ " # エラーチェック\n",
843
+ " if result.returncode != 0:\n",
844
+ " print(f\"\\n❌ Training failed with exit code {result.returncode}\")\n",
845
+ " print(\"\\n--- STDOUT ---\")\n",
846
+ " print(result.stdout)\n",
847
+ " print(\"\\n--- STDERR ---\")\n",
848
+ " print(result.stderr)\n",
849
+ " raise subprocess.CalledProcessError(result.returncode, cmd)\n",
850
+ "\n",
851
+ " print(\"\\n✅ Training completed successfully\")\n",
852
+ " return model_path\n",
853
+ "\n",
854
+ "\n",
855
+ "\n",
856
+ "# After (mipGS) - Added Multi-Scale Testing Support\n",
857
+ "def render_video(model_path, output_video_path, iteration=3000,\n",
858
+ " multiscale=False, scale_factors=None):\n",
859
+ " \"\"\"\n",
860
+ " Generate video from the trained model (mipGS version)\n",
861
+ "\n",
862
+ " Args:\n",
863
+ " model_path: Path to the trained model\n",
864
+ " output_video_path: Output video file path\n",
865
+ " iteration: Iteration number to render\n",
866
+ " multiscale: If True, render at multiple scales\n",
867
+ " scale_factors: List of scale factors [1.0, 2.0, 4.0, 8.0] or None for default\n",
868
+ " \"\"\"\n",
869
+ " print(\"Rendering video...\")\n",
870
+ "\n",
871
+ " # Default scale factors for multi-scale testing\n",
872
+ " if multiscale and scale_factors is None:\n",
873
+ " scale_factors = [1.0, 2.0, 4.0, 8.0]\n",
874
+ " elif not multiscale:\n",
875
+ " scale_factors = [1.0] # Single scale only\n",
876
+ "\n",
877
+ " # Render at each scale\n",
878
+ " for scale in scale_factors:\n",
879
+ " scale_str = f\"scale_{scale:.1f}\" if multiscale else \"\"\n",
880
+ " print(f\"Rendering at scale {scale}x...\")\n",
881
+ "\n",
882
+ " # Execute rendering with scale factor\n",
883
+ " cmd = [\n",
884
+ " sys.executable, 'render.py',\n",
885
+ " '-m', model_path,\n",
886
+ " '--iteration', str(iteration)\n",
887
+ " ]\n",
888
+ "\n",
889
+ " # Add scale factor parameter for mipGS\n",
890
+ " if scale != 1.0:\n",
891
+ " cmd.extend(['--scale_factor', str(scale)])\n",
892
+ "\n",
893
+ " subprocess.run(cmd, cwd=WORK_DIR, check=True)\n",
894
+ "\n",
895
+ " # Find the rendering directory (use original scale for video)\n",
896
+ " possible_dirs = [\n",
897
+ " f\"{model_path}/test/ours_{iteration}/renders\",\n",
898
+ " f\"{model_path}/train/ours_{iteration}/renders\",\n",
899
+ " ]\n",
900
+ "\n",
901
+ " render_dir = None\n",
902
+ " for test_dir in possible_dirs:\n",
903
+ " if os.path.exists(test_dir):\n",
904
+ " render_dir = test_dir\n",
905
+ " print(f\"Rendering directory found: {render_dir}\")\n",
906
+ " break\n",
907
+ "\n",
908
+ " if render_dir and os.path.exists(render_dir):\n",
909
+ " render_imgs = sorted([f for f in os.listdir(render_dir) if f.endswith('.png')])\n",
910
+ "\n",
911
+ " if render_imgs:\n",
912
+ " print(f\"Found {len(render_imgs)} rendered images\")\n",
913
+ "\n",
914
+ " # Create video with ffmpeg\n",
915
+ " subprocess.run([\n",
916
+ " 'ffmpeg', '-y',\n",
917
+ " '-framerate', '30',\n",
918
+ " '-pattern_type', 'glob',\n",
919
+ " '-i', f\"{render_dir}/*.png\",\n",
920
+ " '-c:v', 'libx264',\n",
921
+ " '-pix_fmt', 'yuv420p',\n",
922
+ " '-crf', '18',\n",
923
+ " output_video_path\n",
924
+ " ], check=True)\n",
925
+ "\n",
926
+ " print(f\"Video saved: {output_video_path}\")\n",
927
+ "\n",
928
+ " # If multiscale, save additional scale videos\n",
929
+ " if multiscale:\n",
930
+ " for scale in scale_factors:\n",
931
+ " if scale != 1.0:\n",
932
+ " scale_render_dir = render_dir.replace('renders', f'renders_scale_{scale:.1f}')\n",
933
+ " if os.path.exists(scale_render_dir):\n",
934
+ " scale_video_path = output_video_path.replace('.mp4', f'_scale_{scale:.1f}x.mp4')\n",
935
+ " subprocess.run([\n",
936
+ " 'ffmpeg', '-y',\n",
937
+ " '-framerate', '30',\n",
938
+ " '-pattern_type', 'glob',\n",
939
+ " '-i', f\"{scale_render_dir}/*.png\",\n",
940
+ " '-c:v', 'libx264',\n",
941
+ " '-pix_fmt', 'yuv420p',\n",
942
+ " '-crf', '18',\n",
943
+ " scale_video_path\n",
944
+ " ], check=True)\n",
945
+ " print(f\"Multi-scale video saved: {scale_video_path}\")\n",
946
+ "\n",
947
+ " return True\n",
948
+ "\n",
949
+ " print(\"Error: Rendering directory not found\")\n",
950
+ " return False\n",
951
+ "\n",
952
+ "\n",
953
+ "\n",
954
+ "def create_gif(video_path, gif_path):\n",
955
+ " \"\"\"Create GIF from MP4\"\"\"\n",
956
+ " print(\"Creating animated GIF...\")\n",
957
+ "\n",
958
+ " subprocess.run([\n",
959
+ " 'ffmpeg', '-y',\n",
960
+ " '-i', video_path,\n",
961
+ " '-vf', 'setpts=8*PTS,fps=10,scale=720:-1:flags=lanczos',\n",
962
+ " '-loop', '0',\n",
963
+ " gif_path\n",
964
+ " ], check=True)\n",
965
+ "\n",
966
+ " if os.path.exists(gif_path):\n",
967
+ " size_mb = os.path.getsize(gif_path) / (1024 * 1024)\n",
968
+ " print(f\"GIF creation complete: {gif_path} ({size_mb:.2f} MB)\")\n",
969
+ " return True\n",
970
+ "\n",
971
+ " return False\n",
972
+ ""
973
+ ]
974
+ },
975
+ {
976
+ "cell_type": "code",
977
+ "source": [
978
+ "# New function for mipGS - Fuse 3D filter into Gaussian parameters\n",
979
+ "def create_fused_ply(model_path, scene_name, output_dir=\"fused\"):\n",
980
+ " \"\"\"\n",
981
+ " Fuse the 3D smoothing filter to Gaussian parameters for deployment\n",
982
+ " This creates a .ply file that can be used in online viewers\n",
983
+ "\n",
984
+ " Args:\n",
985
+ " model_path: Path to trained model\n",
986
+ " scene_name: Name of the scene\n",
987
+ " output_dir: Directory to save fused .ply file\n",
988
+ " \"\"\"\n",
989
+ " os.makedirs(output_dir, exist_ok=True)\n",
990
+ " output_ply = f\"{output_dir}/{scene_name}_fused.ply\"\n",
991
+ "\n",
992
+ " cmd = [\n",
993
+ " sys.executable, 'create_fused_ply.py',\n",
994
+ " '-m', f\"{model_path}/{scene_name}\",\n",
995
+ " '--output_ply', output_ply\n",
996
+ " ]\n",
997
+ " subprocess.run(cmd, cwd=WORK_DIR, check=True)\n",
998
+ " return output_ply\n",
999
+ ""
1000
+ ],
1001
+ "metadata": {
1002
+ "id": "-Cwgr3I0b57O"
1003
+ },
1004
+ "id": "-Cwgr3I0b57O",
1005
+ "execution_count": 24,
1006
+ "outputs": []
1007
+ },
1008
+ {
1009
+ "cell_type": "code",
1010
+ "source": [
1011
+ "COLMAP_DIR"
1012
+ ],
1013
+ "metadata": {
1014
+ "colab": {
1015
+ "base_uri": "https://localhost:8080/",
1016
+ "height": 35
1017
+ },
1018
+ "id": "69FPH443eEGO",
1019
+ "outputId": "5d761deb-b3a3-4906-cbe9-515e211e6f0f"
1020
+ },
1021
+ "id": "69FPH443eEGO",
1022
+ "execution_count": 25,
1023
+ "outputs": [
1024
+ {
1025
+ "output_type": "execute_result",
1026
+ "data": {
1027
+ "text/plain": [
1028
+ "'/content/colmap_data'"
1029
+ ],
1030
+ "application/vnd.google.colaboratory.intrinsic+json": {
1031
+ "type": "string"
1032
+ }
1033
+ },
1034
+ "metadata": {},
1035
+ "execution_count": 25
1036
+ }
1037
+ ]
1038
+ },
1039
+ {
1040
+ "cell_type": "code",
1041
+ "execution_count": null,
1042
+ "id": "f75233a8",
1043
+ "metadata": {
1044
+ "execution": {
1045
+ "iopub.execute_input": "2026-01-10T18:22:43.807508Z",
1046
+ "iopub.status.busy": "2026-01-10T18:22:43.807294Z",
1047
+ "iopub.status.idle": "2026-01-11T00:00:17.030890Z",
1048
+ "shell.execute_reply": "2026-01-11T00:00:17.029927Z"
1049
+ },
1050
+ "papermill": {
1051
+ "duration": 20253.434865,
1052
+ "end_time": "2026-01-11T00:00:17.234174",
1053
+ "exception": false,
1054
+ "start_time": "2026-01-10T18:22:43.799309",
1055
+ "status": "completed"
1056
+ },
1057
+ "tags": [],
1058
+ "id": "f75233a8",
1059
+ "outputId": "f1d112e0-5c58-4e5f-b343-977723b922a2",
1060
+ "colab": {
1061
+ "base_uri": "https://localhost:8080/"
1062
+ }
1063
+ },
1064
+ "outputs": [
1065
+ {
1066
+ "output_type": "stream",
1067
+ "name": "stdout",
1068
+ "text": [
1069
+ "============================================================\n",
1070
+ "Step 1: Normalizing and preprocessing images\n",
1071
+ "============================================================\n",
1072
+ "--- Step 1: Biplet-Square Normalization ---\n",
1073
+ "Generating 2 cropped squares (Left/Right or Top/Bottom) for each image...\n",
1074
+ "\n",
1075
+ "Processing limited to 20 source images (will generate 40 cropped images)\n",
1076
+ " ✓ image_101.jpeg: (1440, 1920) → 2 square images generated\n",
1077
+ " ✓ image_102.jpeg: (1440, 1920) → 2 square images generated\n",
1078
+ " ✓ image_103.jpeg: (1440, 1920) → 2 square images generated\n",
1079
+ " ✓ image_104.jpeg: (1440, 1920) → 2 square images generated\n",
1080
+ " ✓ image_105.jpeg: (1440, 1920) → 2 square images generated\n",
1081
+ " ✓ image_106.jpeg: (1440, 1920) → 2 square images generated\n",
1082
+ " ✓ image_107.jpeg: (1440, 1920) → 2 square images generated\n",
1083
+ " ✓ image_108.jpeg: (1440, 1920) → 2 square images generated\n",
1084
+ " ✓ image_109.jpeg: (1440, 1920) → 2 square images generated\n",
1085
+ " ✓ image_110.jpeg: (1440, 1920) → 2 square images generated\n",
1086
+ " ✓ image_111.jpeg: (1440, 1920) → 2 square images generated\n",
1087
+ " ✓ image_112.jpeg: (1440, 1920) → 2 square images generated\n",
1088
+ " ✓ image_113.jpeg: (1440, 1920) → 2 square images generated\n",
1089
+ " ✓ image_114.jpeg: (1440, 1920) → 2 square images generated\n",
1090
+ " ✓ image_115.jpeg: (1440, 1920) → 2 square images generated\n",
1091
+ " ✓ image_116.jpeg: (1440, 1920) → 2 square images generated\n",
1092
+ " ✓ image_117.jpeg: (1440, 1920) → 2 square images generated\n",
1093
+ " ✓ image_118.jpeg: (1440, 1920) → 2 square images generated\n",
1094
+ " ✓ image_119.jpeg: (1440, 1920) → 2 square images generated\n",
1095
+ " ✓ image_120.jpeg: (1440, 1920) → 2 square images generated\n",
1096
+ "\n",
1097
+ "Processing complete: 20 source images processed\n",
1098
+ "Total output images: 40\n",
1099
+ "Original size distribution: {'1440x1920': 20}\n",
1100
+ "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",
1101
+ "============================================================\n",
1102
+ "Step 2: Running COLMAP reconstruction\n",
1103
+ "============================================================\n",
1104
+ "Running SfM reconstruction with COLMAP...\n",
1105
+ "1/4: Extracting features...\n"
1106
+ ]
1107
+ }
1108
+ ],
1109
+ "source": [
1110
+ "def main_pipeline(image_dir, output_dir,\n",
1111
+ " square_size=1024, max_images=100):\n",
1112
+ " \"\"\"Main execution function\"\"\"\n",
1113
+ " try:\n",
1114
+ " # Step 1: 画像の正規化と前処理\n",
1115
+ " print(\"=\"*60)\n",
1116
+ " print(\"Step 1: Normalizing and preprocessing images\")\n",
1117
+ " print(\"=\"*60)\n",
1118
+ "\n",
1119
+ " frame_dir = os.path.join(COLMAP_DIR, \"images\")\n",
1120
+ " os.makedirs(frame_dir, exist_ok=True)\n",
1121
+ "\n",
1122
+ " # 画像を正規化して直接COLMAPのディレクトリに保存\n",
1123
+ " num_processed = normalize_image_sizes_biplet(\n",
1124
+ " input_dir=image_dir,\n",
1125
+ " output_dir=frame_dir, # 直接colmap/imagesに保存\n",
1126
+ " size=square_size,\n",
1127
+ " max_images=max_images\n",
1128
+ " )\n",
1129
+ "\n",
1130
+ " print(f\"Processed {num_processed} images\")\n",
1131
+ "\n",
1132
+ " # Step 2: Estimate Camera Info with COLMAP\n",
1133
+ " print(\"=\"*60)\n",
1134
+ " print(\"Step 2: Running COLMAP reconstruction\")\n",
1135
+ " print(\"=\"*60)\n",
1136
+ " colmap_model_dir = run_colmap_reconstruction(frame_dir, COLMAP_DIR)\n",
1137
+ "\n",
1138
+ " print(frame_dir)\n",
1139
+ " print(colmap_model_dir)\n",
1140
+ "\n",
1141
+ " # Step 3: Prepare Data for Gaussian Splatting\n",
1142
+ " print(\"=\"*60)\n",
1143
+ " print(\"Step 3: Preparing Gaussian Splatting data\")\n",
1144
+ " print(\"=\"*60)\n",
1145
+ " data_dir = prepare_gaussian_splatting_data(frame_dir, colmap_model_dir)\n",
1146
+ "\n",
1147
+ " # Step 4: Train Model\n",
1148
+ " print(\"=\"*60)\n",
1149
+ " print(\"Step 4: Training Gaussian Splatting model\")\n",
1150
+ " print(\"=\"*60)\n",
1151
+ " model_path = train_gaussian_splatting(\n",
1152
+ " data_dir=data_dir,\n",
1153
+ " work_dir=work_dir, # 明示的に渡す\n",
1154
+ " iterations=3000\n",
1155
+ " )\n",
1156
+ "\n",
1157
+ " # Step 5: Render Video\n",
1158
+ " print(\"=\"*60)\n",
1159
+ " print(\"Step 5: Rendering video\")\n",
1160
+ " print(\"=\"*60)\n",
1161
+ " os.makedirs(OUTPUT_DIR, exist_ok=True)\n",
1162
+ " output_video = os.path.join(OUTPUT_DIR, \"gaussian_splatting_video.mp4\")\n",
1163
+ "\n",
1164
+ " # 2. マルチスケールレンダリング(mipGSの特徴を活用)\n",
1165
+ " success = render_video(\n",
1166
+ " model_path=\"output/video\",\n",
1167
+ " output_video_path=\"output.mp4\",\n",
1168
+ " iteration=3000,\n",
1169
+ " multiscale=True, # マルチスケールを有効化\n",
1170
+ " scale_factors=[1.0, 2.0, 4.0] # カスタムスケール\n",
1171
+ " )\n",
1172
+ "\n",
1173
+ " if success:\n",
1174
+ " print(\"=\"*60)\n",
1175
+ " print(f\"Success! Video generation complete: {output_video}\")\n",
1176
+ " print(\"=\"*60)\n",
1177
+ "\n",
1178
+ " # Create GIF\n",
1179
+ " output_gif = os.path.join(OUTPUT_DIR, \"gaussian_splatting_video.gif\")\n",
1180
+ " create_gif(output_video, output_gif)\n",
1181
+ "\n",
1182
+ " # Display result\n",
1183
+ " from IPython.display import Image, display\n",
1184
+ " display(Image(open(output_gif, 'rb').read()))\n",
1185
+ "\n",
1186
+ " return output_video, output_gif\n",
1187
+ " else:\n",
1188
+ " print(\"Warning: Rendering complete, but video was not generated\")\n",
1189
+ " return None, None\n",
1190
+ "\n",
1191
+ " except Exception as e:\n",
1192
+ " print(f\"Error: {str(e)}\")\n",
1193
+ " import traceback\n",
1194
+ " traceback.print_exc()\n",
1195
+ " return None, None\n",
1196
+ "\n",
1197
+ "\n",
1198
+ "\n",
1199
+ "if __name__ == \"__main__\":\n",
1200
+ " IMAGE_DIR = \"/content/drive/MyDrive/your_folder/fountain100\"\n",
1201
+ " OUTPUT_DIR = \"/content/output\"\n",
1202
+ " COLMAP_DIR = \"/content/colmap\"\n",
1203
+ "\n",
1204
+ " video_path, gif_path = main_pipeline(\n",
1205
+ " image_dir=IMAGE_DIR,\n",
1206
+ " output_dir=OUTPUT_DIR,\n",
1207
+ " square_size=1024,\n",
1208
+ " max_images=20\n",
1209
+ " )\n",
1210
+ "\n",
1211
+ "\n"
1212
+ ]
1213
+ },
1214
+ {
1215
+ "cell_type": "markdown",
1216
+ "id": "e17ec719",
1217
+ "metadata": {
1218
+ "papermill": {
1219
+ "duration": 0.49801,
1220
+ "end_time": "2026-01-11T00:00:18.165833",
1221
+ "exception": false,
1222
+ "start_time": "2026-01-11T00:00:17.667823",
1223
+ "status": "completed"
1224
+ },
1225
+ "tags": [],
1226
+ "id": "e17ec719"
1227
+ },
1228
+ "source": []
1229
+ },
1230
+ {
1231
+ "cell_type": "markdown",
1232
+ "id": "38b3974c",
1233
+ "metadata": {
1234
+ "papermill": {
1235
+ "duration": 0.427583,
1236
+ "end_time": "2026-01-11T00:00:19.008387",
1237
+ "exception": false,
1238
+ "start_time": "2026-01-11T00:00:18.580804",
1239
+ "status": "completed"
1240
+ },
1241
+ "tags": [],
1242
+ "id": "38b3974c"
1243
+ },
1244
+ "source": []
1245
+ }
1246
+ ],
1247
+ "metadata": {
1248
+ "kaggle": {
1249
+ "accelerator": "nvidiaTeslaT4",
1250
+ "dataSources": [
1251
+ {
1252
+ "databundleVersionId": 5447706,
1253
+ "sourceId": 49349,
1254
+ "sourceType": "competition"
1255
+ },
1256
+ {
1257
+ "datasetId": 1429416,
1258
+ "sourceId": 14451718,
1259
+ "sourceType": "datasetVersion"
1260
+ }
1261
+ ],
1262
+ "dockerImageVersionId": 31090,
1263
+ "isGpuEnabled": true,
1264
+ "isInternetEnabled": true,
1265
+ "language": "python",
1266
+ "sourceType": "notebook"
1267
+ },
1268
+ "kernelspec": {
1269
+ "display_name": "Python 3",
1270
+ "name": "python3"
1271
+ },
1272
+ "language_info": {
1273
+ "codemirror_mode": {
1274
+ "name": "ipython",
1275
+ "version": 3
1276
+ },
1277
+ "file_extension": ".py",
1278
+ "mimetype": "text/x-python",
1279
+ "name": "python",
1280
+ "nbconvert_exporter": "python",
1281
+ "pygments_lexer": "ipython3",
1282
+ "version": "3.11.13"
1283
+ },
1284
+ "papermill": {
1285
+ "default_parameters": {},
1286
+ "duration": 20573.990788,
1287
+ "end_time": "2026-01-11T00:00:22.081506",
1288
+ "environment_variables": {},
1289
+ "exception": null,
1290
+ "input_path": "__notebook__.ipynb",
1291
+ "output_path": "__notebook__.ipynb",
1292
+ "parameters": {},
1293
+ "start_time": "2026-01-10T18:17:28.090718",
1294
+ "version": "2.6.0"
1295
+ },
1296
+ "colab": {
1297
+ "provenance": [],
1298
+ "gpuType": "T4"
1299
+ },
1300
+ "accelerator": "GPU"
1301
+ },
1302
+ "nbformat": 4,
1303
+ "nbformat_minor": 5
1304
+ }