(1) 定义计算过程中需要的symbolic expression
""" 定义相关的symbolic experssion """ # convolution layer的输入,根据theano,它应该是一个4d tensor input = T.tensor4(name=‘input‘) # 共享权值W,它的shape为2,3,9,9 w_shp = (2,3,9,9) w_bound = numpy.sqrt(3*9*9) W = theano.shared(numpy.asarray(rng.uniform(low= -1.0/w_bound, high = 1.0/w_bound,size=w_shp),dtype=input.dtype),name=‘W‘) # 偏执向量b,它的shape为2 b_shp = (2,) b = theano.shared(numpy.asarray(rng.uniform(low= -.5, high = .5,size=b_shp),dtype=input.dtype),name=‘b‘) # 利用卷积核W对输入进行卷积运算 conv_out = conv.conv2d(input,W) # 计算sigmoid函数 output = T.nnet.sigmoid(conv_out+b.dimshuffle(‘x‘,0,‘x‘,‘x‘)) # 输入输出function f = theano.function([input],output)
原文:http://www.cnblogs.com/lutingting/p/5184539.html