【问题标题】:Understanding the Definition of New Tensorflow Operators in C++了解 C++ 中新的 TensorFlow 运算符的定义
【发布时间】:2017-09-11 09:24:41
【问题描述】:

我正在尝试按照官方指南在 tensorflow 中定义新的运算符。 https://www.tensorflow.org/extend/adding_an_op

#include "tensorflow/core/framework/op.h"
#include "tensorflow/core/framework/shape_inference.h"

using namespace tensorflow;

REGISTER_OP("ZeroOut")
    .Input("to_zero: int32")
    .Output("zeroed: int32")
    .SetShapeFn([](::tensorflow::shape_inference::InferenceContext* c){
      c->set_output(0, c->input(0));
      return Status::OK();
    });

但是我找不到此代码的逐行解释,特别是我不明白 .SetShapeFn([](::tensorflow::shape_inference::InferenceContext* c) 的作用及其语法.我也对InferenceContext感到困惑,我猜这是一种连续传递任何数组元素的方法..我在任何地方都找不到明确的定义,也许我找错了地方,有人能帮忙吗我有解释还是参考? 我想深入了解这段代码在后台做了什么。

【问题讨论】:

    标签: tensorflow operators


    【解决方案1】:

    你有没有发现这里关于形状推断函数的部分? https://www.tensorflow.org/extend/adding_an_op#shape_functions_in_c

    其中有很多关于 ShapeInferenceContext 类和编写自己的函数的机制的讨论。如果这不包括您感兴趣的内容,您能否提供更多详细信息?

    【讨论】:

    • 至少,这里有一些操作注册的more examplesHere 是 shape-handling-stuff 的代码。
    猜你喜欢
    • 2016-03-29
    • 1970-01-01
    • 2013-06-09
    • 1970-01-01
    • 1970-01-01
    • 2011-01-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多