首页 > 其他 > 详细

Theano笔记

时间:2014-02-18 11:52:22      阅读:539      评论:0      收藏:0      [点我收藏+]

scan函数

theano.scan(fnsequences=Noneoutputs_info=None,non_sequences=Nonen_steps=Nonetruncate_gradient=-1,go_backwards=Falsemode=Nonename=Noneprofile=False)

 

fn是每一步所用的函数,sequence是输入,outputs_info是scan输出在起始的状态。

 

shared variables相当于全局变量,The value can be accessed and modified by the.get_value() and .set_value() methods.  在function里用updata来修改可以并行。

 

Debug:

http://deeplearning.net/software/theano/tutorial/debug_faq.html

theano.config.compute_test_value = ‘warn‘
  • off: Default behavior. This debugging mechanism is inactive.
  • raise: Compute test values on the fly. Any variable for which a test value is required, but not provided by the user, is treated as an error. An exception is raised accordingly.
  • warn: Idem, but a warning is issued instead of an Exception.
  • ignore: Silently ignore the computation of intermediate test values, if a variable is missing a test value.
import theano

def inspect_inputs(i, node, fn):
    print i, node, "input(s) value(s):", [input[0] for input in fn.inputs],

def inspect_outputs(i, node, fn):
    print "output(s) value(s):", [output[0] for output in fn.outputs]

x = theano.tensor.dscalar(‘x‘)
f = theano.function([x], [5 * x],
                    mode=theano.compile.MonitorMode(
                        pre_func=inspect_inputs,
                        post_func=inspect_outputs))
f(3)

 

mode = ‘DEBUG_MODE‘ 很慢,无效?

使用print

x = theano.tensor.dvector(‘x‘)

x_printed = theano.printing.Print(‘this is a very important value‘)(x)

f = theano.function([x], x * 5)
f_with_print = theano.function([x], x_printed * 5)

#this runs the graph without any printing
assert numpy.all( f([1, 2, 3]) == [5, 10, 15])

#this runs the graph with the message, and value printed
assert numpy.all( f_with_print([1, 2, 3]) == [5, 10, 15])

Theano笔记

原文:http://www.cnblogs.com/huashiyiqike/p/3553325.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!