I'm trying to get the indices of the max values used in a pool_2d 
operation. I can do this nicely with numpy arrays:

my_in = np.zeros((1,1,4,4)).astype(np.float32)
print my_in
print
inp = T.tensor4()
out = T.grad(T.sum(pool_2d(inp, ds=(2,2), ignore_border=True)), wrt=inp).
eval({inp: my_in})
nonzeros = out.nonzero()
print out
for i in range(len(nonzeros)): print nonzeros[i]

# prints
# [[[[ 0.  0.  0.  0.]
#    [ 0.  0.  0.  0.]
#    [ 0.  0.  0.  0.]
#    [ 0.  0.  0.  0.]]]]

# [[[[ 1.  0.  1.  0.]
#    [ 0.  0.  0.  0.]
#    [ 1.  0.  1.  0.]
#    [ 0.  0.  0.  0.]]]]
# [0 0 0 0]
# [0 0 0 0]
# [0 0 2 2]
# [0 2 0 2]

If I try doing this same thing with T.zeros(), I get a bad result:

a = T.zeros((1,1,4,4), 'float32')
print a.eval()
print

b = T.grad(T.sum(pool_2d(a, ds=(2,2), ignore_border=True)), wrt=a)
print b.eval()
non = b.nonzero()
for i in range(len(non)): print non[i].eval()

# prints
# [[[[ 0.  0.  0.  0.]
#    [ 0.  0.  0.  0.]
#    [ 0.  0.  0.  0.]
#    [ 0.  0.  0.  0.]]]]

# [[[[ 1.  1.  1.  1.]
#    [ 1.  1.  1.  1.]
#    [ 1.  1.  1.  1.]
#    [ 1.  1.  1.  1.]]]]
# [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]
# [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]
# [0 0 0 0 1 1 1 1 2 2 2 2 3 3 3 3]
# [0 1 2 3 0 1 2 3 0 1 2 3 0 1 2 3]

Why are these different? What can I change to make the T.zeros() version 
match the numpy version?

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"theano-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to