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

Delete biplet_colmap_mipgs_colab_06.ipynb

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