0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Meta の Map-Anything をローカルで動かす(使い方編 / Gradio 6.x 互換性メモ)

0
Posted at

はじめに

こんにちは、しゅんです。
今回は Meta の MapAnything を「とりあえず手元で動かす」ための 使い方編です。GUI(Gradioデモ)とCLI推論を試しつつ、ハマった点(Gradio 6.x の互換性エラー)も含めてまとめます。

GitHub:

前編

0. 環境メモ(自分のローカル)

  • Python: venv で動かしました(condaでもOKですが、私はconda嫌いなので載せません)
  • 初回実行時、モデルを Hugging Face からダウンロードするためネットが必要
  • 画像枚数が多いと VRAM/RAM が増えがち → --memory_efficient_inference が用意されている(今回は未検証)

1. セットアップ(最小)

リポジトリ取得 & venv

git clone https://github.com/facebookresearch/map-anything.git
cd map-anything

# 例: Python 3.12 を使いたい場合は python3.12 -m venv .venv でもOK
python -m venv .venv
source .venv/bin/activate

依存インストール(最小)

pip install -e .

Gradioデモも使う場合(追加)

pip install -e ".[gradio]"

2. まずは CLI で最小推論(画像フォルダ → GLB)

一番手堅く「動いた」を確認するならこれ。

python scripts/demo_images_only_inference.py \
  --image_folder /path/to/images \
  --viz \
  --save_glb \
  --output_path output.glb
  • --viz:可視化を有効化(Rerunなどを使う想定)
  • --save_glb:結果を GLB で保存
  • --output_path:保存先

メモリが厳しいとき(今回は未検証)

python scripts/demo_images_only_inference.py \
  --image_folder /path/to/images \
  --memory_efficient_inference \
  --save_glb \
  --output_path output.glb

今回の自分のケースではメモリ的に困らなかったので、--memory_efficient_inference は未検証です。

3. 可視化:Rerun(今回は未検証)

MapAnything の周辺は Rerun を使った可視化導線もあります。
(ただし私は今回は Gradioデモで確認したので、Rerunは未検証です)

Rerun サーバ例:

rerun --serve --port 2004 --web-viewer-port 2006

別ターミナルでCLIを回す例:

python scripts/demo_images_only_inference.py \
  --image_folder /path/to/images \
  --viz \
  --save_glb \
  --output_path output.glb

4. Gradio デモを動かす(+ Gradio 6.x 互換性エラー修正)

起動方法

python scripts/gradio_app.py

そこで遭遇したエラー

TypeError: Gallery.__init__() got an unexpected keyword argument 'show_download_button'

原因(自分の理解)

自分の環境(Gradio 6.1 系)では、gr.Gallery(..., show_download_button=True) がそのまま通らず、エラーになりました。

対応(修正方針)

  • show_download_button=True → buttons=["download"] に置き換え
  • ついでに、Gradio 6 系で警告が出やすい theme/css の渡し方も整理
    (Blocks(theme=..., css=...) ではなく、launch(theme=..., css=...) へ寄せる)

修正差分(scripts/gradio_app.py)

diff --git a/scripts/gradio_app.py b/scripts/gradio_app.py
index 66bcec4..ba18df2 100644
--- a/scripts/gradio_app.py
+++ b/scripts/gradio_app.py
@@ -1087,7 +1087,7 @@ def load_example_scene(scene_name, examples_dir="examples"):
 # -------------------------------------------------------------------------
 theme = get_gradio_theme()
 
-with gr.Blocks(theme=theme, css=GRADIO_CSS) as demo:
+with gr.Blocks() as demo:
@@ -1120,7 +1120,7 @@ with gr.Blocks(theme=theme, css=GRADIO_CSS) as demo:
                 label="Preview",
                 columns=4,
                 height="300px",
-                show_download_button=True,
+                buttons=["download"],
                 object_fit="contain",
                 preview=True,
             )
@@ -1582,4 +1582,10 @@ with gr.Blocks(theme=theme, css=GRADIO_CSS) as demo:
     # -------------------------------------------------------------------------
     gr.HTML(get_acknowledgements_html())
 
-    demo.queue(max_size=20).launch(show_error=True, share=True, ssr_mode=False)
+    demo.queue(max_size=20).launch(
+        show_error=True,
+        share=True,
+        ssr_mode=False,
+        theme=theme,
+        css=GRADIO_CSS,
+    )

修正後の使い方(流れ)

  1. python scripts/gradio_app.py を起動

  2. ブラウザで 動画 or 複数画像をアップロード

  3. Reconstruct を押して推論開始

  4. UI上で以下のタブ(表示)から結果を確認できます

    • 3D View
    • Depth
    • Normal
    • Measure

5. COLMAP連携について(注意:一部未検証)

MapAnything には COLMAP形式へ書き出すスクリプトが用意されています(cameras.bin / images.bin / points3D.bin / points.ply)。

COLMAP形式へのエクスポート例

pip install -e ".[colmap]"

# feed-forwardのみ
python scripts/demo_colmap.py --scene_dir=/YOUR/SCENE_DIR/ --memory_efficient_inference

# BAあり
python scripts/demo_colmap.py --scene_dir=/YOUR/SCENE_DIR/ --memory_efficient_inference --use_ba
  • 出力は /YOUR/SCENE_DIR/sparse/ に保存される想定

GLB出力できるスクリプト(未検証)

scripts/demo_inference_on_colmap_outputs.py があり、GLB出力のオプションも用意されています。
ただし 自分はGLB出力後の中身確認までできてないので未検証です。

python scripts/demo_inference_on_colmap_outputs.py \
  --colmap_path /path/to/colmap_output \
  --viz \
  --save_glb \
  --output_path output.glb

6. 結果(Gradioで回してみた)

お茶のボトル、マジックキューブ、学校を撮影して Gradioで回してみた結果です。

7. まとめ(今回のポイント)

  • CLIの image-only 推論 → GLB保存が一番ラクに動作確認できる
  • Gradio 6.x だと show_download_button 周りで落ちることがある
    → buttons=["download"] に変更で回避できた
  • --memory_efficient_inference は「遅くなる代わりに多ビュー/低メモリ寄り」になる想定
    → 今回は 未検証
  • COLMAP連携は導線があるけど、スクリプトによっては自分はまだ 未検証な部分がある

今回も最後まで読んでくれてありがとうございます。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?