AddSymbolicGradients在递归实现中失败

时间:2018-12-31 00:20:58

标签: c++ tensorflow segmentation-fault gradients

我正在使用Tensorflow C ++ API实现简单的RNN。

当前使用github上的1.13。

AddSymbolicGradients (最后一行)的调用失败,成为 Segmentation错误。 gdb告诉我在SymbolicGradientBuilder :: Initialize内部发生错误

auto input_slices = Split(scope, 1, x, window_size);

auto initial_state = Fill(scope, {batch_size, state_size}, 0);

vector<Output> states;
states.reserve(window_size+1);
states.push_back(initial_state);

for (int i=0; i!=window_size; i++) {
    auto concat = Concat(scope, InputList(initializer_list<Input>{input_slices[i], states[i]}), 1);
    auto new_state = Tanh(scope, Add(scope, MatMul(scope, concat, w_rnn), b_rnn));
    states.push_back(new_state);
}

// dense output
auto out = Tanh(scope, Add(scope, MatMul(scope, states[window_size], w_dense), b_dense));

// loss function
auto loss = ReduceMean(scope, Square(scope, Sub(scope, out, y)), {0, 1});

vector<Output> grad_outputs;
TF_CHECK_OK(AddSymbolicGradients(scope, {loss}, {w_rnn, w_dense, b_rnn, b_dense}, &grad_outputs));

有什么主意吗?谢谢

编辑:gdb完整输出

(gdb) where
#0  0x00005555559b45aa in tensorflow::(anonymous namespace)::SymbolicGradientBuilder::Initialize() ()
#1  0x00005555559b6f1c in tensorflow::AddSymbolicGradients(tensorflow::Scope const&, std::vector<tensorflow::Output, std::allocator<tensorflow::O
utput> > const&, std::vector<tensorflow::Output, std::allocator<tensorflow::Output> > const&, std::vector<tensorflow::Output, std::allocator<tens
orflow::Output> > const&, std::vector<tensorflow::Output, std::allocator<tensorflow::Output> >*) ()
#2  0x00005555559b9bb2 in tensorflow::AddSymbolicGradients(tensorflow::Scope const&, std::vector<tensorflow::Output, std::allocator<tensorflow::O
utput> > const&, std::vector<tensorflow::Output, std::allocator<tensorflow::Output> > const&, std::vector<tensorflow::Output, std::allocator<tens
orflow::Output> >*) ()
#3  0x000055555597ce6c in Rnn::train(Dataset, int, int, int) ()
#4  0x00005555558410d6 in main ()

0 个答案:

没有答案