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
|
| 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 |
+
]
|
| 855 |
+
},
|
| 856 |
+
{
|
| 857 |
+
"cell_type": "code",
|
| 858 |
+
"source": [
|
| 859 |
+
"# New function for mipGS - Fuse 3D filter into Gaussian parameters\n",
|
| 860 |
+
"def create_fused_ply(model_path, scene_name, output_dir=\"fused\"):\n",
|
| 861 |
+
" \"\"\"\n",
|
| 862 |
+
" Fuse the 3D smoothing filter to Gaussian parameters for deployment\n",
|
| 863 |
+
" This creates a .ply file that can be used in online viewers\n",
|
| 864 |
+
"\n",
|
| 865 |
+
" Args:\n",
|
| 866 |
+
" model_path: Path to trained model\n",
|
| 867 |
+
" scene_name: Name of the scene\n",
|
| 868 |
+
" output_dir: Directory to save fused .ply file\n",
|
| 869 |
+
" \"\"\"\n",
|
| 870 |
+
" os.makedirs(output_dir, exist_ok=True)\n",
|
| 871 |
+
" output_ply = f\"{output_dir}/{scene_name}_fused.ply\"\n",
|
| 872 |
+
"\n",
|
| 873 |
+
" cmd = [\n",
|
| 874 |
+
" sys.executable, 'create_fused_ply.py',\n",
|
| 875 |
+
" '-m', f\"{model_path}/{scene_name}\",\n",
|
| 876 |
+
" '--output_ply', output_ply\n",
|
| 877 |
+
" ]\n",
|
| 878 |
+
" subprocess.run(cmd, cwd=WORK_DIR, check=True)\n",
|
| 879 |
+
" return output_ply\n",
|
| 880 |
+
""
|
| 881 |
+
],
|
| 882 |
+
"metadata": {
|
| 883 |
+
"id": "-Cwgr3I0b57O"
|
| 884 |
+
},
|
| 885 |
+
"id": "-Cwgr3I0b57O",
|
| 886 |
+
"execution_count": 24,
|
| 887 |
+
"outputs": []
|
| 888 |
+
},
|
| 889 |
+
{
|
| 890 |
+
"cell_type": "code",
|
| 891 |
+
"execution_count": null,
|
| 892 |
+
"id": "f75233a8",
|
| 893 |
+
"metadata": {
|
| 894 |
+
"execution": {
|
| 895 |
+
"iopub.execute_input": "2026-01-10T18:22:43.807508Z",
|
| 896 |
+
"iopub.status.busy": "2026-01-10T18:22:43.807294Z",
|
| 897 |
+
"iopub.status.idle": "2026-01-11T00:00:17.030890Z",
|
| 898 |
+
"shell.execute_reply": "2026-01-11T00:00:17.029927Z"
|
| 899 |
+
},
|
| 900 |
+
"papermill": {
|
| 901 |
+
"duration": 20253.434865,
|
| 902 |
+
"end_time": "2026-01-11T00:00:17.234174",
|
| 903 |
+
"exception": false,
|
| 904 |
+
"start_time": "2026-01-10T18:22:43.799309",
|
| 905 |
+
"status": "completed"
|
| 906 |
+
},
|
| 907 |
+
"tags": [],
|
| 908 |
+
"id": "f75233a8",
|
| 909 |
+
"outputId": "3abca916-1c6a-42fa-c825-66f63f65f5de",
|
| 910 |
+
"colab": {
|
| 911 |
+
"base_uri": "https://localhost:8080/"
|
| 912 |
+
}
|
| 913 |
+
},
|
| 914 |
+
"outputs": [
|
| 915 |
+
{
|
| 916 |
+
"output_type": "stream",
|
| 917 |
+
"name": "stdout",
|
| 918 |
+
"text": [
|
| 919 |
+
"============================================================\n",
|
| 920 |
+
"Step 1: Normalizing and preprocessing images\n",
|
| 921 |
+
"============================================================\n",
|
| 922 |
+
"--- Step 1: Biplet-Square Normalization ---\n",
|
| 923 |
+
"Generating 2 cropped squares (Left/Right or Top/Bottom) for each image...\n",
|
| 924 |
+
"\n",
|
| 925 |
+
"Processing limited to 20 source images (will generate 40 cropped images)\n",
|
| 926 |
+
" ✓ image_101.jpeg: (1440, 1920) → 2 square images generated\n",
|
| 927 |
+
" ✓ image_102.jpeg: (1440, 1920) → 2 square images generated\n",
|
| 928 |
+
" ✓ image_103.jpeg: (1440, 1920) → 2 square images generated\n",
|
| 929 |
+
" ✓ image_104.jpeg: (1440, 1920) → 2 square images generated\n",
|
| 930 |
+
" ✓ image_105.jpeg: (1440, 1920) → 2 square images generated\n",
|
| 931 |
+
" ✓ image_106.jpeg: (1440, 1920) → 2 square images generated\n",
|
| 932 |
+
" ✓ image_107.jpeg: (1440, 1920) → 2 square images generated\n",
|
| 933 |
+
" ✓ image_108.jpeg: (1440, 1920) → 2 square images generated\n",
|
| 934 |
+
" ✓ image_109.jpeg: (1440, 1920) → 2 square images generated\n",
|
| 935 |
+
" ✓ image_110.jpeg: (1440, 1920) → 2 square images generated\n",
|
| 936 |
+
" ✓ image_111.jpeg: (1440, 1920) → 2 square images generated\n",
|
| 937 |
+
" ✓ image_112.jpeg: (1440, 1920) → 2 square images generated\n",
|
| 938 |
+
" ✓ image_113.jpeg: (1440, 1920) → 2 square images generated\n",
|
| 939 |
+
" ✓ image_114.jpeg: (1440, 1920) → 2 square images generated\n",
|
| 940 |
+
" ✓ image_115.jpeg: (1440, 1920) → 2 square images generated\n",
|
| 941 |
+
" ✓ image_116.jpeg: (1440, 1920) → 2 square images generated\n",
|
| 942 |
+
" ✓ image_117.jpeg: (1440, 1920) → 2 square images generated\n",
|
| 943 |
+
" ✓ image_118.jpeg: (1440, 1920) → 2 square images generated\n",
|
| 944 |
+
" ✓ image_119.jpeg: (1440, 1920) → 2 square images generated\n",
|
| 945 |
+
" ✓ image_120.jpeg: (1440, 1920) → 2 square images generated\n",
|
| 946 |
+
"\n",
|
| 947 |
+
"Processing complete: 20 source images processed\n",
|
| 948 |
+
"Total output images: 40\n",
|
| 949 |
+
"Original size distribution: {'1440x1920': 20}\n",
|
| 950 |
+
"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",
|
| 951 |
+
"============================================================\n",
|
| 952 |
+
"Step 2: Running COLMAP reconstruction\n",
|
| 953 |
+
"============================================================\n",
|
| 954 |
+
"Running SfM reconstruction with COLMAP...\n",
|
| 955 |
+
"1/4: Extracting features...\n",
|
| 956 |
+
"2/4: Matching features...\n",
|
| 957 |
+
"3/4: Sparse reconstruction...\n",
|
| 958 |
+
"4/4: Exporting to text format...\n",
|
| 959 |
+
"COLMAP reconstruction complete: /content/colmap/sparse/0\n",
|
| 960 |
+
"/content/colmap/images\n",
|
| 961 |
+
"/content/colmap/sparse/0\n",
|
| 962 |
+
"============================================================\n",
|
| 963 |
+
"Step 3: Preparing Gaussian Splatting data\n",
|
| 964 |
+
"============================================================\n",
|
| 965 |
+
"Preparing data for Gaussian Splatting...\n",
|
| 966 |
+
"Copying images...\n",
|
| 967 |
+
"Copied 40 images\n",
|
| 968 |
+
"Converting camera model to PINHOLE format...\n",
|
| 969 |
+
"Reading camera file: /content/colmap/sparse/0/cameras.txt\n",
|
| 970 |
+
"Converted 1 cameras to PINHOLE format\n",
|
| 971 |
+
"Copied images.txt\n",
|
| 972 |
+
"Copied points3D.txt\n",
|
| 973 |
+
"Data preparation complete: /content/mip-splatting/data/video\n",
|
| 974 |
+
"============================================================\n",
|
| 975 |
+
"Step 4: Training Gaussian Splatting model\n",
|
| 976 |
+
"============================================================\n",
|
| 977 |
+
"Training configuration:\n",
|
| 978 |
+
" Work dir: /content/mip-splatting\n",
|
| 979 |
+
" Data dir: /content/mip-splatting/data/video\n",
|
| 980 |
+
" Model path: /content/mip-splatting/output/video\n",
|
| 981 |
+
" Command: /usr/bin/python3 train.py -s /content/mip-splatting/data/video -m /content/mip-splatting/output/video --iterations 3000 --eval\n"
|
| 982 |
+
]
|
| 983 |
+
}
|
| 984 |
+
],
|
| 985 |
+
"source": [
|
| 986 |
+
"def main_pipeline(image_dir, output_dir,\n",
|
| 987 |
+
" square_size=1024, max_images=100):\n",
|
| 988 |
+
" \"\"\"Main execution function\"\"\"\n",
|
| 989 |
+
" try:\n",
|
| 990 |
+
" # Step 1: 画像の正規化と前処理\n",
|
| 991 |
+
" print(\"=\"*60)\n",
|
| 992 |
+
" print(\"Step 1: Normalizing and preprocessing images\")\n",
|
| 993 |
+
" print(\"=\"*60)\n",
|
| 994 |
+
"\n",
|
| 995 |
+
" frame_dir = os.path.join(COLMAP_DIR, \"images\")\n",
|
| 996 |
+
" os.makedirs(frame_dir, exist_ok=True)\n",
|
| 997 |
+
"\n",
|
| 998 |
+
" # 画像を正規化して直接COLMAPのディレクトリに保存\n",
|
| 999 |
+
" num_processed = normalize_image_sizes_biplet(\n",
|
| 1000 |
+
" input_dir=image_dir,\n",
|
| 1001 |
+
" output_dir=frame_dir, # 直接colmap/imagesに保存\n",
|
| 1002 |
+
" size=square_size,\n",
|
| 1003 |
+
" max_images=max_images\n",
|
| 1004 |
+
" )\n",
|
| 1005 |
+
"\n",
|
| 1006 |
+
" print(f\"Processed {num_processed} images\")\n",
|
| 1007 |
+
"\n",
|
| 1008 |
+
" # Step 2: Estimate Camera Info with COLMAP\n",
|
| 1009 |
+
" print(\"=\"*60)\n",
|
| 1010 |
+
" print(\"Step 2: Running COLMAP reconstruction\")\n",
|
| 1011 |
+
" print(\"=\"*60)\n",
|
| 1012 |
+
" colmap_model_dir = run_colmap_reconstruction(frame_dir, COLMAP_DIR)\n",
|
| 1013 |
+
"\n",
|
| 1014 |
+
" print(frame_dir)\n",
|
| 1015 |
+
" print(colmap_model_dir)\n",
|
| 1016 |
+
"\n",
|
| 1017 |
+
" # Step 3: Prepare Data for Gaussian Splatting\n",
|
| 1018 |
+
" print(\"=\"*60)\n",
|
| 1019 |
+
" print(\"Step 3: Preparing Gaussian Splatting data\")\n",
|
| 1020 |
+
" print(\"=\"*60)\n",
|
| 1021 |
+
" data_dir = prepare_gaussian_splatting_data(frame_dir, colmap_model_dir)\n",
|
| 1022 |
+
"\n",
|
| 1023 |
+
" # Step 4: Train Model\n",
|
| 1024 |
+
" print(\"=\"*60)\n",
|
| 1025 |
+
" print(\"Step 4: Training Gaussian Splatting model\")\n",
|
| 1026 |
+
" print(\"=\"*60)\n",
|
| 1027 |
+
" model_path = train_gaussian_splatting(\n",
|
| 1028 |
+
" data_dir=data_dir,\n",
|
| 1029 |
+
" work_dir=work_dir, # 明示的に渡す\n",
|
| 1030 |
+
" iterations=3000\n",
|
| 1031 |
+
" )\n",
|
| 1032 |
+
"\n",
|
| 1033 |
+
" except Exception as e:\n",
|
| 1034 |
+
" print(f\"Error: {str(e)}\")\n",
|
| 1035 |
+
" import traceback\n",
|
| 1036 |
+
" traceback.print_exc()\n",
|
| 1037 |
+
" return None, None\n",
|
| 1038 |
+
"\n",
|
| 1039 |
+
"\n",
|
| 1040 |
+
"\n",
|
| 1041 |
+
"if __name__ == \"__main__\":\n",
|
| 1042 |
+
" IMAGE_DIR = \"/content/drive/MyDrive/your_folder/fountain100\"\n",
|
| 1043 |
+
" OUTPUT_DIR = \"/content/output\"\n",
|
| 1044 |
+
" COLMAP_DIR = \"/content/colmap\"\n",
|
| 1045 |
+
"\n",
|
| 1046 |
+
" video_path, gif_path = main_pipeline(\n",
|
| 1047 |
+
" image_dir=IMAGE_DIR,\n",
|
| 1048 |
+
" output_dir=OUTPUT_DIR,\n",
|
| 1049 |
+
" square_size=1024,\n",
|
| 1050 |
+
" max_images=20\n",
|
| 1051 |
+
" )\n",
|
| 1052 |
+
"\n",
|
| 1053 |
+
"\n"
|
| 1054 |
+
]
|
| 1055 |
+
},
|
| 1056 |
+
{
|
| 1057 |
+
"cell_type": "markdown",
|
| 1058 |
+
"id": "e17ec719",
|
| 1059 |
+
"metadata": {
|
| 1060 |
+
"papermill": {
|
| 1061 |
+
"duration": 0.49801,
|
| 1062 |
+
"end_time": "2026-01-11T00:00:18.165833",
|
| 1063 |
+
"exception": false,
|
| 1064 |
+
"start_time": "2026-01-11T00:00:17.667823",
|
| 1065 |
+
"status": "completed"
|
| 1066 |
+
},
|
| 1067 |
+
"tags": [],
|
| 1068 |
+
"id": "e17ec719"
|
| 1069 |
+
},
|
| 1070 |
+
"source": []
|
| 1071 |
+
},
|
| 1072 |
+
{
|
| 1073 |
+
"cell_type": "markdown",
|
| 1074 |
+
"id": "38b3974c",
|
| 1075 |
+
"metadata": {
|
| 1076 |
+
"papermill": {
|
| 1077 |
+
"duration": 0.427583,
|
| 1078 |
+
"end_time": "2026-01-11T00:00:19.008387",
|
| 1079 |
+
"exception": false,
|
| 1080 |
+
"start_time": "2026-01-11T00:00:18.580804",
|
| 1081 |
+
"status": "completed"
|
| 1082 |
+
},
|
| 1083 |
+
"tags": [],
|
| 1084 |
+
"id": "38b3974c"
|
| 1085 |
+
},
|
| 1086 |
+
"source": []
|
| 1087 |
+
}
|
| 1088 |
+
],
|
| 1089 |
+
"metadata": {
|
| 1090 |
+
"kaggle": {
|
| 1091 |
+
"accelerator": "nvidiaTeslaT4",
|
| 1092 |
+
"dataSources": [
|
| 1093 |
+
{
|
| 1094 |
+
"databundleVersionId": 5447706,
|
| 1095 |
+
"sourceId": 49349,
|
| 1096 |
+
"sourceType": "competition"
|
| 1097 |
+
},
|
| 1098 |
+
{
|
| 1099 |
+
"datasetId": 1429416,
|
| 1100 |
+
"sourceId": 14451718,
|
| 1101 |
+
"sourceType": "datasetVersion"
|
| 1102 |
+
}
|
| 1103 |
+
],
|
| 1104 |
+
"dockerImageVersionId": 31090,
|
| 1105 |
+
"isGpuEnabled": true,
|
| 1106 |
+
"isInternetEnabled": true,
|
| 1107 |
+
"language": "python",
|
| 1108 |
+
"sourceType": "notebook"
|
| 1109 |
+
},
|
| 1110 |
+
"kernelspec": {
|
| 1111 |
+
"display_name": "Python 3",
|
| 1112 |
+
"name": "python3"
|
| 1113 |
+
},
|
| 1114 |
+
"language_info": {
|
| 1115 |
+
"codemirror_mode": {
|
| 1116 |
+
"name": "ipython",
|
| 1117 |
+
"version": 3
|
| 1118 |
+
},
|
| 1119 |
+
"file_extension": ".py",
|
| 1120 |
+
"mimetype": "text/x-python",
|
| 1121 |
+
"name": "python",
|
| 1122 |
+
"nbconvert_exporter": "python",
|
| 1123 |
+
"pygments_lexer": "ipython3",
|
| 1124 |
+
"version": "3.11.13"
|
| 1125 |
+
},
|
| 1126 |
+
"papermill": {
|
| 1127 |
+
"default_parameters": {},
|
| 1128 |
+
"duration": 20573.990788,
|
| 1129 |
+
"end_time": "2026-01-11T00:00:22.081506",
|
| 1130 |
+
"environment_variables": {},
|
| 1131 |
+
"exception": null,
|
| 1132 |
+
"input_path": "__notebook__.ipynb",
|
| 1133 |
+
"output_path": "__notebook__.ipynb",
|
| 1134 |
+
"parameters": {},
|
| 1135 |
+
"start_time": "2026-01-10T18:17:28.090718",
|
| 1136 |
+
"version": "2.6.0"
|
| 1137 |
+
},
|
| 1138 |
+
"colab": {
|
| 1139 |
+
"provenance": [],
|
| 1140 |
+
"gpuType": "T4"
|
| 1141 |
+
},
|
| 1142 |
+
"accelerator": "GPU"
|
| 1143 |
+
},
|
| 1144 |
+
"nbformat": 4,
|
| 1145 |
+
"nbformat_minor": 5
|
| 1146 |
+
}
|