深度学习实践指南(一)—— 卷积和池化

详细信息请见 Convolutional Neural Networks (LeNet)

  • 卷积:

    from theano.tensor.nnet import conv2d
  • 池化

    from theano.tensor.signal.downsample import max_pool_2d

卷积

import numpy as np
import theano
import theano.tensor as T
from theano.tensor.nnet import conv2d

inpt = T.tensor4('inpt')

# 2: # feature maps
# 3: # color dim
# 9*9: # kernel size
W = theano.shared(np.asarray(np.random.randn(2, 3, 9, 9), dtype='float64'), name='W', borrow=True)
conv_out = conv2d(inpt, W)
f = theano.function([inpt], conv_out)

池化

import theano
import theano.tensor as T
from theano.tensor.signal import downsample

inpt = T.tensor4('inpt')
ds = (2, 2)
pool_out = downsample.max_pool_2d(inpt, ds, ignore_border=True)
f = theano.function([inpt], pool_out)

关于 max_pool_2d 的 ignore_border 参数:


深度学习实践指南(一)—— 卷积和池化_第1张图片

你可能感兴趣的:(深度学习实践指南(一)—— 卷积和池化)