Skip to content

Commit

Permalink
Upgrade to NatML 1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
lanreolokoba committed Feb 1, 2023
1 parent cac2be3 commit 3312d62
Show file tree
Hide file tree
Showing 14 changed files with 379 additions and 369 deletions.
473 changes: 238 additions & 235 deletions Assembly-CSharp.csproj

Large diffs are not rendered by default.

20 changes: 11 additions & 9 deletions Assets/MeetSample.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Meet
* Copyright (c) 2022 NatML Inc. All Rights Reserved.
* Copyright © 2023 NatML Inc. All Rights Reserved.
*/

namespace NatML.Examples {
Expand All @@ -19,20 +19,17 @@ public class MeetSample : MonoBehaviour {
public RawImage rawImage;
public AspectRatioFitter aspectFitter;

private MLModel model;
private MLEdgeModel model;
private MeetPredictor predictor;
private RenderTexture matteTexture;

private async void Start () {
Debug.Log("Fetching model from NatML...");
// Fetch the model data from NatML Hub
var modelData = await MLModelData.FromHub("@natml/meet");
// Create the edge model
model = new MLEdgeModel(modelData);
// Create the model
model = await MLEdgeModel.Create("@natml/meet");
// Create the Meet predictor
predictor = new MeetPredictor(model);
// Listen for camera frames
cameraManager.OnFrame.AddListener(OnCameraFrame);
cameraManager.OnCameraFrame.AddListener(OnCameraFrame);
}

private void OnCameraFrame (CameraFrame frame) {
Expand All @@ -46,6 +43,11 @@ private void OnCameraFrame (CameraFrame frame) {
aspectFitter.aspectRatio = (float)matteTexture.width / matteTexture.height;
}

private void OnDisable () => model?.Dispose(); // Dispose model
private void OnDisable () {
// Stop listening for camera frames
cameraManager.OnCameraFrame.RemoveListener(OnCameraFrame);
// Dispose model
model?.Dispose();
}
}
}
7 changes: 4 additions & 3 deletions Assets/MeetSample.unity
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ RenderSettings:
m_ReflectionIntensity: 1
m_CustomReflection: {fileID: 0}
m_Sun: {fileID: 705507994}
m_IndirectSpecularColor: {r: 0.44657838, g: 0.49641234, b: 0.57481676, a: 1}
m_IndirectSpecularColor: {r: 0.4440765, g: 0.49331635, b: 0.57239074, a: 1}
m_UseRadianceAmbientProbe: 0
--- !u!157 &3
LightmapSettings:
Expand Down Expand Up @@ -379,11 +379,11 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
resolution: 3
capabilities: 1
capabilities: 2
playOnAwake: 1
focusMode: 0
exposureMode: 0
OnFrame:
OnCameraFrame:
m_PersistentCalls:
m_Calls: []
--- !u!1 &963194225
Expand Down Expand Up @@ -588,6 +588,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 4f231c4fb786f3946a6b90b886c48677, type: 3}
m_Name:
m_EditorClassIdentifier:
m_SendPointerHoverToParent: 1
m_HorizontalAxis: Horizontal
m_VerticalAxis: Vertical
m_SubmitButton: Submit
Expand Down
3 changes: 3 additions & 0 deletions Packages/ai.natml.vision.meet/Changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## 1.0.4
+ Upgraded to NatML 1.1.

