【发布时间】:2018-11-20 00:14:55
【问题描述】:
从 TensorFlow 文档中,可以执行以下操作来使用固有 OP 构建图形
#include "tensorflow/cc/client/client_session.h"
#include "tensorflow/cc/ops/standard_ops.h"
#include "tensorflow/core/framework/tensor.h"
int main() {
using namespace tensorflow;
using namespace tensorflow::ops;
Scope root = Scope::NewRootScope();
// Matrix A = [3 2; -1 0]
auto A = Const(root, { {3.f, 2.f}, {-1.f, 0.f} });
// Vector b = [3 5]
auto b = Const(root, { {3.f, 5.f} });
// v = Ab^T
auto v = MatMul(root.WithOpName("v"), A, b, MatMul::TransposeB(true));
std::vector<Tensor> outputs;
ClientSession session(root);
// Run and fetch v
TF_CHECK_OK(session.Run({v}, &outputs));
// Expect outputs[0] == [19; -3]
LOG(INFO) << outputs[0].matrix<float>();
return 0;
}
似乎MatMul 类是自动生成的,因为 github 源代码中没有tensorflow/cc/ops/math_ops.h。
如何为 here 的 ZeroOut OP 等自定义操作做同样的事情
【问题讨论】:
标签: c++ tensorflow machine-learning