This is a sample code to execute depth estimation using MiDaS with Unity.Sentis.
Important
GPU usage is assumed and compute shader is used for post-processing (depth mapping).
Unity : 6000.0.31f1
OS : Windows 11
GPU : GeForce RTX 4070 Ti
Unity.Sentis 2.1.1
Get any onnx format model from here.
Note
Operation is checked with model-f6b98070.onnx
Please put the downloaded onnx file in Assets folder of Unity.
Register the model you just created in the ModelAsset of the Exector (component) attached to the Exector (object).
Now all you have to do is play the Unity project. ✨
You can use other depth estimation models besides MiDaS by simply changing the settings.
Get the model in onnx format on this page.
🚧 Some models are not available. Under investigation... 🚧
I confirmed that it works correctly when using depth_anything_v2_vitb_indoor_dynamic.onnx.
The value of Input Width and Output Width should be 518.
MiDaSを利用した深度推定を、Unity.Sentisを用いて実行するサンプルプログラムです。
Important
GPU使用を前提とし、後処理(深度マップ作成)にはコンピュートシェーダを用いています。
ここから、任意のonnx形式モデルを入手してください。
Note
なお、動作確認は、model-f6b98070.onnx を用いています。
ダウンロードしたonnxファイルは、UnityのAssets内においてください。
Exector (オブジェクト)にアタッチされている Exector(コンポーネント)の、ModelAssetに先ほどのモデルを登録してください。
あとは、Unityプロジェクトを再生するだけです。
MiDaS以外の深度推定モデルでも、設定を変更することで使用できます。
ここ から onnx 形式のモデルを入手します。
Sentisが対応していない部分もあるようで、使用できないモデルもあるようです。
とはいえ、最低限 depth_anything_v2_vitb_indoor_dynamic.onnx は使用できることを確認済みです。
なお、入力・出力サイズ(Input Width と Output Width)は 518 に変更してください。
🚧 執筆中 🚧


