c++ - AddSymbolicGradients 在递归实现中失败
问题描述
我正在使用 Tensorflow C++ API 实现一个简单的 RNN。
目前使用来自 github 的 1.13。
对AddSymbolicGradients(最后一行)的调用失败为Segmentation fault。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 ()
解决方案
推荐阅读
- c# - 比较跨不同系统保存的 DateTime 是一个坏主意吗?
- jquery - 使用网站名称进行表单验证时出错
- tensorflow - 在仅具有 CPU 的 PC 上使用 NCHW 训练的 GAN?
- c# - 如何尽可能快地处理 Parallel.ForEach 结果?
- javascript - 在 Lightgallery 中查看上传的 PDF
- vue.js - 每周vuejs日历不显示事件
- python - 我怎样才能使我的单矩阵检查的文档相似性更快?
- android - 重命名 Base.apk
- xamarin - 使用 xamarin 表单在列表视图上添加左右全滑动手势
- excel - 尝试从 Excel 电子表格中的数据生成电子邮件,出现编译错误“未定义用户定义类型”