c++ - tensorflow Invalid argument: In[0] is not a matrix -


i new tensorflow c++ api , struggling find documentation online. short code performs inner product of 2 vectors w , x1, compile fine there run time errors, copy code , error logs here. lot help

#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;    tensor w (dt_float,tensorshape({2}));    tensor x1(dt_float,tensorshape({2}));     auto w_map  = w .tensor<float,1>();   auto x1_map = x1.tensor<float,1>();    for(int i=0;i<l;++i) {      w_map(i)  = -1;      x1_map(i) =  1;     }   std::cout<<"w  \n"<<w .flat<float>()<<"\n debug "<<w .debugstring()<<std::endl;   std::cout<<"x1 \n"<<x1.flat<float>()<<"\n debug "<<x1.debugstring()<<std::endl;     scope root = scope::newrootscope();   clientsession session(root);    // either line of code gives similar run time error  // auto v1 = matmul(root.withopname("v1"), w, x1,  matmul::transposea(true));   auto v1 = matmul(root.withopname("v1"), w, x1, matmul::transposeb(true));    std::vector<tensor> o1;     tf_check_ok(session.run({v1}, &o1)); }  ===========================  hweekuans-macbook-pro:linear_model hweekuan$ ./linear  w   -1 -1  debug tensor<type: float shape: [2] values: -1 -1>  x1  1 1  debug tensor<type: float shape: [2] values: 1 1>  f tensorflow/cc/20170412/linear_model/linear.cc:37] check failed:   ::tensorflow::status::ok() == (session.run({v1}, &o1)) (ok vs. invalid argument: in[0] not matrix      [[node: v1 = matmul[t=dt_float, transpose_a=false, transpose_b=true, _device="/job:localhost/replica:0/task:0/cpu:0"](const/const, const_1/const)]]) abort trap: 6 

the error message gives clue problem: neither w nor x1 2-d matrix—in fact, both 1-d vectors—and tensorflow::ops::matmul() op requires both of arguments @ least 2-dimensional. not automatically convert vectors matrix representation, , must manually.

to solve problem, specify tensorshape({1, 2}) when construct w , tensorshape({2, 1}) when construct x1. these shapes, should not set matmul::transposea(false) , matmul::transposeb(false), or can omit these options since default values.


Comments

Popular posts from this blog

php - Permission denied. Laravel linux server -

google bigquery - Delta between query execution time and Java query call to finish -

python - Pandas two dataframes multiplication? -