Tensorflow 服务 C++ 语法
Tensorflow Serving C++ Syntax
现在,我正在研究 Tensorflow Serving 并尝试创建一个 Custom Servable。
所以,我阅读了有关 hashmap_source_adaptor 的代码(这是 Tensorflow Serving 中的示例代码)。
但是,有些代码,我看不懂。
HashmapSourceAdapter::HashmapSourceAdapter(
const HashmapSourceAdapterConfig& config)
: SimpleLoaderSourceAdapter<StoragePath, Hashmap>(
[config](const StoragePath& path, std::unique_ptr<Hashmap>* hashmap) {
return LoadHashmapFromFile(path, config.format(), hashmap);
},
// Decline to supply a resource footprint estimate.
SimpleLoaderSourceAdapter<StoragePath,
Hashmap>::EstimateNoResources()) {}
HashmapSourceAdapter::~HashmapSourceAdapter() { Detach(); }
第 4 行中的 [config] 是什么意思?
给我一个搜索的想法或提示。
源码在这个link。我无法理解第 70 行。
https://github.com/tensorflow/serving/blob/master/tensorflow_serving/servables/hashmap/hashmap_source_adapter.cc#L70
谢谢。
[config]
是 lambda 表达式的捕获列表。由于未另行指定,因此它按值捕获 config
。这会复制 config
所指的内容,并使其在 lambda 中可见。
需要捕获config
,因为lambda表达式中的代码使用了config
:
return LoadHashmapFromFile(path, config.format(), hashmap);
要使 config
表示 lambda 表达式中的某些内容,必须捕获它。特别是,lambda 表达式基本上是创建 class 的捷径。捕获列表中的任何内容(在 lambda 表达式中实际使用的)都成为传递给 class 的构造函数的参数(并且 lambda 表达式的主体成为 operator()()
重载的主体class).
现在,我正在研究 Tensorflow Serving 并尝试创建一个 Custom Servable。
所以,我阅读了有关 hashmap_source_adaptor 的代码(这是 Tensorflow Serving 中的示例代码)。
但是,有些代码,我看不懂。
HashmapSourceAdapter::HashmapSourceAdapter(
const HashmapSourceAdapterConfig& config)
: SimpleLoaderSourceAdapter<StoragePath, Hashmap>(
[config](const StoragePath& path, std::unique_ptr<Hashmap>* hashmap) {
return LoadHashmapFromFile(path, config.format(), hashmap);
},
// Decline to supply a resource footprint estimate.
SimpleLoaderSourceAdapter<StoragePath,
Hashmap>::EstimateNoResources()) {}
HashmapSourceAdapter::~HashmapSourceAdapter() { Detach(); }
第 4 行中的 [config] 是什么意思?
给我一个搜索的想法或提示。
源码在这个link。我无法理解第 70 行。 https://github.com/tensorflow/serving/blob/master/tensorflow_serving/servables/hashmap/hashmap_source_adapter.cc#L70
谢谢。
[config]
是 lambda 表达式的捕获列表。由于未另行指定,因此它按值捕获 config
。这会复制 config
所指的内容,并使其在 lambda 中可见。
需要捕获config
,因为lambda表达式中的代码使用了config
:
return LoadHashmapFromFile(path, config.format(), hashmap);
要使 config
表示 lambda 表达式中的某些内容,必须捕获它。特别是,lambda 表达式基本上是创建 class 的捷径。捕获列表中的任何内容(在 lambda 表达式中实际使用的)都成为传递给 class 的构造函数的参数(并且 lambda 表达式的主体成为 operator()()
重载的主体class).