# 深度学习算法实践11---卷积神经网络（CNN）之卷积操作

式3

式4

式5

import theano
from theano import tensor as T
from theano.tensor.nnet import conv2d
import numpy
from matplotlib import pylab
from PIL import Image

def conv_wky():
rng = numpy.random.RandomState(23455)
input = T.tensor4(name='input')
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_shp = (2,)
b = theano.shared(numpy.asarray(
rng.uniform(low=-.5, high=.5, size=b_shp),
dtype=input.dtype), name ='b')
conv_out = conv2d(input, W)
output = T.nnet.sigmoid(conv_out + b.dimshuffle('x', 0, 'x', 'x'))
return theano.function([input], output)

def do_conv():
f = conv_wky()
img = Image.open(open('3wolfmoon.jpg', 'rb'))
img = numpy.asarray(img, dtype='float64') / 256.
img_ = img.transpose(2, 0, 1).reshape(1, 3, 639, 516)
filtered_img = f(img_)
pylab.subplot(1, 3, 1); pylab.axis('off'); pylab.imshow(img)
pylab.gray()
pylab.subplot(1, 3, 2); pylab.axis('off'); pylab.imshow(filtered_img[0, 0, :, :])
pylab.subplot(1, 3, 3); pylab.axis('off'); pylab.imshow(filtered_img[0, 1, :, :])
pylab.show()

if __name__ == '__main__':
do_conv()

#### 深度学习中的卷积计算及caffe的实现

2017-11-17 09:09:55

#### 深度学习中的卷积与反卷积

2017-07-16 16:31:00

#### 卷积神经网络CNN原理以及TensorFlow实现

2017-04-27 23:10:10

#### Tensorflow卷积实现原理+手写python代码实现卷积

2018-01-21 17:30:50

#### 深度学习笔记4：卷积层的实现

2016-08-18 14:02:19

#### 深度学习(DL)与卷积神经网络(CNN)学习笔记随笔-02-基于Python的卷积运算

2015-08-27 12:41:02

#### 卷积神经网络CNN、caffe_Blob（improving）

2016-12-13 12:37:28

#### DeepLearning tutorial（4）CNN卷积神经网络原理简介+代码详解

2015-01-28 07:48:28

#### Deep Learning（深度学习）学习笔记整理系列之（三）

2013-04-09 00:37:38

#### 深度学习之卷积神经网络CNN及tensorflow代码实现示例

2017-05-01 13:28:21