## 1.0.3
+ Fixed incorrect prediction results on WebGL.
+ Upgraded to NatML 1.0.18.
Expand Down
16 changes: 7 additions & 9 deletions Packages/ai.natml.vision.meet/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,25 @@ Add the following items to your Unity project's `Packages/manifest.json`:
}
],
"dependencies": {
"ai.natml.vision.meet": "1.0.3"
"ai.natml.vision.meet": "1.0.4"
}
}
```

## Predicting the Matte
First, create the predictor:
```csharp
// Fetch the model data from NatML Hub
var modelData = await MLModelData.FromHub("@natml/meet");
// Deserialize the model
var model = modelData.Deserialize();
// Create the model
var model = await MLEdgeModel.Create("@natml/meet");
// Create the Meet predictor
var predictor = new MeetPredictor(model);
```

Then predict the human matte:
```csharp
// Predict
Texture2D image = ...; // This can also be a `WebCamTexture` or any other image feature
// Given an image...
Texture2D image = ...;
// Predict the human matte
MeetPredictor.Matte matte = predictor.Predict(image);
```

Expand All @@ -51,8 +50,7 @@ ___
## Quick Tips
- Discover more ML models on [NatML Hub](https://hub.natml.ai).
- See the [NatML documentation](https://docs.natml.ai/unity).
- Join the [NatML community on Discord](https://hub.natml.ai/community).
- Discuss [NatML on Unity Forums](https://forum.unity.com/threads/open-beta-natml-machine-learning-runtime.1109339/).
- Join the [NatML community on Discord](https://natml.ai/community).
- Contact us at [[email protected]](mailto:[email protected]).

Thank you very much!
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//
// Meet
// Copyright (c) 2022 NatML Inc. All Rights Reserved.
// Copyright (c) 2023 NatML Inc. All Rights Reserved.
//

#pragma kernel CSMain
Expand Down
2 changes: 1 addition & 1 deletion Packages/ai.natml.vision.meet/Runtime/Matte.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Meet
* Copyright (c) 2022 NatML Inc. All Rights Reserved.
* Copyright © 2023 NatML Inc. All Rights Reserved.
*/

namespace NatML.Vision {
Expand Down
6 changes: 3 additions & 3 deletions Packages/ai.natml.vision.meet/Runtime/MeetPredictor.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Meet
* Copyright (c) 2022 NatML Inc. All Rights Reserved.
* Copyright © 2023 NatML Inc. All Rights Reserved.
*/

namespace NatML.Vision {
Expand All @@ -19,8 +19,8 @@ public sealed partial class MeetPredictor : IMLPredictor<MeetPredictor.Matte> {
/// <summary>
/// Create the meet predictor.
/// </summary>
/// <param name="model">Meet ML model.</param>
public MeetPredictor (MLModel model) => this.model = model as MLEdgeModel;
/// <param name="model">Meet model.</param>
public MeetPredictor (MLEdgeModel model) => this.model = model as MLEdgeModel;

/// <summary>
/// Segment a person in an image.
Expand Down
4 changes: 2 additions & 2 deletions Packages/ai.natml.vision.meet/package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"name": "ai.natml.vision.meet",
"version": "1.0.3",
"version": "1.0.4",
"displayName": "Meet",
"description": "MediaPipe Meet Segmentation for human matting in Unity Engine.",
"unity": "2021.2",
"dependencies": {
"ai.natml.natml": "1.0.19"
"ai.natml.natml": "1.1.0"
},
"keywords": [
"natml",
Expand Down
10 changes: 5 additions & 5 deletions Packages/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@
}
],
"dependencies": {
"ai.natml.videokit": "0.0.3",
"com.unity.collab-proxy": "1.15.17",
"ai.natml.videokit": "0.0.9",
"com.unity.collab-proxy": "1.17.7",
"com.unity.feature.development": "1.0.1",
"com.unity.ide.rider": "3.0.14",
"com.unity.ide.visualstudio": "2.0.15",
"com.unity.ide.rider": "3.0.18",
"com.unity.ide.visualstudio": "2.0.17",
"com.unity.ide.vscode": "1.2.5",
"com.unity.test-framework": "1.1.31",
"com.unity.textmeshpro": "3.0.6",
"com.unity.timeline": "1.6.4",
"com.unity.ugui": "1.0.0",
"com.unity.visualscripting": "1.7.8",
"com.unity.visualscripting": "1.8.0",
"com.unity.modules.ai": "1.0.0",
"com.unity.modules.androidjni": "1.0.0",
"com.unity.modules.animation": "1.0.0",
Expand Down
41 changes: 21 additions & 20 deletions Packages/packages-lock.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{
"dependencies": {
"ai.natml.hub": {
"version": "1.0.15",
"depth": 2,
"version": "1.0.20",
"depth": 1,
"source": "registry",
"dependencies": {},
"url": "https://registry.npmjs.com"
},
"ai.natml.natcorder": {
"version": "1.9.1",
"version": "1.9.3",
"depth": 1,
"source": "registry",
"dependencies": {
Expand All @@ -17,7 +17,7 @@
"url": "https://registry.npmjs.com"
},
"ai.natml.natdevice": {
"version": "1.3.1",
"version": "1.3.2",
"depth": 1,
"source": "registry",
"dependencies": {
Expand All @@ -26,11 +26,11 @@
"url": "https://registry.npmjs.com"
},
"ai.natml.natml": {
"version": "1.0.19",
"version": "1.1.0",
"depth": 1,
"source": "registry",
"dependencies": {
"ai.natml.hub": "1.0.12"
"ai.natml.hub": "1.0.20"
},
"url": "https://registry.npmjs.com"
},
Expand All @@ -44,13 +44,14 @@
"url": "https://registry.npmjs.com"
},
"ai.natml.videokit": {
"version": "0.0.3",
"version": "0.0.9",
"depth": 0,
"source": "registry",
"dependencies": {
"ai.natml.natcorder": "1.9.1",
"ai.natml.natdevice": "1.3.1",
"ai.natml.natml": "1.0.19",
"ai.natml.hub": "1.0.20",
"ai.natml.natml": "1.1.0",
"ai.natml.natcorder": "1.9.3",
"ai.natml.natdevice": "1.3.2",
"ai.natml.natshare": "1.3.0"
},
"url": "https://registry.npmjs.com"
Expand All @@ -60,11 +61,11 @@
"depth": 0,
"source": "embedded",
"dependencies": {
"ai.natml.natml": "1.0.19"
"ai.natml.natml": "1.1.0"
}
},
"com.unity.collab-proxy": {
"version": "1.15.17",
"version": "1.17.7",
"depth": 0,
"source": "registry",
"dependencies": {
Expand All @@ -91,17 +92,17 @@
"depth": 0,
"source": "builtin",
"dependencies": {
"com.unity.ide.visualstudio": "2.0.15",
"com.unity.ide.rider": "3.0.14",
"com.unity.ide.visualstudio": "2.0.17",
"com.unity.ide.rider": "3.0.18",
"com.unity.ide.vscode": "1.2.5",
"com.unity.editorcoroutines": "1.0.0",
"com.unity.performance.profile-analyzer": "1.1.1",
"com.unity.test-framework": "1.1.31",
"com.unity.testtools.codecoverage": "1.0.1"
"com.unity.testtools.codecoverage": "1.2.2"
}
},
"com.unity.ide.rider": {
"version": "3.0.14",
"version": "3.0.18",
"depth": 0,
"source": "registry",
"dependencies": {
Expand All @@ -110,7 +111,7 @@
"url": "https://packages.unity.com"
},
"com.unity.ide.visualstudio": {
"version": "2.0.15",
"version": "2.0.17",
"depth": 0,
"source": "registry",
"dependencies": {
Expand Down Expand Up @@ -140,7 +141,7 @@
"url": "https://packages.unity.com"
},
"com.unity.services.core": {
"version": "1.4.0",
"version": "1.7.0",
"depth": 1,
"source": "registry",
"dependencies": {
Expand Down Expand Up @@ -169,7 +170,7 @@
"url": "https://packages.unity.com"
},
"com.unity.testtools.codecoverage": {
"version": "1.0.1",
"version": "1.2.2",
"depth": 1,
"source": "registry",
"dependencies": {
Expand Down Expand Up @@ -209,7 +210,7 @@
}
},
"com.unity.visualscripting": {
"version": "1.7.8",
"version": "1.8.0",
"depth": 0,
"source": "registry",
"dependencies": {
Expand Down
8 changes: 5 additions & 3 deletions ProjectSettings/PackageManagerSettings.asset
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,20 @@ MonoBehaviour:
m_Scopes: []
m_IsDefault: 1
m_Capabilities: 7
- m_Id: scoped:NatML
m_ConfigSource: 0
- m_Id: scoped:project:NatML
m_Name: NatML
m_Url: https://registry.npmjs.com
m_Scopes:
- ai.natml
m_IsDefault: 0
m_Capabilities: 0
m_ConfigSource: 4
m_UserSelectedRegistryName: NatML
m_UserAddingNewScopedRegistry: 0
m_RegistryInfoDraft:
m_Modified: 0
m_ErrorMessage:
m_UserModificationsInstanceId: -828
m_OriginalInstanceId: -830
m_UserModificationsInstanceId: -846
m_OriginalInstanceId: -850
m_LoadAssets: 0
4 changes: 2 additions & 2 deletions ProjectSettings/ProjectVersion.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
m_EditorVersion: 2021.3.4f1
m_EditorVersionWithRevision: 2021.3.4f1 (cb45f9cae8b7)
m_EditorVersion: 2021.3.17f1
m_EditorVersionWithRevision: 2021.3.17f1 (3e8111cac19d)
Loading

0 comments on commit 3312d62

Please sign in to comment.