当前位置:   article > 正文

Convolution Neural Network (CNN) 原理与实现_convolution neural network survey

convolution neural network survey

本文结合Deep learning的一个应用,Convolution Neural Network 进行一些基本应用,参考Lecun的Document 0.1进行部分拓展,与结果展示(in python)。

分为以下几部分:

1. Convolution(卷积)

2. Pooling(降采样过程)

3. CNN结构

4.  跑实验

下面分别介绍。


PS:本篇blog为ese机器学习短期班参考资料(20140516课程),本文只是简要讲最naive最simple的思想,重在实践部分,原理课上详述。


1. Convolution(卷积)

类似于高斯卷积,对imagebatch中的所有image进行卷积。对于一张图,其所有feature map用一个filter卷成一张feature map。 如下面的代码,对一个imagebatch(含两张图)进行操作,每个图初始有3张feature map(R,G,B), 用两个9*9的filter进行卷积,结果是,每张图得到两个feature map。

卷积操作由theano的conv.conv2d实现,这里我们用随机参数W,b。结果有点像edge detector是不是?

Code: (详见注释)


  1. # -*- coding: utf-8 -*-
  2. """
  3. Created on Sat May 10 18:55:26 2014
  4. @author: rachel
  5. Function: convolution option of two pictures with same size (width,height)
  6. input: 3 feature maps (3 channels <RGB> of a picture)
  7. convolution: two 9*9 convolutional filters
  8. """
  9. from theano.tensor.nnet import conv
  10. import theano.tensor as T
  11. import numpy, theano
  12. rng = numpy.random.RandomState(23455)
  13. # symbol variable
  14. input = T.tensor4(name = 'input')
  15. # initial weights
  16. w_shape = (2,3,9,9) #2 convolutional filters, 3 channels, filter shape: 9*9
  17. w_bound = numpy.sqrt(3*9*9)
  18. W = theano.shared(numpy.asarray(rng.uniform(low = -1.0/w_bound, high = 1.0/w_bound,size = w_shape),
  19. dtype = input.dtype),name = 'W')
  20. b_shape = (2,)
  21. b = theano.shared(numpy.asarray(rng.uniform(low = -.5, high = .5, size = b_shape),
  22. dtype = input.dtype),name = 'b')
  23. conv_out = conv.conv2d(input,W)
  24. #T.TensorVariable.dimshuffle() can reshape or broadcast (add dimension)
  25. #dimshuffle(self,*pattern)
  26. # >>>b1 = b.dimshuffle('x',0,'x','x')
  27. # >>>b1.shape.eval()
  28. # array([1,2,1,1])
  29. output &#
本文内容由网友自发贡献,转载请注明出处:https://www.wpsshop.cn/w/代码探险家/article/detail/846668
推荐阅读
相关标签
  

闽ICP备14008679号