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

Delete biplet_colmap_mipgs_colab_05.ipynb

Browse files
Files changed (1) hide show
  1. biplet_colmap_mipgs_colab_05.ipynb +0 -1422
biplet_colmap_mipgs_colab_05.ipynb DELETED
@@ -1,1422 +0,0 @@
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
- }