如何调试 theano 张量的形状不匹配?
How to debug shape mismatch of theano tensor?
我定义了一个 Theano 张量 m = T.imatrix('m')
并将其用作 theano 函数的参数 foo
。
当我现在用形状为 (100,3) 的 numpy 数组 arr
调用 foo(arr)
时,我希望 m[:, 1]
具有形状 (100,)。
但是,错误信息显示形状是(1,100)。如何逐步检查功能不匹配?
感谢评论中的有用提示,我能够调试形状不匹配问题。我设置了另一个具有相同输入和自定义输出的 theano 调试函数,我可以用调试器检查它,例如:
# define a function ...
inputs = T.matrix('inputs')
debug_out = T.sum(fancy_expression(inputs)) # expression to debug
debug_fn = theano.function(
inputs=[inputs],
outputs=debug_out,
on_unused_input='ignore' # to suppress unused input exeptions
)
# ... and debug it here
result = debug_fn(np.empty((100,3)))
再次感谢@ali_m
我定义了一个 Theano 张量 m = T.imatrix('m')
并将其用作 theano 函数的参数 foo
。
当我现在用形状为 (100,3) 的 numpy 数组 arr
调用 foo(arr)
时,我希望 m[:, 1]
具有形状 (100,)。
但是,错误信息显示形状是(1,100)。如何逐步检查功能不匹配?
感谢评论中的有用提示,我能够调试形状不匹配问题。我设置了另一个具有相同输入和自定义输出的 theano 调试函数,我可以用调试器检查它,例如:
# define a function ...
inputs = T.matrix('inputs')
debug_out = T.sum(fancy_expression(inputs)) # expression to debug
debug_fn = theano.function(
inputs=[inputs],
outputs=debug_out,
on_unused_input='ignore' # to suppress unused input exeptions
)
# ... and debug it here
result = debug_fn(np.empty((100,3)))
再次感谢@ali_m