theano - print value of TensorVariable

后端 未结 5 2025
夕颜
夕颜 2020-12-29 19:02

How can I print the numerical value of a theano TensorVariable? I\'m new to theano, so please be patient :)

I have a function where I get y

5条回答
  •  心在旅途
    2020-12-29 19:13

    For future readers: the previous answer is quite good. But, I found the 'tag.test_value' mechanism more beneficial for debugging purposes (see theano-debug-faq):

    from theano import config
    from theano import tensor as T
    config.compute_test_value = 'raise'
    import numpy as np    
    #define a variable, and use the 'tag.test_value' option:
    x = T.matrix('x')
    x.tag.test_value = np.random.randint(100,size=(5,5))
    
    #define how y is dependent on x:
    y = x*x
    
    #define how some other value (here 'errorCount') depends on y:
    errorCount = T.sum(y)
    
    #print the tag.test_value result for debug purposes!
    errorCount.tag.test_value
    

    For me, this is much more helpful; e.g., checking correct dimensions etc.

提交回复
热议问题