This project demonstrates a real-time image classification system built with Unity 6 (6000.0.58f2) and Unity Sentis (formerly Barracuda). It uses a deep learning model to classify input images directly within the Unity engine.
- In-Engine Inference: Runs AI models natively in Unity without external dependencies using Sentis.
- GPU Acceleration: Utilizes GPU Compute for efficient model execution.
- Image Processing: Automatically converts and resizes
Texture2Dinputs to the required tensor shape(1, 3, 224, 224). - Top Prediction: identifies the most likely class from the model's output.
- Target Search: Ability to check confidence for specific target objects (e.g. "goldfish").
- Model: MobileNetV2 (
mobilenetv2-10.onnx) - Input Resolution: 224x224 RGB
- Backend: Unity Sentis
BackendType.GPUCompute
- Unity Version: 6000.0.58f2 or later (should work with later unity 6 versions too)
- Packages:
com.unity.ai.inference(Sentis) v2.2.2
- Clone the Repository:
git clone <your-repo-url>
- Open in Unity:
- Open the project via Unity Hub.
- Ensure the Unity version matches or is compatible.
- Configuration:
- The main logic is in
ClassifyImage.cs. - Ensure a valid
.onnxmodel is assigned to theModel Assetfield. - Ensure
synset.txt(ImageNet labels) is assigned to theLabels Field. - Assign an input image to the
Input Imagefield in the inspector.
- The main logic is in
- Run:
- Enter Play Mode.
- The classification result will be logged to the Console.
Assets/Scripts/ClassifyImage.cs: Core logic for loading model, processing input, and interpreting results.Assets/AI Models/: Contains themobilenetv2-10.onnxmodel file.Assets/synset.txt: List of class labels (ImageNet).