UnityPaul commited on
Commit
6949f00
1 Parent(s): c08911a

Upload 3 files

Browse files
Files changed (3) hide show
  1. README.md +2 -2
  2. RunFaceLandmark.cs +4 -12
  3. face_landmark.sentis +2 -2
README.md CHANGED
@@ -4,7 +4,7 @@ license: apache-2.0
4
  library_name: unity-sentis
5
  ---
6
 
7
- # Face Landmark from Google Mediapipe validated for Unity Sentis (Version 1.3.0-pre.3*)
8
  *Version 1.3.0 Sentis files are not compatible with Sentis 1.4.0 and need to be recreated/downloaded
9
 
10
  This is the [Face Landmark model](https://developers.google.com/mediapipe/solutions/vision/face_landmarker) from Google in the Sentis format.
@@ -16,7 +16,7 @@ The model detects 468 3D markers on a face centered in an image. You could use t
16
  ## How to Use
17
  * Create a new scene in Unity 2023
18
  * Put the face_landmark.sentis file in the `Assets/StreamingAssets` folder
19
- * Install package `com.unity.sentis` version `1.3.0-pre.3` from the package manager
20
  * Put a video in the `Assets/StreamingAssets` folder and set `videoName` variable to the video name
21
  * Create a RawImage and place it in your scene. Link to this image in the `previewUI` field.
22
 
 
4
  library_name: unity-sentis
5
  ---
6
 
7
+ # Face Landmark from Google Mediapipe validated for Unity Sentis (Version 1.4.0-pre.2*)
8
  *Version 1.3.0 Sentis files are not compatible with Sentis 1.4.0 and need to be recreated/downloaded
9
 
10
  This is the [Face Landmark model](https://developers.google.com/mediapipe/solutions/vision/face_landmarker) from Google in the Sentis format.
 
16
  ## How to Use
17
  * Create a new scene in Unity 2023
18
  * Put the face_landmark.sentis file in the `Assets/StreamingAssets` folder
19
+ * Install package `com.unity.sentis` version `1.4.0-pre.2` from the package manager
20
  * Put a video in the `Assets/StreamingAssets` folder and set `videoName` variable to the video name
21
  * Create a RawImage and place it in your scene. Link to this image in the `previewUI` field.
22
 
RunFaceLandmark.cs CHANGED
@@ -53,8 +53,6 @@ public class RunFaceLandmark : MonoBehaviour
53
  //Size of input image to neural network (196)
54
  const int size = 192;
55
 
56
- Ops ops;
57
- ITensorAllocator allocator;
58
 
59
  Model model;
60
 
@@ -67,8 +65,6 @@ public class RunFaceLandmark : MonoBehaviour
67
 
68
  void Start()
69
  {
70
- allocator = new TensorCachingAllocator();
71
-
72
  //(Note: if using a webcam on mobile get permissions here first)
73
 
74
  SetupTextures();
@@ -85,7 +81,6 @@ public class RunFaceLandmark : MonoBehaviour
85
  public void SetupEngine()
86
  {
87
  worker = WorkerFactory.CreateWorker(backend, model);
88
- ops = WorkerFactory.CreateOps(backend, allocator);
89
  }
90
 
91
  void SetupTextures()
@@ -202,12 +197,11 @@ public class RunFaceLandmark : MonoBehaviour
202
  var transform = new TextureTransform();
203
  transform.SetDimensions(size, size, 3);
204
  transform.SetTensorLayout(0, 3, 1, 2);
205
- using var image0 = TextureConverter.ToTensor(source, transform);
206
 
207
- // Pre-process the image to make input in range (-1..1)
208
- using var image = ops.Mad(image0, 2f, -1f);
209
 
210
- worker.Execute(image0);
211
 
212
  using var landmarks= worker.PeekOutput("conv2d_21") as TensorFloat;
213
 
@@ -217,7 +211,7 @@ public class RunFaceLandmark : MonoBehaviour
217
  float scaleX = targetTexture.width * 1f / size;
218
  float scaleY = targetTexture.height * 1f / size;
219
 
220
- landmarks.MakeReadable();
221
  DrawLandmarks(landmarks, scaleX, scaleY);
222
  }
223
 
@@ -245,8 +239,6 @@ public class RunFaceLandmark : MonoBehaviour
245
  void CleanUp()
246
  {
247
  closing = true;
248
- ops?.Dispose();
249
- allocator?.Dispose();
250
  if (webcam) Destroy(webcam);
251
  if (video) Destroy(video);
252
  RenderTexture.active = null;
 
53
  //Size of input image to neural network (196)
54
  const int size = 192;
55
 
 
 
56
 
57
  Model model;
58
 
 
65
 
66
  void Start()
67
  {
 
 
68
  //(Note: if using a webcam on mobile get permissions here first)
69
 
70
  SetupTextures();
 
81
  public void SetupEngine()
82
  {
83
  worker = WorkerFactory.CreateWorker(backend, model);
 
84
  }
85
 
86
  void SetupTextures()
 
197
  var transform = new TextureTransform();
198
  transform.SetDimensions(size, size, 3);
199
  transform.SetTensorLayout(0, 3, 1, 2);
200
+ using var image = TextureConverter.ToTensor(source, transform);
201
 
202
+ // The image has pixels in the range [0..1]
 
203
 
204
+ worker.Execute(image);
205
 
206
  using var landmarks= worker.PeekOutput("conv2d_21") as TensorFloat;
207
 
 
211
  float scaleX = targetTexture.width * 1f / size;
212
  float scaleY = targetTexture.height * 1f / size;
213
 
214
+ landmarks.CompleteOperationsAndDownload();
215
  DrawLandmarks(landmarks, scaleX, scaleY);
216
  }
217
 
 
239
  void CleanUp()
240
  {
241
  closing = true;
 
 
242
  if (webcam) Destroy(webcam);
243
  if (video) Destroy(video);
244
  RenderTexture.active = null;
face_landmark.sentis CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:fe79525320811b1b997fc09ffa290e488b70c454d1178238955302a93f67865f
3
- size 2488087
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:091bea3c3863cd029b5a180707c7add67112fc9f79d177849686ac984a9c5f5f
3
+ size 2449056