两个卷积层的结果相加,怎么就没有了height以及width信息
有两个输出 output1 = img_conv(..) output2 = img_conv(....) output1和output2的height和width一致, 但相加后,我想保留height和width,但实际相加后就没有这些信息了,请问该如何修改
请贴一下执行相加的相关配置代码,谢谢
@JiayiFeng
conv2 = paddle.layer.img_conv(
input=output1,
filter_size=kernel_size,
num_channels=n_outputs,
num_filters=n_outputs,
stride=stride,
padding=padding,
act=paddle.activation.Linear(),
dilation=dilation,
bias_attr=False,
name='layer'+str(level)+'_conv2')
res_x = paddle.layer.img_conv(
input=value,
filter_size=1,
num_channels=n_inputs,
num_filters=n_outputs,
padding=padding,
dilation=dilation,
act=paddle.activation.Linear(),
bias_attr=False,
name='layer'+str(level)+'_conv')
tmp_input = res_x + output2
(Pdb) p output2.height 45L (Pdb) p res_x.height 45L (Pdb) p tmp_input.height 0 (Pdb) p output2.width 58L (Pdb) p res_x.width 58L (Pdb) p tmp_input.width 0
在配置网络的过程中,并不能直接使用Python里的+,因为conv2、output2的值实际上存储于C++中。要将两个结果相加,请使用paddle.v2.layer.addto:
http://www.paddlepaddle.org/docs/0.12.0/api/en/config/layer.html#addto
另外,如果您是paddle的初学者,建议您直接开始学习Fluid。Fluid是Paddle新版本的接口,也是未来的主推方向。
@JiayiFeng 多谢多谢,直接也用了这个,理解错了接口的定义。。。。。
@JiayiFeng 因为看了这个接口的公式,不对劲。。。有点误导人
恩,这也是我们推荐Fluid的原因之一。Fluid中做了一些处理,可以直接将Python的加减乘除映射为elementwise的layer操作,更加直观。
@JiayiFeng 好的,多谢
@JiayiFeng hi,上面的代码经过修改之后,现在构建网络没有报错,
conv2 = paddle.layer.img_conv(
input=output1,
filter_size=kernel_size,
num_channels=n_outputs,
num_filters=n_outputs,
stride=stride,
padding=padding,
act=paddle.activation.Linear(),
dilation=dilation,
bias_attr=False,
name='layer'+str(level)+'_conv2')
res_x = paddle.layer.img_conv(
input=value,
filter_size=1,
num_channels=n_inputs,
num_filters=n_outputs,
padding=padding,
dilation=dilation,
act=paddle.activation.Linear(),
bias_attr=False,
name='layer'+str(level)+'_conv')
output = paddle.layer.addto(input=[res_x, output2],
act=paddle.activation.Relu(),
bias_attr=True)
但在运行过程中出现了以下错误 F0604 19:43:24.618275 32327 BaseMatrix.cu:65] Check failed: height_ == b.height_ && width_ == b.width_ Matrix dimensions are not equalF0604 19:43:24.628722 32331 BaseMatrix.cu:65] Check failed: height_ == b.height_ && width_ == b.wid, 明明在构建网络的时候已经check了res_x,output2的形状完全一致,怎么在运行过程中还能出现这样的错误,请问是什么原因
@JiayiFeng 好像即使我改成 output = paddle.layer.addto(input=[output2, output2], act=paddle.activation.Relu(), bias_attr=True)
这样也报错。。。。。,如果我直接返回output2或者res_x是没有问题的,我猜测应该是addto函数用法不对?
output2是哪个的输出?我看上面卷积层的输出一个是conv2另一个是res_x
@JiayiFeng 和rex_x一样的,就是conv2 output = paddle.layer.addto(input=[res_x, res_x], act=paddle.activation.Relu(), bias_attr=True) 改成这样也是报同样的错
请问能不能把报的错给贴出来?
@luotao1 上面有写到啊
但在运行过程中出现了以下错误 F0604 19:43:24.618275 32327 BaseMatrix.cu:65] Check failed: height_ == b.height_ && width_ == b.width_ Matrix dimensions are not equalF0604 19:43:24.628722 32331 BaseMatrix.cu:65] Check failed: height_ == b.height_ && width_ == b.wid,
@luotao1 @JiayiFeng 完整log如下:
F0605 10:27:03.032656 6580 BaseMatrix.cu:65] Check failed: height_ == b.height_ && width_ == b.width_ Matrix dimensions are not equal
*** Check failure stack trace: ***
@ 0x7fcb87d722ed google::LogMessage::Fail()
@ 0x7fcb87d75d9c google::LogMessage::SendToLog()
@ 0x7fcb87d71e13 google::LogMessage::Flush()
@ 0x7fcb87d772ae google::LogMessageFatal::~LogMessageFatal()
@ 0x7fcb87c11f2e paddle::BaseMatrixT<>::applyBinary<>()
@ 0x7fcb87c12001 paddle::BaseMatrixT<>::assign()
@ 0x7fcb879fe6ab paddle::AddtoLayer::forward()
@ 0x7fcb8796ca4d paddle::NeuralNetwork::forward()
F0605 10:27:03.048748 6584 BaseMatrix.cu:65] Check failed: height_ == b.height_ && width_ == b.width_ Matrix dimensions are not equal
*** Check failure stack trace: ***
F0605 10:27:03.048748 6584 BaseMatrix.cu:65] Check failed: height_ == b.height_ && width_ == b.width_ Matrix dimensions are not equalF0605 10:27:03.049868 6596 BaseMatrix.cu:65] Check failed: height_ == b.height_ && width_ == b.width_ Matrix dimensions are not equal
*** Check failure stack trace: ***
@ 0x7fcb87949f54 paddle::TrainerThread::forward()
@ 0x7fcb87d722ed google::LogMessage::Fail()
@ 0x7fcb87d722ed google::LogMessage::Fail()
@ 0x7fcb8794b255 paddle::TrainerThread::computeThread()
@ 0x7fcb87d75d9c google::LogMessage::SendToLog()
@ 0x7fcb87d75d9c google::LogMessage::SendToLog()
F0605 10:27:03.048748 6584 BaseMatrix.cu:65] Check failed: height_ == b.height_ && width_ == b.width_ Matrix dimensions are not equalF0605 10:27:03.049868 6596 BaseMatrix.cu:65] Check failed: height_ == b.height_ && width_ == b.width_ Matrix dimensions are not equalF0605 10:27:03.053695 6592 BaseMatrix.cu:65] Check failed: height_ == b.height_ && width_ == b.width_ Matrix dimensions are not equal
*** Check failure stack trace: ***
@ 0x7fcc040da870 (unknown)
@ 0x7fcb87d71e13 google::LogMessage::Flush()
@ 0x7fcb87d71e13 google::LogMessage::Flush()
@ 0x7fcb87d722ed google::LogMessage::Fail()
@ 0x7fcb87d772ae google::LogMessageFatal::~LogMessageFatal()
@ 0x7fcb87d772ae google::LogMessageFatal::~LogMessageFatal()
@ 0x7fcc13aa4dc5 start_thread
@ 0x7fcb87d75d9c google::LogMessage::SendToLog()
F0605 10:27:03.048748 6584 BaseMatrix.cu:65] Check failed: height_ == b.height_ && width_ == b.width_ Matrix dimensions are not equalF0605 10:27:03.049868 6596 BaseMatrix.cu:65] Check failed: height_ == b.height_ && width_ == b.width_ Matrix dimensions are not equalF0605 10:27:03.053695 6592 BaseMatrix.cu:65] Check failed: height_ == b.height_ && width_ == b.width_ Matrix dimensions are not equalF0605 10:27:03.057507 6588 BaseMatrix.cu:65] Check failed: height_ == b.height_ && width_ == b.width_ Matrix dimensions are not equal
*** Check failure stack trace: ***
@ 0x7fcb87c11f2e paddle::BaseMatrixT<>::applyBinary<>()
@ 0x7fcb87c11f2e paddle::BaseMatrixT<>::applyBinary<>()
@ 0x7fcb87d71e13 google::LogMessage::Flush()
@ 0x7fcb87d722ed google::LogMessage::Fail()
@ 0x7fcc130c921d __clone
@ 0x7fcb87c12001 paddle::BaseMatrixT<>::assign()
@ 0x7fcb87c12001 paddle::BaseMatrixT<>::assign()
@ 0x7fcb87d772ae google::LogMessageFatal::~LogMessageFatal()
@ 0x7fcb87d75d9c google::LogMessage::SendToLog()
@ 0x7fcb879fe6ab paddle::AddtoLayer::forward()
@ (nil) (unknown)
请问addto的时候,不加bias,能不能试下呢?
@luotao1 都试过了,都不行。。。不知道该怎么解决,就算两个一样的相加都出问题。
如果说自己和自己相加也出错的话,那很可能出错的位置不是addto。从错误日志里只能看到出错的是一个binary的操作,不一定是addto。检查一下其他binary操作的输入情况。
另外,对于图片来说,在Python端看到的shape并不完全等于C++端运行时候的shape。 Python端的[hight, width]就是[H, W] 而C++端的[hight, width]是[N, C*H*W] 其中N是batchsize,C是图片或者feature map的channel数,H和W分别是高和宽。
@JiayiFeng 那假如C++端的W(如果是动态的)不和python端的一致,该怎么解决
没有明白你的意思。“如果是动态的”是什么意思?