Tensorflow添加新的切片输出张量

时间:2018-09-25 02:30:12

标签: c++ tensorflow eigen

我检查了文件here

➜  ~ ✗ python
Python 3.6.0 |Continuum Analytics, Inc.| (default, Dec 23 2016, 13:19:00)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy as np
>>> import cv2
>>>

还有Tensorflow tutorial上的那个:

// get the corresponding Eigen tensors for data access
auto input_tensor = input.matrix<double>();
auto weights_tensor = weights.matrix<double>();
auto biases_tensor = biases.matrix<double>();
auto output_tensor = output->matrix<double>();

for (int ix_sample = 0; ix_sample < batch_samples; ix_sample++) {
  for (int ix_unit = 0; ix_unit < units; ix_unit++) {
    output_tensor(ix_sample, ix_unit) = 0;
    for (int ix_input = 0; ix_input < input_feature_width; ix_input++) {
      output_tensor(ix_sample, ix_unit) += input_tensor(ix_sample, ix_input) * weights_tensor(ix_input, ix_unit );
    }  
    output_tensor(ix_sample, ix_unit) += biases_tensor(0, ix_unit);
  }
}

我想知道输出张量是否为3d张量,如何对其进行切片并按矢量分配其值。

我找到了// Create an output tensor Tensor* output_tensor = NULL; OP_REQUIRES_OK(context, context->allocate_output(0, input_tensor.shape(), &output_tensor)); auto output_flat = output_tensor->flat<int32>(); // Set all but the first element of the output tensor to 0. const int N = input.size(); for (int i = 1; i < N; i++) { output_flat(i) = 0; } 的{​​{1}}方法:

slice

但不清楚在这里如何使用它。

0 个答案:

没有答案