Skip to content

Commit

Permalink
feat(sdk): implement path resolver for unity
Browse files Browse the repository at this point in the history
  • Loading branch information
homuler committed Oct 10, 2020
1 parent 81ff269 commit 468d444
Show file tree
Hide file tree
Showing 20 changed files with 207 additions and 766 deletions.
4 changes: 1 addition & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ obj/

bazel-*

Assets/MediaPipe/SDK/Models/*
!Assets/MediaPipe/SDK/Models/.gitkeep
Assets/StreamingAssets*
Assets/MediaPipe/SDK/Plugins/Protobuf*

Assets/MediaPipe/SDK/Scripts/Protobuf/**/*.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ node {
output_stream: "TENSORS:detection_tensors"
node_options: {
[type.googleapis.com/mediapipe.TfLiteInferenceCalculatorOptions] {
model_path: "Assets/MediaPipe/SDK/Models/face_detection_front.tflite"
model_path: "mediapipe/models/face_detection_front.tflite"
}
}
}
Expand Down Expand Up @@ -154,7 +154,7 @@ node {
output_stream: "labeled_detections"
node_options: {
[type.googleapis.com/mediapipe.DetectionLabelIdToTextCalculatorOptions] {
label_map_path: "Assets/MediaPipe/SDK/Models/face_detection_front_labelmap.txt"
label_map_path: "mediapipe/models/face_detection_front_labelmap.txt"
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ node {
output_stream: "TENSORS_GPU:detection_tensors"
node_options: {
[type.googleapis.com/mediapipe.TfLiteInferenceCalculatorOptions] {
model_path: "Assets/MediaPipe/SDK/Models/face_detection_front.tflite"
model_path: "mediapipe/models/face_detection_front.tflite"
}
}
}
Expand Down Expand Up @@ -154,7 +154,7 @@ node {
output_stream: "labeled_detections"
node_options: {
[type.googleapis.com/mediapipe.DetectionLabelIdToTextCalculatorOptions] {
label_map_path: "Assets/MediaPipe/SDK/Models/face_detection_front_labelmap.txt"
label_map_path: "mediapipe/models/face_detection_front_labelmap.txt"
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ node {
input_side_packet: "CUSTOM_OP_RESOLVER:op_resolver"
node_options: {
[type.googleapis.com/mediapipe.TfLiteInferenceCalculatorOptions] {
model_path: "Assets/MediaPipe/SDK/Models/hair_segmentation.tflite"
model_path: "mediapipe/models/hair_segmentation.tflite"
use_gpu: true
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ node {
output_stream: "TENSORS:detection_tensors"
node_options: {
[type.googleapis.com/mediapipe.TfLiteInferenceCalculatorOptions] {
model_path: "Assets/MediaPipe/SDK/Models/ssdlite_object_detection.tflite"
model_path: "mediapipe/models/ssdlite_object_detection.tflite"
}
}
}
Expand Down Expand Up @@ -160,7 +160,7 @@ node {
output_stream: "output_detections"
node_options: {
[type.googleapis.com/mediapipe.DetectionLabelIdToTextCalculatorOptions] {
label_map_path: "Assets/MediaPipe/SDK/Models/ssdlite_object_detection_labelmap.txt"
label_map_path: "mediapipe/models/ssdlite_object_detection_labelmap.txt"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ node {
output_stream: "TENSORS_GPU:detection_tensors"
node_options: {
[type.googleapis.com/mediapipe.TfLiteInferenceCalculatorOptions] {
model_path: "Assets/MediaPipe/SDK/Models/ssdlite_object_detection.tflite"
model_path: "mediapipe/models/ssdlite_object_detection.tflite"
}
}
}
Expand Down Expand Up @@ -161,7 +161,7 @@ node {
output_stream: "output_detections"
node_options: {
[type.googleapis.com/mediapipe.DetectionLabelIdToTextCalculatorOptions] {
label_map_path: "Assets/MediaPipe/SDK/Models/ssdlite_object_detection_labelmap.txt"
label_map_path: "mediapipe/models/ssdlite_object_detection_labelmap.txt"
}
}
}
1 change: 1 addition & 0 deletions Assets/MediaPipe/Examples/Scripts/SceneDirector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public class SceneDirector : MonoBehaviour {
}

UnsafeNativeMethods.InitGoogleLogging(nameForGlog, logDir);
ResourceUtil.SetResourceRootPath(Application.streamingAssetsPath);
}

void Start() {
Expand Down
8 changes: 0 additions & 8 deletions Assets/MediaPipe/SDK/Models.meta

This file was deleted.

Empty file.
7 changes: 7 additions & 0 deletions Assets/MediaPipe/SDK/Scripts/ResourceUtil.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Mediapipe {
public class ResourceUtil {
public static void SetResourceRootPath(string path) {
UnsafeNativeMethods.MpSetResourceRootPath(path);
}
}
}
11 changes: 11 additions & 0 deletions Assets/MediaPipe/SDK/Scripts/ResourceUtil.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions Assets/MediaPipe/SDK/Scripts/UnsafeNativeMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,11 @@ internal static class UnsafeNativeMethods {
public static extern unsafe MpNormalizedRectVector MpPacketGetNormalizedRectVector(MpPacket packet);


/// Resource Util API
[DllImport (MediaPipeLibrary)]
public static extern unsafe void MpSetResourceRootPath(string path);


/// SidePacket API

[DllImport (MediaPipeLibrary)]
Expand Down
1 change: 1 addition & 0 deletions C/mediapipe_api/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ cc_library(
"//mediapipe_api/framework/formats:landmark",
"//mediapipe_api/framework/formats:rect",
"//mediapipe_api/framework/port:logging",
"//mediapipe_api/util:resource_util",
] + select({
"@com_google_mediapipe//mediapipe/gpu:disable_gpu": [],
"//conditions:default": [
Expand Down
11 changes: 11 additions & 0 deletions C/mediapipe_api/util/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
cc_library(
name = "resource_util",
srcs = ["resource_util.cc"],
hdrs = ["resource_util.h"],
deps = [
"@com_google_mediapipe//mediapipe/util:resource_util",
"//mediapipe_api:common",
],
visibility = ["//visibility:public"],
alwayslink = True,
)
6 changes: 6 additions & 0 deletions C/mediapipe_api/util/resource_util.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include <string>
#include "mediapipe_api/util/resource_util.h"

void MpSetResourceRootPath(const char* path) {
mediapipe::SetResourceRootPath(std::string(path));
}
13 changes: 13 additions & 0 deletions C/mediapipe_api/util/resource_util.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#ifndef C_MEDIAPIPE_API_UTIL_RESOURCE_UTIL_H_
#define C_MEDIAPIPE_API_UTIL_RESOURCE_UTIL_H_

#include "mediapipe/util/resource_util.h"
#include "mediapipe_api/common.h"

extern "C" {

MP_CAPI_EXPORT extern void MpSetResourceRootPath(const char* path);

} // extern "C"

#endif // C_MEDIAPIPE_API_UTIL_RESOURCE_UTIL_H_
Loading

0 comments on commit 468d444

Please sign in to comment.