如何使用theano获取代码的错误行?

时间:2015-11-18 03:44:39

标签: theano

在常见问题页面http://deeplearning.net/software/theano/tutorial/debug_faq.html中, 我看到了这个例子

import numpy as np
import theano
import theano.tensor as T

x = T.vector()
y = T.vector()
z = x + x
z = z + y
f = theano.function([x, y], z)
f(np.ones((2,)), np.ones((3,)))

如果我使用optimizer = fast_compile或optimizer = None而exception_verbosity = high我应该看到

Backtrace when the node is created:
  File "test0.py", line 8, in <module>
    z = z + y

Debugprint of the apply node:
Elemwise{add,no_inplace} [id A] <TensorType(float64, vector)> ''
 |Elemwise{add,no_inplace} [id B] <TensorType(float64, vector)> ''
 | |<TensorType(float64, vector)> [id C] <TensorType(float64, vector)>
 | |<TensorType(float64, vector)> [id C] <TensorType(float64, vector)>
 |<TensorType(float64, vector)> [id D] <TensorType(float64, vector)>

但我只是看到了

Traceback (most recent call last):
  File "C:\test.py", line 21, in <module>
    f(np.ones((2,)), np.ones((3,)))
  File "C:\Anaconda\lib\site-packages\theano\compile\function_module.py", line 606, in __call__
    storage_map=self.fn.storage_map)
  File "C:\Anaconda\lib\site-packages\theano\compile\function_module.py", line 595, in __call__
    outputs = self.fn()
ValueError: Input dimension mis-match. (input[0].shape[0] = 2, input[1].shape[0] = 3)
Apply node that caused the error: Elemwise{add,no_inplace}(Elemwise{add,no_inplace}.0, <TensorType(float32, vector)>)
Inputs types: [TensorType(float32, vector), TensorType(float32, vector)]
Inputs shapes: [(2L,), (3L,)]
Inputs strides: [(4L,), (4L,)]
Inputs values: [array([ 2.,  2.], dtype=float32), array([ 1.,  1.,  1.], dtype=float32)]

Backtrace when the node is created:
  File "C:\Anaconda\lib\site-packages\theano\gof\type.py", line 318, in __call__
    return utils.add_tag_trace(self.make_variable(name))

Debugprint of the apply node: 
Elemwise{add,no_inplace} [@A] <TensorType(float32, vector)> ''   
 |Elemwise{add,no_inplace} [@B] <TensorType(float32, vector)> ''   
 | |<TensorType(float32, vector)> [@C] <TensorType(float32, vector)>
 | |<TensorType(float32, vector)> [@C] <TensorType(float32, vector)>
 |<TensorType(float32, vector)> [@D] <TensorType(float32, vector)>

Storage map footprint:
 - <TensorType(float32, vector)>, Shape: (2L,), ElemSize: 4 Byte(s), TotalSize: 8 Byte(s)
 - Elemwise{add,no_inplace}.0, Shape: (2L,), ElemSize: 4 Byte(s), TotalSize: 8 Byte(s)
 - <TensorType(float32, vector)>, Shape: (3L,), ElemSize: 4 Byte(s), TotalSize: 12 Byte(s)
回溯没有告诉我这条线。有什么问题?

0 个答案:

没有答案