-
-
Notifications
You must be signed in to change notification settings - Fork 450
Commit
* feat: import protos from mediapipe.tasks.core.proto * feat: add Vision.RunningMode * refactor: rename the asmdef for tests * build: test code can access internal properties * feat: implement BaseOptions
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// Copyright (c) 2023 homuler | ||
// | ||
// Use of this source code is governed by an MIT-style | ||
// license that can be found in the LICENSE file or at | ||
// https://opensource.org/licenses/MIT. | ||
|
||
using System.Runtime.CompilerServices; | ||
|
||
[assembly: InternalsVisibleTo("Mediapipe.Tests.EditMode")] |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
// Copyright (c) 2023 homuler | ||
// | ||
// Use of this source code is governed by an MIT-style | ||
// license that can be found in the LICENSE file or at | ||
// https://opensource.org/licenses/MIT. | ||
|
||
namespace Mediapipe.Tasks.Core | ||
{ | ||
public sealed class BaseOptions | ||
{ | ||
public enum Delegate | ||
{ | ||
CPU, | ||
GPU, | ||
} | ||
|
||
public Delegate delegateCase { get; } = Delegate.CPU; | ||
public string modelAssetPath { get; } = string.Empty; | ||
public byte[] modelAssetBuffer { get; } = null; | ||
|
||
public BaseOptions(Delegate delegateCase = Delegate.CPU, string modelAssetPath = "", byte[] modelAssetBuffer = null) | ||
{ | ||
this.delegateCase = delegateCase; | ||
this.modelAssetPath = modelAssetPath; | ||
this.modelAssetBuffer = modelAssetBuffer; | ||
} | ||
|
||
private Proto.Acceleration acceleration | ||
{ | ||
get | ||
{ | ||
switch (delegateCase) | ||
{ | ||
case Delegate.CPU: | ||
return new Proto.Acceleration | ||
{ | ||
Tflite = new InferenceCalculatorOptions.Types.Delegate.Types.TfLite { }, | ||
}; | ||
case Delegate.GPU: | ||
return new Proto.Acceleration | ||
{ | ||
Gpu = new InferenceCalculatorOptions.Types.Delegate.Types.Gpu { }, | ||
}; | ||
default: | ||
return null; | ||
} | ||
} | ||
} | ||
|
||
private Proto.ExternalFile modelAsset | ||
{ | ||
get | ||
{ | ||
var file = new Proto.ExternalFile { }; | ||
|
||
if (modelAssetPath != null) | ||
{ | ||
file.FileName = modelAssetPath; | ||
} | ||
if (modelAssetBuffer != null) | ||
{ | ||
file.FileContent = Google.Protobuf.ByteString.CopyFrom(modelAssetBuffer); | ||
} | ||
|
||
return file; | ||
} | ||
} | ||
|
||
internal Proto.BaseOptions ToProto() | ||
{ | ||
return new Proto.BaseOptions | ||
{ | ||
ModelAsset = modelAsset, | ||
Acceleration = acceleration, | ||
}; | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// Copyright (c) 2023 homuler | ||
// | ||
// Use of this source code is governed by an MIT-style | ||
// license that can be found in the LICENSE file or at | ||
// https://opensource.org/licenses/MIT. | ||
|
||
namespace Mediapipe.Tasks.Vision.Core | ||
{ | ||
public enum RunningMode | ||
{ | ||
IMAGE, | ||
VIDEO, | ||
LIVE_STREAM, | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// Copyright (c) 2023 homuler | ||
// | ||
// Use of this source code is governed by an MIT-style | ||
// license that can be found in the LICENSE file or at | ||
// https://opensource.org/licenses/MIT. | ||
|
||
using Mediapipe.Tasks.Core; | ||
using NUnit.Framework; | ||
|
||
namespace Mediapipe.Tests.Tasks.Core | ||
{ | ||
public class BaseOptionsTest | ||
{ | ||
#region ToProto | ||
[TestCase(BaseOptions.Delegate.CPU, Mediapipe.Tasks.Core.Proto.Acceleration.DelegateOneofCase.Tflite)] | ||
[TestCase(BaseOptions.Delegate.GPU, Mediapipe.Tasks.Core.Proto.Acceleration.DelegateOneofCase.Gpu)] | ||
public void ToProto_ShouldSetDelegateCase(BaseOptions.Delegate delegateCase, Mediapipe.Tasks.Core.Proto.Acceleration.DelegateOneofCase delegateOneofCase) | ||
{ | ||
var options = new BaseOptions(delegateCase: delegateCase); | ||
var proto = options.ToProto(); | ||
Assert.AreEqual(delegateOneofCase, proto.Acceleration.DelegateCase); | ||
} | ||
|
||
[Test] | ||
public void ToProto_ShouldSetModelAsset_When_ModelAssetPathIsSet() | ||
{ | ||
var path = "asset/path"; | ||
var options = new BaseOptions(modelAssetPath: path); | ||
var proto = options.ToProto(); | ||
Assert.AreEqual(path, proto.ModelAsset.FileName); | ||
} | ||
|
||
[Test] | ||
public void ToProto_ShouldSetModelAsset_When_ModelAssetBufferIsSet() | ||
{ | ||
var contents = new byte[] { 1, 2, 3 }; | ||
var options = new BaseOptions(modelAssetBuffer: contents); | ||
var proto = options.ToProto(); | ||
Assert.AreEqual(contents, proto.ModelAsset.FileContent.ToByteArray()); | ||
} | ||
#endregion | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# Copyright (c) 2021 homuler | ||
# | ||
# Use of this source code is governed by an MIT-style | ||
# license that can be found in the LICENSE file or at | ||
# https://opensource.org/licenses/MIT. | ||
|
||
load("@rules_pkg//pkg:mappings.bzl", "pkg_files") | ||
load("//mediapipe_api:csharp_proto_src.bzl", "csharp_proto_src") | ||
|
||
package(default_visibility = ["//visibility:public"]) | ||
|
||
pkg_files( | ||
name = "proto_srcs", | ||
srcs = [ | ||
":base_options_cs", | ||
":external_file_cs", | ||
":acceleration_cs", | ||
], | ||
prefix = "Tasks/Core/Proto", | ||
) | ||
|
||
csharp_proto_src( | ||
name = "base_options_cs", | ||
proto_src = "mediapipe/tasks/cc/core/proto/base_options.proto", | ||
deps = [ | ||
"@com_google_mediapipe//mediapipe/calculators/tensor:protos_src", | ||
"@com_google_mediapipe//mediapipe/framework:protos_src", | ||
"@com_google_mediapipe//mediapipe/tasks/cc/core/proto:protos_src", | ||
], | ||
) | ||
|
||
csharp_proto_src( | ||
name = "external_file_cs", | ||
proto_src = "mediapipe/tasks/cc/core/proto/external_file.proto", | ||
deps = [ | ||
"@com_google_mediapipe//mediapipe/calculators/tensor:protos_src", | ||
"@com_google_mediapipe//mediapipe/framework:protos_src", | ||
"@com_google_mediapipe//mediapipe/tasks/cc/core/proto:protos_src", | ||
], | ||
) | ||
|
||
csharp_proto_src( | ||
name = "acceleration_cs", | ||
proto_src = "mediapipe/tasks/cc/core/proto/acceleration.proto", | ||
deps = [ | ||
"@com_google_mediapipe//mediapipe/calculators/tensor:protos_src", | ||
"@com_google_mediapipe//mediapipe/framework:protos_src", | ||
"@com_google_mediapipe//mediapipe/tasks/cc/core/proto:protos_src", | ||
], | ||
) |