Project import generated by Copybara.
GitOrigin-RevId: 6e4aff1cc351be3ae4537b677f36d139ee50ce09
This commit is contained in:
+37
-33
@@ -13,6 +13,7 @@
|
||||
# limitations under the License.
|
||||
#
|
||||
load("//mediapipe/framework/port:build_config.bzl", "mediapipe_proto_library")
|
||||
load("//mediapipe/framework:mediapipe_cc_test.bzl", "mediapipe_cc_test")
|
||||
|
||||
licenses(["notice"])
|
||||
|
||||
@@ -45,7 +46,7 @@ cc_library(
|
||||
name = "audio_decoder",
|
||||
srcs = ["audio_decoder.cc"],
|
||||
hdrs = ["audio_decoder.h"],
|
||||
visibility = ["//mediapipe:__subpackages__"],
|
||||
visibility = ["//visibility:public"],
|
||||
deps = [
|
||||
":audio_decoder_cc_proto",
|
||||
"//mediapipe/framework:packet",
|
||||
@@ -53,7 +54,6 @@ cc_library(
|
||||
"//mediapipe/framework/deps:cleanup",
|
||||
"//mediapipe/framework/formats:matrix",
|
||||
"//mediapipe/framework/formats:time_series_header_cc_proto",
|
||||
"//mediapipe/framework/port:commandlineflags",
|
||||
"//mediapipe/framework/port:integral_types",
|
||||
"//mediapipe/framework/port:map_util",
|
||||
"//mediapipe/framework/port:ret_check",
|
||||
@@ -61,9 +61,10 @@ cc_library(
|
||||
"//mediapipe/framework/tool:status_util",
|
||||
"//third_party:libffmpeg",
|
||||
"@com_google_absl//absl/base:endian",
|
||||
"@com_google_absl//absl/flags:flag",
|
||||
"@com_google_absl//absl/strings",
|
||||
"@com_google_absl//absl/time",
|
||||
"@eigen_archive//:eigen",
|
||||
"@eigen_archive//:eigen3",
|
||||
],
|
||||
)
|
||||
|
||||
@@ -71,11 +72,10 @@ cc_library(
|
||||
name = "cpu_util",
|
||||
srcs = ["cpu_util.cc"],
|
||||
hdrs = ["cpu_util.h"],
|
||||
visibility = [
|
||||
"//mediapipe/framework:mediapipe_internal",
|
||||
],
|
||||
visibility = ["//visibility:public"],
|
||||
deps = [
|
||||
"@com_google_absl//absl/algorithm:container",
|
||||
"@com_google_absl//absl/flags:flag",
|
||||
"@com_google_absl//absl/strings",
|
||||
"//mediapipe/framework/port:integral_types",
|
||||
"//mediapipe/framework/port:status",
|
||||
@@ -92,9 +92,7 @@ cc_library(
|
||||
name = "header_util",
|
||||
srcs = ["header_util.cc"],
|
||||
hdrs = ["header_util.h"],
|
||||
visibility = [
|
||||
"//mediapipe/framework:mediapipe_internal",
|
||||
],
|
||||
visibility = ["//visibility:public"],
|
||||
deps = [
|
||||
"//mediapipe/framework:calculator_framework",
|
||||
"//mediapipe/framework:packet_set",
|
||||
@@ -107,9 +105,7 @@ cc_library(
|
||||
name = "image_frame_util",
|
||||
srcs = ["image_frame_util.cc"],
|
||||
hdrs = ["image_frame_util.h"],
|
||||
visibility = [
|
||||
"//visibility:public",
|
||||
],
|
||||
visibility = ["//visibility:public"],
|
||||
deps = [
|
||||
"//mediapipe/framework/deps:mathutil",
|
||||
"//mediapipe/framework/formats:image_format_cc_proto",
|
||||
@@ -132,9 +128,7 @@ cc_library(
|
||||
name = "annotation_renderer",
|
||||
srcs = ["annotation_renderer.cc"],
|
||||
hdrs = ["annotation_renderer.h"],
|
||||
visibility = [
|
||||
"//visibility:public",
|
||||
],
|
||||
visibility = ["//visibility:public"],
|
||||
deps = [
|
||||
":render_data_cc_proto",
|
||||
"//mediapipe/framework/port:logging",
|
||||
@@ -145,15 +139,31 @@ cc_library(
|
||||
],
|
||||
)
|
||||
|
||||
# Prefer to use ":resource_util", Customization of the resource util is being restricted
|
||||
# while we explore how it should best be implemented.
|
||||
cc_library(
|
||||
name = "resource_util_custom",
|
||||
hdrs = ["resource_util_custom.h"],
|
||||
visibility = ["//visibility:public"],
|
||||
deps = [
|
||||
"//mediapipe/framework/port:status",
|
||||
],
|
||||
)
|
||||
|
||||
cc_library(
|
||||
name = "resource_util",
|
||||
srcs = select({
|
||||
"//conditions:default": ["resource_util.cc"],
|
||||
srcs = [
|
||||
"resource_util.cc",
|
||||
"resource_util_internal.h",
|
||||
] + select({
|
||||
"//conditions:default": ["resource_util_default.cc"],
|
||||
"//mediapipe:android": ["resource_util_android.cc"],
|
||||
"//mediapipe:ios": ["resource_util_apple.cc"],
|
||||
"//mediapipe:macos": ["resource_util.cc"],
|
||||
"//mediapipe:macos": ["resource_util_default.cc"],
|
||||
}),
|
||||
hdrs = ["resource_util.h"],
|
||||
hdrs = [
|
||||
"resource_util.h",
|
||||
],
|
||||
# We use Objective-C++ on iOS.
|
||||
copts = select({
|
||||
"//conditions:default": [],
|
||||
@@ -162,10 +172,10 @@ cc_library(
|
||||
],
|
||||
"//mediapipe:macos": [],
|
||||
}),
|
||||
visibility = [
|
||||
"//mediapipe/framework:mediapipe_internal",
|
||||
],
|
||||
visibility = ["//visibility:public"],
|
||||
deps = [
|
||||
":resource_util_custom",
|
||||
"@com_google_absl//absl/container:flat_hash_map",
|
||||
"//mediapipe/framework/port:ret_check",
|
||||
"//mediapipe/framework/port:singleton",
|
||||
"//mediapipe/framework/port:status",
|
||||
@@ -197,9 +207,7 @@ cc_library(
|
||||
# Layering check doesn't play nicely with portable proto wrappers.
|
||||
"no_layering_check",
|
||||
],
|
||||
visibility = [
|
||||
"//visibility:public",
|
||||
],
|
||||
visibility = ["//visibility:public"],
|
||||
deps = [
|
||||
"//mediapipe/framework/formats:detection_cc_proto",
|
||||
"//mediapipe/framework/formats:location",
|
||||
@@ -221,9 +229,7 @@ cc_library(
|
||||
name = "time_series_util",
|
||||
srcs = ["time_series_util.cc"],
|
||||
hdrs = ["time_series_util.h"],
|
||||
visibility = [
|
||||
"//visibility:public",
|
||||
],
|
||||
visibility = ["//visibility:public"],
|
||||
deps = [
|
||||
"//mediapipe/framework:calculator_framework",
|
||||
"//mediapipe/framework/formats:matrix",
|
||||
@@ -239,9 +245,7 @@ cc_library(
|
||||
name = "time_series_test_util",
|
||||
testonly = 1,
|
||||
hdrs = ["time_series_test_util.h"],
|
||||
visibility = [
|
||||
"//visibility:public",
|
||||
],
|
||||
visibility = ["//visibility:public"],
|
||||
deps = [
|
||||
":time_series_util",
|
||||
"//mediapipe/framework:calculator_framework",
|
||||
@@ -255,7 +259,7 @@ cc_library(
|
||||
"//mediapipe/framework/port:parse_text_proto",
|
||||
"//mediapipe/framework/port:status",
|
||||
"@com_google_absl//absl/strings",
|
||||
"@eigen_archive//:eigen",
|
||||
"@eigen_archive//:eigen3",
|
||||
],
|
||||
)
|
||||
|
||||
@@ -269,6 +273,6 @@ cc_test(
|
||||
"//mediapipe/framework/deps:message_matchers",
|
||||
"//mediapipe/framework/formats:time_series_header_cc_proto",
|
||||
"//mediapipe/framework/port:gtest_main",
|
||||
"@eigen_archive//:eigen",
|
||||
"@eigen_archive//:eigen3",
|
||||
],
|
||||
)
|
||||
|
||||
@@ -41,14 +41,14 @@ extern "C" {
|
||||
#include "libavutil/samplefmt.h"
|
||||
}
|
||||
|
||||
DEFINE_int64(media_decoder_allowed_audio_gap_merge, 5,
|
||||
"The time gap forwards or backwards in the audio to ignore. "
|
||||
"Timestamps in media files are restricted by the container format "
|
||||
"and stream codec and are invariably not accurate to exact sample "
|
||||
"numbers. If the discrepency between time based on counting "
|
||||
"samples and based on the container timestamps grows beyond this "
|
||||
"value it will be reset to the value in the audio stream and "
|
||||
"counting based on samples will resume.");
|
||||
ABSL_FLAG(int64_t, media_decoder_allowed_audio_gap_merge, 5,
|
||||
"The time gap forwards or backwards in the audio to ignore. "
|
||||
"Timestamps in media files are restricted by the container format "
|
||||
"and stream codec and are invariably not accurate to exact sample "
|
||||
"numbers. If the discrepency between time based on counting "
|
||||
"samples and based on the container timestamps grows beyond this "
|
||||
"value it will be reset to the value in the audio stream and "
|
||||
"counting based on samples will resume.");
|
||||
|
||||
namespace mediapipe {
|
||||
|
||||
|
||||
@@ -20,10 +20,10 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "absl/flags/flag.h"
|
||||
#include "absl/time/time.h"
|
||||
#include "mediapipe/framework/formats/time_series_header.pb.h"
|
||||
#include "mediapipe/framework/packet.h"
|
||||
#include "mediapipe/framework/port/commandlineflags.h"
|
||||
#include "mediapipe/framework/port/integral_types.h"
|
||||
#include "mediapipe/framework/port/status.h"
|
||||
#include "mediapipe/framework/timestamp.h"
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
#include <fstream>
|
||||
|
||||
#include "absl/algorithm/container.h"
|
||||
#include "absl/flags/flag.h"
|
||||
#include "absl/strings/numbers.h"
|
||||
#include "absl/strings/str_cat.h"
|
||||
#include "absl/strings/substitute.h"
|
||||
@@ -33,14 +34,24 @@
|
||||
#include "mediapipe/framework/port/integral_types.h"
|
||||
#include "mediapipe/framework/port/statusor.h"
|
||||
|
||||
ABSL_FLAG(std::string, system_cpu_max_freq_file,
|
||||
"/sys/devices/system/cpu/cpu$0/cpufreq/cpuinfo_max_freq",
|
||||
"The file pattern for CPU max frequencies, where $0 will be replaced "
|
||||
"with the CPU id.");
|
||||
|
||||
namespace mediapipe {
|
||||
namespace {
|
||||
|
||||
constexpr uint32 kBufferLength = 64;
|
||||
|
||||
absl::StatusOr<std::string> GetFilePath(int cpu) {
|
||||
return absl::Substitute(
|
||||
"/sys/devices/system/cpu/cpu$0/cpufreq/cpuinfo_max_freq", cpu);
|
||||
if (absl::GetFlag(FLAGS_system_cpu_max_freq_file).find("$0") ==
|
||||
std::string::npos) {
|
||||
return absl::InvalidArgumentError(
|
||||
absl::StrCat("Invalid frequency file: ",
|
||||
absl::GetFlag(FLAGS_system_cpu_max_freq_file)));
|
||||
}
|
||||
return absl::Substitute(absl::GetFlag(FLAGS_system_cpu_max_freq_file), cpu);
|
||||
}
|
||||
|
||||
absl::StatusOr<uint64> GetCpuMaxFrequency(int cpu) {
|
||||
|
||||
@@ -38,6 +38,18 @@ cc_test(
|
||||
],
|
||||
)
|
||||
|
||||
cc_library(
|
||||
name = "one_euro_filter",
|
||||
srcs = ["one_euro_filter.cc"],
|
||||
hdrs = ["one_euro_filter.h"],
|
||||
deps = [
|
||||
":low_pass_filter",
|
||||
"//mediapipe/framework/port:logging",
|
||||
"@com_google_absl//absl/memory",
|
||||
"@com_google_absl//absl/time",
|
||||
],
|
||||
)
|
||||
|
||||
cc_library(
|
||||
name = "relative_velocity_filter",
|
||||
srcs = ["relative_velocity_filter.cc"],
|
||||
|
||||
@@ -0,0 +1,84 @@
|
||||
#include "mediapipe/util/filtering/one_euro_filter.h"
|
||||
|
||||
#include <cmath>
|
||||
|
||||
#include "absl/memory/memory.h"
|
||||
#include "mediapipe/framework/port/logging.h"
|
||||
#include "mediapipe/util/filtering/low_pass_filter.h"
|
||||
|
||||
namespace mediapipe {
|
||||
|
||||
static const double kEpsilon = 0.000001;
|
||||
|
||||
OneEuroFilter::OneEuroFilter(double frequency, double min_cutoff, double beta,
|
||||
double derivate_cutoff) {
|
||||
SetFrequency(frequency);
|
||||
SetMinCutoff(min_cutoff);
|
||||
SetBeta(beta);
|
||||
SetDerivateCutoff(derivate_cutoff);
|
||||
x_ = absl::make_unique<LowPassFilter>(GetAlpha(min_cutoff));
|
||||
dx_ = absl::make_unique<LowPassFilter>(GetAlpha(derivate_cutoff));
|
||||
last_time_ = 0;
|
||||
}
|
||||
|
||||
double OneEuroFilter::Apply(absl::Duration timestamp, double value) {
|
||||
int64_t new_timestamp = absl::ToInt64Nanoseconds(timestamp);
|
||||
if (last_time_ >= new_timestamp) {
|
||||
// Results are unpredictable in this case, so nothing to do but
|
||||
// return same value
|
||||
LOG(WARNING) << "New timestamp is equal or less than the last one.";
|
||||
return value;
|
||||
}
|
||||
|
||||
// update the sampling frequency based on timestamps
|
||||
if (last_time_ != 0 && new_timestamp != 0) {
|
||||
static constexpr double kNanoSecondsToSecond = 1e-9;
|
||||
frequency_ = 1.0 / ((new_timestamp - last_time_) * kNanoSecondsToSecond);
|
||||
}
|
||||
last_time_ = new_timestamp;
|
||||
|
||||
// estimate the current variation per second
|
||||
double dvalue = x_->HasLastRawValue()
|
||||
? (value - x_->LastRawValue()) * frequency_
|
||||
: 0.0; // FIXME: 0.0 or value?
|
||||
double edvalue = dx_->ApplyWithAlpha(dvalue, GetAlpha(derivate_cutoff_));
|
||||
// use it to update the cutoff frequency
|
||||
double cutoff = min_cutoff_ + beta_ * std::fabs(edvalue);
|
||||
|
||||
// filter the given value
|
||||
return x_->ApplyWithAlpha(value, GetAlpha(cutoff));
|
||||
}
|
||||
|
||||
double OneEuroFilter::GetAlpha(double cutoff) {
|
||||
double te = 1.0 / frequency_;
|
||||
double tau = 1.0 / (2 * M_PI * cutoff);
|
||||
return 1.0 / (1.0 + tau / te);
|
||||
}
|
||||
|
||||
void OneEuroFilter::SetFrequency(double frequency) {
|
||||
if (frequency <= kEpsilon) {
|
||||
LOG(ERROR) << "frequency should be > 0";
|
||||
return;
|
||||
}
|
||||
frequency_ = frequency;
|
||||
}
|
||||
|
||||
void OneEuroFilter::SetMinCutoff(double min_cutoff) {
|
||||
if (min_cutoff <= kEpsilon) {
|
||||
LOG(ERROR) << "min_cutoff should be > 0";
|
||||
return;
|
||||
}
|
||||
min_cutoff_ = min_cutoff;
|
||||
}
|
||||
|
||||
void OneEuroFilter::SetBeta(double beta) { beta_ = beta; }
|
||||
|
||||
void OneEuroFilter::SetDerivateCutoff(double derivate_cutoff) {
|
||||
if (derivate_cutoff <= kEpsilon) {
|
||||
LOG(ERROR) << "derivate_cutoff should be > 0";
|
||||
return;
|
||||
}
|
||||
derivate_cutoff_ = derivate_cutoff;
|
||||
}
|
||||
|
||||
} // namespace mediapipe
|
||||
@@ -0,0 +1,40 @@
|
||||
#ifndef MEDIAPIPE_UTIL_FILTERING_ONE_EURO_FILTER_H_
|
||||
#define MEDIAPIPE_UTIL_FILTERING_ONE_EURO_FILTER_H_
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "absl/time/time.h"
|
||||
#include "mediapipe/util/filtering/low_pass_filter.h"
|
||||
|
||||
namespace mediapipe {
|
||||
|
||||
class OneEuroFilter {
|
||||
public:
|
||||
OneEuroFilter(double frequency, double min_cutoff, double beta,
|
||||
double derivate_cutoff);
|
||||
|
||||
double Apply(absl::Duration timestamp, double value);
|
||||
|
||||
private:
|
||||
double GetAlpha(double cutoff);
|
||||
|
||||
void SetFrequency(double frequency);
|
||||
|
||||
void SetMinCutoff(double min_cutoff);
|
||||
|
||||
void SetBeta(double beta);
|
||||
|
||||
void SetDerivateCutoff(double derivate_cutoff);
|
||||
|
||||
double frequency_;
|
||||
double min_cutoff_;
|
||||
double beta_;
|
||||
double derivate_cutoff_;
|
||||
std::unique_ptr<LowPassFilter> x_;
|
||||
std::unique_ptr<LowPassFilter> dx_;
|
||||
int64_t last_time_;
|
||||
};
|
||||
|
||||
} // namespace mediapipe
|
||||
|
||||
#endif // MEDIAPIPE_UTIL_FILTERING_ONE_EURO_FILTER_H_
|
||||
@@ -14,27 +14,31 @@
|
||||
|
||||
#include "mediapipe/util/resource_util.h"
|
||||
|
||||
#include "absl/flags/flag.h"
|
||||
#include <iostream>
|
||||
|
||||
#include "absl/strings/str_split.h"
|
||||
#include "mediapipe/framework/deps/file_path.h"
|
||||
#include "mediapipe/framework/port/file_helpers.h"
|
||||
#include "mediapipe/framework/port/ret_check.h"
|
||||
|
||||
ABSL_FLAG(
|
||||
std::string, resource_root_dir, "",
|
||||
"The absolute path to the resource directory."
|
||||
"If specified, resource_root_dir will be prepended to the original path.");
|
||||
#include "mediapipe/util/resource_util_custom.h"
|
||||
#include "mediapipe/util/resource_util_internal.h"
|
||||
|
||||
namespace mediapipe {
|
||||
|
||||
absl::StatusOr<std::string> PathToResourceAsFile(const std::string& path) {
|
||||
return mediapipe::file::JoinPath(absl::GetFlag(FLAGS_resource_root_dir),
|
||||
path);
|
||||
}
|
||||
namespace {
|
||||
ResourceProviderFn resource_provider_ = nullptr;
|
||||
} // namespace
|
||||
|
||||
absl::Status GetResourceContents(const std::string& path, std::string* output,
|
||||
bool read_as_binary) {
|
||||
return mediapipe::file::GetContents(path, output, read_as_binary);
|
||||
if (resource_provider_ == nullptr || !resource_provider_(path, output).ok()) {
|
||||
return internal::DefaultGetResourceContents(path, output, read_as_binary);
|
||||
}
|
||||
return absl::OkStatus();
|
||||
}
|
||||
|
||||
void SetCustomGlobalResourceProvider(ResourceProviderFn fn) {
|
||||
resource_provider_ = std::move(fn);
|
||||
}
|
||||
|
||||
} // namespace mediapipe
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "mediapipe/framework/port/status.h"
|
||||
#include "mediapipe/framework/port/statusor.h"
|
||||
|
||||
namespace mediapipe {
|
||||
|
||||
@@ -18,9 +18,9 @@
|
||||
#include "mediapipe/framework/port/file_helpers.h"
|
||||
#include "mediapipe/framework/port/ret_check.h"
|
||||
#include "mediapipe/framework/port/singleton.h"
|
||||
#include "mediapipe/framework/port/statusor.h"
|
||||
#include "mediapipe/util/android/asset_manager_util.h"
|
||||
#include "mediapipe/util/android/file/base/helpers.h"
|
||||
#include "mediapipe/util/resource_util.h"
|
||||
|
||||
namespace mediapipe {
|
||||
|
||||
@@ -31,6 +31,37 @@ absl::StatusOr<std::string> PathToResourceAsFileInternal(
|
||||
}
|
||||
} // namespace
|
||||
|
||||
namespace internal {
|
||||
absl::Status DefaultGetResourceContents(const std::string& path,
|
||||
std::string* output,
|
||||
bool read_as_binary) {
|
||||
if (!read_as_binary) {
|
||||
LOG(WARNING)
|
||||
<< "Setting \"read_as_binary\" to false is a no-op on Android.";
|
||||
}
|
||||
if (absl::StartsWith(path, "/")) {
|
||||
return file::GetContents(path, output, file::Defaults());
|
||||
}
|
||||
|
||||
if (absl::StartsWith(path, "content://")) {
|
||||
MP_RETURN_IF_ERROR(
|
||||
Singleton<AssetManager>::get()->ReadContentUri(path, output));
|
||||
return absl::OkStatus();
|
||||
}
|
||||
|
||||
// Try the test environment.
|
||||
absl::string_view workspace = "mediapipe";
|
||||
auto test_path = file::JoinPath(std::getenv("TEST_SRCDIR"), workspace, path);
|
||||
if (file::Exists(test_path).ok()) {
|
||||
return file::GetContents(path, output, file::Defaults());
|
||||
}
|
||||
|
||||
RET_CHECK(Singleton<AssetManager>::get()->ReadFile(path, output))
|
||||
<< "could not read asset: " << path;
|
||||
return absl::OkStatus();
|
||||
}
|
||||
} // namespace internal
|
||||
|
||||
absl::StatusOr<std::string> PathToResourceAsFile(const std::string& path) {
|
||||
// Return full path.
|
||||
if (absl::StartsWith(path, "/")) {
|
||||
@@ -68,25 +99,4 @@ absl::StatusOr<std::string> PathToResourceAsFile(const std::string& path) {
|
||||
return path;
|
||||
}
|
||||
|
||||
absl::Status GetResourceContents(const std::string& path, std::string* output,
|
||||
bool read_as_binary) {
|
||||
if (!read_as_binary) {
|
||||
LOG(WARNING)
|
||||
<< "Setting \"read_as_binary\" to false is a no-op on Android.";
|
||||
}
|
||||
if (absl::StartsWith(path, "/")) {
|
||||
return file::GetContents(path, output, file::Defaults());
|
||||
}
|
||||
|
||||
if (absl::StartsWith(path, "content://")) {
|
||||
MP_RETURN_IF_ERROR(
|
||||
Singleton<AssetManager>::get()->ReadContentUri(path, output));
|
||||
return absl::OkStatus();
|
||||
}
|
||||
|
||||
RET_CHECK(Singleton<AssetManager>::get()->ReadFile(path, output))
|
||||
<< "could not read asset: " << path;
|
||||
return absl::OkStatus();
|
||||
}
|
||||
|
||||
} // namespace mediapipe
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
#include "absl/strings/match.h"
|
||||
#include "mediapipe/framework/port/file_helpers.h"
|
||||
#include "mediapipe/framework/port/ret_check.h"
|
||||
#include "mediapipe/framework/port/statusor.h"
|
||||
#include "mediapipe/util/resource_util.h"
|
||||
|
||||
namespace mediapipe {
|
||||
@@ -40,6 +41,23 @@ absl::StatusOr<std::string> PathToResourceAsFileInternal(
|
||||
}
|
||||
} // namespace
|
||||
|
||||
namespace internal {
|
||||
absl::Status DefaultGetResourceContents(const std::string& path,
|
||||
std::string* output,
|
||||
bool read_as_binary) {
|
||||
if (!read_as_binary) {
|
||||
LOG(WARNING) << "Setting \"read_as_binary\" to false is a no-op on ios.";
|
||||
}
|
||||
ASSIGN_OR_RETURN(std::string full_path, PathToResourceAsFile(path));
|
||||
|
||||
std::ifstream input_file(full_path);
|
||||
std::stringstream buffer;
|
||||
buffer << input_file.rdbuf();
|
||||
buffer.str().swap(*output);
|
||||
return absl::OkStatus();
|
||||
}
|
||||
} // namespace internal
|
||||
|
||||
absl::StatusOr<std::string> PathToResourceAsFile(const std::string& path) {
|
||||
// Return full path.
|
||||
if (absl::StartsWith(path, "/")) {
|
||||
@@ -83,18 +101,4 @@ absl::StatusOr<std::string> PathToResourceAsFile(const std::string& path) {
|
||||
return path;
|
||||
}
|
||||
|
||||
absl::Status GetResourceContents(const std::string& path, std::string* output,
|
||||
bool read_as_binary) {
|
||||
if (!read_as_binary) {
|
||||
LOG(WARNING) << "Setting \"read_as_binary\" to false is a no-op on ios.";
|
||||
}
|
||||
ASSIGN_OR_RETURN(std::string full_path, PathToResourceAsFile(path));
|
||||
|
||||
std::ifstream input_file(full_path);
|
||||
std::stringstream buffer;
|
||||
buffer << input_file.rdbuf();
|
||||
buffer.str().swap(*output);
|
||||
return absl::OkStatus();
|
||||
}
|
||||
|
||||
} // namespace mediapipe
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
#ifndef MEDIAPIPE_UTIL_RESOURCE_UTIL_CUSTOM_H_
|
||||
#define MEDIAPIPE_UTIL_RESOURCE_UTIL_CUSTOM_H_
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "mediapipe/framework/port/status.h"
|
||||
|
||||
namespace mediapipe {
|
||||
|
||||
typedef std::function<absl::Status(const std::string&, std::string*)>
|
||||
ResourceProviderFn;
|
||||
|
||||
// Overrides the behavior of GetResourceContents.
|
||||
void SetCustomGlobalResourceProvider(ResourceProviderFn fn);
|
||||
|
||||
} // namespace mediapipe
|
||||
|
||||
#endif // MEDIAPIPE_UTIL_RESOURCE_UTIL_CUSTOM_H_
|
||||
@@ -0,0 +1,43 @@
|
||||
// Copyright 2019 The MediaPipe Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "absl/flags/flag.h"
|
||||
#include "mediapipe/framework/deps/file_path.h"
|
||||
#include "mediapipe/framework/port/file_helpers.h"
|
||||
#include "mediapipe/framework/port/statusor.h"
|
||||
|
||||
ABSL_FLAG(
|
||||
std::string, resource_root_dir, "",
|
||||
"The absolute path to the resource directory."
|
||||
"If specified, resource_root_dir will be prepended to the original path.");
|
||||
|
||||
namespace mediapipe {
|
||||
|
||||
using mediapipe::file::GetContents;
|
||||
using mediapipe::file::JoinPath;
|
||||
|
||||
namespace internal {
|
||||
|
||||
absl::Status DefaultGetResourceContents(const std::string& path,
|
||||
std::string* output,
|
||||
bool read_as_binary) {
|
||||
return GetContents(path, output, read_as_binary);
|
||||
}
|
||||
} // namespace internal
|
||||
|
||||
absl::StatusOr<std::string> PathToResourceAsFile(const std::string& path) {
|
||||
return JoinPath(absl::GetFlag(FLAGS_resource_root_dir), path);
|
||||
}
|
||||
|
||||
} // namespace mediapipe
|
||||
@@ -0,0 +1,19 @@
|
||||
#ifndef MEDIAPIPE_UTIL_RESOURCE_UTIL_INTERNAL_H_
|
||||
#define MEDIAPIPE_UTIL_RESOURCE_UTIL_INTERNAL_H_
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "mediapipe/framework/port/status.h"
|
||||
|
||||
namespace mediapipe {
|
||||
namespace internal {
|
||||
|
||||
// Tries to return the contents of a file given the path. Implementation is
|
||||
// platform-dependent.
|
||||
absl::Status DefaultGetResourceContents(const std::string& path,
|
||||
std::string* output,
|
||||
bool read_as_binary);
|
||||
|
||||
} // namespace internal
|
||||
} // namespace mediapipe
|
||||
#endif // MEDIAPIPE_UTIL_RESOURCE_UTIL_INTERNAL_H_
|
||||
@@ -27,7 +27,8 @@ extern "C" void MediaPipe_RegisterTfLiteOpResolver(tflite::MutableOpResolver*);
|
||||
|
||||
// This resolver is used for the custom ops introduced by
|
||||
// `MediaPipe_RegisterTfLiteOpResolver` (see above).
|
||||
class CpuOpResolver : public tflite::ops::builtin::BuiltinOpResolver {
|
||||
class CpuOpResolver
|
||||
: public tflite::ops::builtin::BuiltinOpResolverWithoutDefaultDelegates {
|
||||
public:
|
||||
CpuOpResolver() { MediaPipe_RegisterTfLiteOpResolver(this); }
|
||||
};
|
||||
|
||||
@@ -20,7 +20,8 @@
|
||||
namespace mediapipe {
|
||||
|
||||
// This OpResolver is used for supporting "Convolution2DTransposeBias" on GPU.
|
||||
class OpResolver : public tflite::ops::builtin::BuiltinOpResolver {
|
||||
class OpResolver
|
||||
: public tflite::ops::builtin::BuiltinOpResolverWithoutDefaultDelegates {
|
||||
public:
|
||||
OpResolver();
|
||||
};
|
||||
|
||||
@@ -24,7 +24,6 @@ absl::StatusOr<api2::Packet<TfLiteModelPtr>> TfLiteModelLoader::LoadFromPath(
|
||||
std::string model_path = path;
|
||||
|
||||
ASSIGN_OR_RETURN(model_path, mediapipe::PathToResourceAsFile(model_path));
|
||||
|
||||
auto model = tflite::FlatBufferModel::BuildFromFile(model_path.c_str());
|
||||
RET_CHECK(model) << "Failed to load model from path " << model_path;
|
||||
return api2::MakePacket<TfLiteModelPtr>(
|
||||
|
||||
@@ -290,7 +290,7 @@ cc_library(
|
||||
"//mediapipe/framework/port:vector",
|
||||
"@com_google_absl//absl/container:node_hash_map",
|
||||
"@com_google_absl//absl/strings:str_format",
|
||||
"@eigen_archive//:eigen",
|
||||
"@eigen_archive//:eigen3",
|
||||
],
|
||||
)
|
||||
|
||||
@@ -429,7 +429,7 @@ cc_library(
|
||||
"@com_google_absl//absl/container:node_hash_map",
|
||||
"@com_google_absl//absl/container:node_hash_set",
|
||||
"@com_google_absl//absl/strings",
|
||||
"@eigen_archive//:eigen",
|
||||
"@eigen_archive//:eigen3",
|
||||
],
|
||||
)
|
||||
|
||||
@@ -526,7 +526,7 @@ cc_library(
|
||||
"@com_google_absl//absl/container:flat_hash_map",
|
||||
"@com_google_absl//absl/container:node_hash_set",
|
||||
"@com_google_absl//absl/memory",
|
||||
"@eigen_archive//:eigen",
|
||||
"@eigen_archive//:eigen3",
|
||||
],
|
||||
)
|
||||
|
||||
@@ -624,7 +624,7 @@ cc_library(
|
||||
"@com_google_absl//absl/algorithm:container",
|
||||
"@com_google_absl//absl/container:flat_hash_set",
|
||||
"@com_google_absl//absl/memory",
|
||||
"@eigen_archive//:eigen",
|
||||
"@eigen_archive//:eigen3",
|
||||
],
|
||||
alwayslink = 1,
|
||||
)
|
||||
@@ -735,7 +735,6 @@ cc_test(
|
||||
":region_flow_cc_proto",
|
||||
":region_flow_computation",
|
||||
"//mediapipe/framework/deps:file_path",
|
||||
"//mediapipe/framework/port:commandlineflags",
|
||||
"//mediapipe/framework/port:file_helpers",
|
||||
"//mediapipe/framework/port:gtest_main",
|
||||
"//mediapipe/framework/port:logging",
|
||||
@@ -744,6 +743,7 @@ cc_test(
|
||||
"//mediapipe/framework/port:opencv_imgproc",
|
||||
"//mediapipe/framework/port:status",
|
||||
"//mediapipe/framework/port:vector",
|
||||
"@com_google_absl//absl/flags:flag",
|
||||
"@com_google_absl//absl/time",
|
||||
],
|
||||
)
|
||||
@@ -757,6 +757,7 @@ cc_test(
|
||||
":box_tracker",
|
||||
"//mediapipe/framework/deps:file_path",
|
||||
"//mediapipe/framework/port:gtest_main",
|
||||
"@com_google_absl//absl/flags:flag",
|
||||
],
|
||||
)
|
||||
|
||||
|
||||
@@ -21,9 +21,9 @@
|
||||
#include <random>
|
||||
#include <string>
|
||||
|
||||
#include "absl/flags/flag.h"
|
||||
#include "absl/time/clock.h"
|
||||
#include "mediapipe/framework/deps/file_path.h"
|
||||
#include "mediapipe/framework/port/commandlineflags.h"
|
||||
#include "mediapipe/framework/port/file_helpers.h"
|
||||
#include "mediapipe/framework/port/gtest.h"
|
||||
#include "mediapipe/framework/port/logging.h"
|
||||
@@ -37,7 +37,7 @@
|
||||
|
||||
// To ensure that the selected thresholds are robust, it is recommend
|
||||
// to run this test mutiple times with time seed, if changes are made.
|
||||
DEFINE_bool(time_seed, false, "Activate to test thresholds");
|
||||
ABSL_FLAG(bool, time_seed, false, "Activate to test thresholds");
|
||||
|
||||
namespace mediapipe {
|
||||
namespace {
|
||||
|
||||
Reference in New Issue
Block a user