View GIFCreator.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static async Task<MediaAsset> CreateGIF (Texture2D[] textures) { | |
// Make sure `textures` is not empty | |
// Make sure every texture has the same size (width and height) | |
// Make sure every texture has the `TextureFormat.RGBA32` format | |
// Create recorder | |
var width = textures[0].width; | |
var height = textures[0].height; | |
var frameRate = 5; | |
var recorder = await MediaRecorder.Create( | |
MediaFormat.GIF, |
View RenderTextureDetect.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void Detect (RenderTexture renderTexture) { | |
// Create the YOLOX model | |
var model = await MLEdgeModel.Create("@natsuite/yolox"); | |
// Create the YOLOX predictor | |
var predictor = new YOLOXPredictor(model); | |
// Readback the render texture | |
AsyncGPUReadback.Request(renderTexture, request => { | |
// Create an image feature | |
var feature = new MLImageFeature(request.GetData<byte>(), request.width, request.height); | |
// Predict |
View MatOutput.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* NatDevice | |
* Copyright (c) 2022 NatML Inc. All Rights Reserved. | |
*/ | |
namespace NatSuite.Devices.Outputs { | |
using System; | |
using OpenCVForUnity.CoreModule; | |
using OpenCVForUnity.UtilsModule; |
View MLPredict.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Create a classification predictor | |
var labels = new [] { "cat", "dog", ... }; | |
var predictor = new MobileNetv2Predictor(model, labels); |
View MLModules.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Create a classifier module | |
var labels = new [] { "goldfish", "tiger shark", ... }; | |
var classifier = new MLClassifier("/path/to/classifier.onnx", labels); | |
// Classify an image | |
Texture2D image = ...; | |
var (label, confidence) = classifier.Predict(image); | |
Debug.Log($"Image contains {label} with confidence: {confidence}"); |
View MLPredict.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// If you have some feature | |
Texture2D image = ...; | |
// You can predict easily | |
var (label, confidence) = predictor.Predict(image); | |
Debug.Log($"Image contains {label} with confidence {confidence}"); |
View HelloML.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Load the ML model data | |
var modelData = MLModelData.FromFile("/path/to/model.onnx"); | |
// Deserialize the model | |
var model = modelData.Deserialize(); | |
// Print a model metadata value | |
Debug.Log("The model was created by: " + model["Author"]); | |
// Check the expected input size | |
var inputType = model.inputs[0] as MLImageType; | |
Debug.Log($"Model expects image with size: {inputType.width}x{inputType.height}"); |
View ThreadedAsyncTextureInput.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using NatSuite.Recorders.Inputs; | |
/// <summary> | |
/// Recorder input for recording video frames from textures. | |
/// </summary> | |
public class ThreadedAsyncTextureInput : ITextureInput { | |
#region --Client API-- | |
/// <summary> | |
/// Create a texture input which performs asynchronous readbacks. |
View Galaxy.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Camera2: Hardware level: 1 | |
06-02 10:49:07.625 21849 21865 I Unity : Camera2: FrameSize 4032 x 3024 [2.5824869781268642] | |
06-02 10:49:07.625 21849 21865 I Unity : Camera2: FrameSize 4032 x 2268 [2.2948049056750834] | |
06-02 10:49:07.625 21849 21865 I Unity : Camera2: FrameSize 3984 x 2988 [2.558534596033433] | |
06-02 10:49:07.625 21849 21865 I Unity : Camera2: FrameSize 3264 x 2448 [2.1598687907924505] | |
06-02 10:49:07.626 21849 21865 I Unity : Camera2: FrameSize 3264 x 1836 [1.8721867183406695] | |
06-02 10:49:07.626 21849 21865 I Unity : Camera2: FrameSize 3024 x 3024 [2.2948049056750834] | |
06-02 10:49:07.626 21849 21865 I Unity : Camera2: FrameSize 2976 x 2976 [2.2628042229822007] | |
06-02 10:49:07.626 21849 21865 I Unity : Camera2: FrameSize 2880 x 2160 [1.9095425048844386] | |
06-02 10:49:07.626 21849 21865 I Unity : Camera2: FrameSize 2592 x 1944 [1.698821473568786] |
View CameraTextureInput.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* NatCorder | |
* Copyright (c) 2020 Yusuf Olokoba. | |
*/ | |
namespace NatSuite.Recorders.Inputs { | |
using UnityEngine; | |
using UnityEngine.Rendering; |
NewerOlder