Project import generated by Copybara.
GitOrigin-RevId: 777962478d88650e311af635e3ac3fa58e5a530b
This commit is contained in:
parent
06c30f1931
commit
b65602fd31
|
@ -298,6 +298,7 @@ cc_library(
|
||||||
hdrs = ["inference_calculator_utils.h"],
|
hdrs = ["inference_calculator_utils.h"],
|
||||||
deps = [
|
deps = [
|
||||||
":inference_calculator_cc_proto",
|
":inference_calculator_cc_proto",
|
||||||
|
"//mediapipe/framework:port",
|
||||||
] + select({
|
] + select({
|
||||||
"//conditions:default": [
|
"//conditions:default": [
|
||||||
"//mediapipe/util:cpu_util",
|
"//mediapipe/util:cpu_util",
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
#include "mediapipe/calculators/tensor/inference_calculator_utils.h"
|
#include "mediapipe/calculators/tensor/inference_calculator_utils.h"
|
||||||
|
|
||||||
#include "mediapipe/calculators/tensor/inference_calculator.pb.h"
|
#include "mediapipe/calculators/tensor/inference_calculator.pb.h"
|
||||||
|
#include "mediapipe/framework/port.h" // NOLINT: provides MEDIAPIPE_ANDROID/IOS
|
||||||
|
|
||||||
#if !defined(__EMSCRIPTEN__) || defined(__EMSCRIPTEN_PTHREADS__)
|
#if !defined(__EMSCRIPTEN__) || defined(__EMSCRIPTEN_PTHREADS__)
|
||||||
#include "mediapipe/util/cpu_util.h"
|
#include "mediapipe/util/cpu_util.h"
|
||||||
|
|
|
@ -324,6 +324,63 @@ TEST(BuilderTest, GraphIndexes) {
|
||||||
EXPECT_THAT(graph.GetConfig(), EqualsProto(expected));
|
EXPECT_THAT(graph.GetConfig(), EqualsProto(expected));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class AnyAndSameTypeCalculator : public NodeIntf {
|
||||||
|
public:
|
||||||
|
static constexpr Input<AnyType> kAnyTypeInput{"INPUT"};
|
||||||
|
static constexpr Output<AnyType> kAnyTypeOutput{"ANY_OUTPUT"};
|
||||||
|
static constexpr Output<SameType<kAnyTypeInput>> kSameTypeOutput{
|
||||||
|
"SAME_OUTPUT"};
|
||||||
|
|
||||||
|
static constexpr Input<int> kIntInput{"INT_INPUT"};
|
||||||
|
// `SameType` usage for this output is only for testing purposes.
|
||||||
|
//
|
||||||
|
// `SameType` is designed to work with inputs of `AnyType` and, normally, you
|
||||||
|
// would not use `Output<SameType<kIntInput>>` in a real calculator. You
|
||||||
|
// should write `Output<int>` instead, since the type is known.
|
||||||
|
static constexpr Output<SameType<kIntInput>> kSameIntOutput{
|
||||||
|
"SAME_INT_OUTPUT"};
|
||||||
|
|
||||||
|
MEDIAPIPE_NODE_INTERFACE(AnyTypeCalculator, kAnyTypeInput, kAnyTypeOutput,
|
||||||
|
kSameTypeOutput);
|
||||||
|
};
|
||||||
|
|
||||||
|
TEST(BuilderTest, AnyAndSameTypeHandledProperly) {
|
||||||
|
builder::Graph graph;
|
||||||
|
builder::Source<internal::Generic> any_input =
|
||||||
|
graph[Input<AnyType>{"GRAPH_ANY_INPUT"}];
|
||||||
|
builder::Source<int> int_input = graph[Input<int>{"GRAPH_INT_INPUT"}];
|
||||||
|
|
||||||
|
auto& node = graph.AddNode("AnyAndSameTypeCalculator");
|
||||||
|
any_input >> node[AnyAndSameTypeCalculator::kAnyTypeInput];
|
||||||
|
int_input >> node[AnyAndSameTypeCalculator::kIntInput];
|
||||||
|
|
||||||
|
builder::Source<internal::Generic> any_type_output =
|
||||||
|
node[AnyAndSameTypeCalculator::kAnyTypeOutput];
|
||||||
|
any_type_output.SetName("any_type_output");
|
||||||
|
|
||||||
|
builder::Source<internal::Generic> same_type_output =
|
||||||
|
node[AnyAndSameTypeCalculator::kSameTypeOutput];
|
||||||
|
same_type_output.SetName("same_type_output");
|
||||||
|
builder::Source<internal::Generic> same_int_output =
|
||||||
|
node[AnyAndSameTypeCalculator::kSameIntOutput];
|
||||||
|
same_int_output.SetName("same_int_output");
|
||||||
|
|
||||||
|
CalculatorGraphConfig expected =
|
||||||
|
mediapipe::ParseTextProtoOrDie<CalculatorGraphConfig>(R"pb(
|
||||||
|
node {
|
||||||
|
calculator: "AnyAndSameTypeCalculator"
|
||||||
|
input_stream: "INPUT:__stream_0"
|
||||||
|
input_stream: "INT_INPUT:__stream_1"
|
||||||
|
output_stream: "ANY_OUTPUT:any_type_output"
|
||||||
|
output_stream: "SAME_INT_OUTPUT:same_int_output"
|
||||||
|
output_stream: "SAME_OUTPUT:same_type_output"
|
||||||
|
}
|
||||||
|
input_stream: "GRAPH_ANY_INPUT:__stream_0"
|
||||||
|
input_stream: "GRAPH_INT_INPUT:__stream_1"
|
||||||
|
)pb");
|
||||||
|
EXPECT_THAT(graph.GetConfig(), EqualsProto(expected));
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace test
|
} // namespace test
|
||||||
} // namespace api2
|
} // namespace api2
|
||||||
} // namespace mediapipe
|
} // namespace mediapipe
|
||||||
|
|
|
@ -27,6 +27,12 @@ using HolderBase = mediapipe::packet_internal::HolderBase;
|
||||||
template <typename T>
|
template <typename T>
|
||||||
class Packet;
|
class Packet;
|
||||||
|
|
||||||
|
struct DynamicType {};
|
||||||
|
|
||||||
|
struct AnyType : public DynamicType {
|
||||||
|
AnyType() = delete;
|
||||||
|
};
|
||||||
|
|
||||||
// Type-erased packet.
|
// Type-erased packet.
|
||||||
class PacketBase {
|
class PacketBase {
|
||||||
public:
|
public:
|
||||||
|
@ -148,9 +154,8 @@ inline void CheckCompatibleType(const HolderBase& holder,
|
||||||
<< " was requested.";
|
<< " was requested.";
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Generic {
|
// TODO: remove usage of internal::Generic and simply use AnyType.
|
||||||
Generic() = delete;
|
using Generic = ::mediapipe::api2::AnyType;
|
||||||
};
|
|
||||||
|
|
||||||
template <class V, class U>
|
template <class V, class U>
|
||||||
struct IsCompatibleType : std::false_type {};
|
struct IsCompatibleType : std::false_type {};
|
||||||
|
|
|
@ -77,10 +77,6 @@ struct NoneType {
|
||||||
NoneType() = delete;
|
NoneType() = delete;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct DynamicType {};
|
|
||||||
|
|
||||||
struct AnyType : public DynamicType {};
|
|
||||||
|
|
||||||
template <auto& P>
|
template <auto& P>
|
||||||
class SameType : public DynamicType {
|
class SameType : public DynamicType {
|
||||||
public:
|
public:
|
||||||
|
|
|
@ -23,7 +23,7 @@
|
||||||
@property(nonatomic, getter=isAuthorized, readonly) BOOL authorized;
|
@property(nonatomic, getter=isAuthorized, readonly) BOOL authorized;
|
||||||
|
|
||||||
/// Session preset to use for capturing.
|
/// Session preset to use for capturing.
|
||||||
@property(nonatomic) NSString *sessionPreset;
|
@property(nonatomic, nullable) NSString *sessionPreset;
|
||||||
|
|
||||||
/// Which camera on an iOS device to use, assuming iOS device with more than one camera.
|
/// Which camera on an iOS device to use, assuming iOS device with more than one camera.
|
||||||
@property(nonatomic) AVCaptureDevicePosition cameraPosition;
|
@property(nonatomic) AVCaptureDevicePosition cameraPosition;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user