数日前に Stability AI 及び Tripo AI からリリースされた TripoSR というものがあります。 Image-to-3dModel にあたるようです。
普段は、diffusers 経由で Stable Diffusion を触っていて、まだ触り始めて間もないので過去のリリースノートから追って行っている感じです。ですが、個人的に昨年は Unity とか触ってたので、3D モデル生成の TripoSR は思わず飛び付き、急に最新の情報に触れることになりました。3Dモデル生成はすごいワクワクします。
早速、使わせていただきましょう!!Google Colab で!!
TripoSR とは?
Stability AI と Tripo AI が共同開発した Text-to-3dModel のようです。
🎉新リリース🎉@tripoAI とのコラボレーションにより、TripoSR をリリースしました。
— Stability AI Japan (@StabilityAI_JP) 2024年3月5日
TripoSR は、1秒以内に高品質なアウトプットを作成できる新しい image-to-3D モデルです。
詳細はこちら:https://t.co/3vts0AHAh6 pic.twitter.com/EUVgAnmDVi
ソースコードは MIT ライセンスで GitHub 上に公開されており、Python で実行できるようになっていました。
準備
リポジトリをクローンする
!git clone https://github.com/VAST-AI-Research/TripoSR.git
ワーキングディレクトリを変更する
%cd TripoSR
必要モジュールをインストール
!pip install -r requirements.txt
実行してみる
!python run.py examples/chair.png --output-dir output/
output/ ディレクトリ以下に input.png と mesh.obj が出力されました。
mesh.obj を Blender で開いてみる
ちゃんと椅子の 3D モデルができました! ちなみにマテリアルは持っていないですが、頂点カラーを持っています。
ハンバーガーも作ってみる
!python run.py examples/hamburger.png --output-dir output2
run.py に渡している画像が input.png ではない
どうやら少し加工をしているようです。
image = remove_background(Image.open(image_path), rembg_session) image = resize_foreground(image, args.foreground_ratio) image = np.array(image).astype(np.float32) / 255.0 image = image[:, :, :3] * image[:, :, 3:4] + (1 - image[:, :, 3:4]) * 0.5 image = Image.fromarray((image * 255.0).astype(np.uint8)) if not os.path.exists(os.path.join(output_dir, str(i))): os.makedirs(os.path.join(output_dir, str(i))) image.save(os.path.join(output_dir, str(i), f"input.png"))
この辺のコードでしょうか。 remove_background をしたり resize_foreground をしたりしているようです。
run.py のヘルプを見る
!python run.py --help -- usage: run.py [-h] [--device DEVICE] [--pretrained-model-name-or-path PRETRAINED_MODEL_NAME_OR_PATH] [--chunk-size CHUNK_SIZE] [--no-remove-bg] [--foreground-ratio FOREGROUND_RATIO] [--output-dir OUTPUT_DIR] [--model-save-format {obj,glb}] [--render] image [image ...] positional arguments: image Path to input image(s). options: -h, --help show this help message and exit --device DEVICE Device to use. If no CUDA-compatible device is found, will fallback to 'cpu'. Default: 'cuda:0' --pretrained-model-name-or-path PRETRAINED_MODEL_NAME_OR_PATH Path to the pretrained model. Could be either a huggingface model id is or a local path. Default: 'stabilityai/TripoSR' --chunk-size CHUNK_SIZE Evaluation chunk size for surface extraction and rendering. Smaller chunk size reduces VRAM usage but increases computation time. 0 for no chunking. Default: 8192 --no-remove-bg If specified, the background will NOT be automatically removed from the input image, and the input image should be an RGB image with gray background and properly-sized foreground. Default: false --foreground-ratio FOREGROUND_RATIO Ratio of the foreground size to the image size. Only used when --no- remove-bg is not specified. Default: 0.85 --output-dir OUTPUT_DIR Output directory to save the results. Default: 'output/' --model-save-format {obj,glb} Format to save the extracted mesh. Default: 'obj' --render If specified, save a NeRF-rendered video. Default: false
--render オプションを付けてみる
!python run.py examples/hamburger.png --render --output-dir output2
アウトプットディレクトリ以下に render.mp4 が出力されましたね。
おまけ
お寿司はできるかな?
写真AC からまぐろの握り寿司 を使わせていただきます。
シャリと背景が同色だったのが悪かったですね...
まとめ
3D モデルがこんなに簡単にできるの凄いです。
すぐゲームに展開できそうです。