gpt4 book ai didi

c++ - Tensorflow 服务 C++ 语法

转载 作者:行者123 更新时间:2023-11-30 05:13:01 31 4
gpt4 key购买 nike

现在,我正在研究 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] 是什么意思?

给我一​​个搜索的想法或提示。

原始代码在此链接中。我无法理解第 70 行。 https://github.com/tensorflow/serving/blob/master/tensorflow_serving/servables/hashmap/hashmap_source_adapter.cc#L70

谢谢。

最佳答案

[config]是 lambda 表达式的捕获列表。由于没有另外指定,它捕获 config按值(value)。这会复制任何 config引用并使其在 lambda 内部可见。

捕获 config是必需的,因为 lambda 表达式中的代码使用了 config :

return LoadHashmapFromFile(path, config.format(), hashmap);

对于 config要在 lambda 表达式中表示某些内容,必须捕获它。特别是,lambda 表达式基本上是创建类的捷径。捕获列表中的任何内容(在 lambda 表达式中实际使用的)都会成为传递给该类的 ctor 的参数(并且 lambda 表达式的主体成为该类的 operator()() 重载的主体)。

关于c++ - Tensorflow 服务 C++ 语法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44149123/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com