frthjf
frthjf

Reputation: 251

How to debug shape mismatch of theano tensor?

I defined a Theano tensor m = T.imatrix('m') and used it as an argument of a theano function foo.

When I now call foo(arr) with a numpy array arr of shape (100,3), I'd expect that m[:, 1] would have the shape (100,).

However, the error message shows that the shape is (1,100). How can I examine the function mismatch step by step?

Upvotes: 1

Views: 1200

Answers (1)

frthjf
frthjf

Reputation: 251

Thanks to the useful hints in the comments I was able to debug the shape mismatch. I set up another theano debug function with the same inputs and a custom output, which I could examine with the debugger, e.g.:

# 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)))

Thanks again to @ali_m

Upvotes: 2

Related Questions