【问题标题】:Tensorflow Serving C++ SyntaxTensorFlow Serving C++ 语法
【发布时间】:2017-10-24 06:02:15
【问题描述】:

现在,我正在研究 Tensorflow Serving 并尝试创建一个自定义 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

谢谢。

【问题讨论】:

    标签: c++ tensorflow-serving


    【解决方案1】:

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

    需要捕获config,因为lambda表达式中的代码使用config

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-07-28
      • 1970-01-01
      • 1970-01-01
      • 2016-12-20
      • 2018-02-01
      相关资源
      最近更新 更多