TensorFlow (4-2) TensorFlow CNN Functions
1. Using TensorFlow to construct a CNN :
來介紹一些 CNN 會用到的 TensorFlow Functions 和一些有的沒的。
2. 輸入:
對一 CNN 的輸入要先定義輸入的下列參數:
- w: the width of the input.
- h: the height of the input.
- d: the depth of the input.
- p: the size of the padding of the input(zero padding).
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgDizSNLDlGsLteN8dhgVrIJYJakeVAVXrN32se6O01BdwliVNkgOau72XpMVy-gaBVm2E31PEi4t6WsIQ63AhyphenhyphenHXk1tuXQIUb7jcQsON4m3fxwdEx7tpG1Vms3gcvZSDU94YkTdiLzVJ8/s200/2018-04-30+14-57-41+%25E7%259A%2584%25E8%259E%25A2%25E5%25B9%2595%25E6%2593%25B7%25E5%259C%2596.png)
3. Filter, Spatial Extent and Stride:
- Filter: 捲積的 mask。
- The spatial extent e, which is equal to the filter's height and width.
- The stride means the distance between consecutive applications of the filter on the input volume.
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjuDoGwRPfoWo6X96iMxzbjTmZ0c8ZpdTEfuDBlrHSMOZgWxinkeOxpeU9msrlnWxblzdZFeS1CmK8fB6Gw7iIH2rHYrAC7Saf-5jwtu-roU0UTFEK43j8zPGtIxKfvw94jCUqNS4NGkh4/s200/2018-04-30+15-04-43+%25E7%259A%2584%25E8%259E%25A2%25E5%25B9%2595%25E6%2593%25B7%25E5%259C%2596.png)
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgtFS1ZU1aAEZdd9qNvlBaiM9cKDUhZFZbfD-jMtlcbpFrhYtOliP7Np3mgz-bYgmwXsbUpP37uJe6EIRgXGNpy0IBDE4YlMiJvY_fMuWZAtJzmIiJim_4QzDxlebuyEIMxp-fAOBSJC6U/s640/2018-04-30+15-06-25+%25E7%259A%2584%25E8%259E%25A2%25E5%25B9%2595%25E6%2593%25B7%25E5%259C%2596.png)
4. 舉個實際的例子
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjlq0XbfPerGsmFppQShGguylU0o-pbrHpRFYyjU-Xi-30gq8sMJjFcbHxbq0979PW5xnhyphenhyphen9HyZkH0j-oZJfCcN5N3RKXB8pKJc454hnrpjUMG-RafvsFoJaMHc7k4IoG_k-yijk19LOIc/s640/2018-04-30+15-07-50+%25E7%259A%2584%25E8%259E%25A2%25E5%25B9%2595%25E6%2593%25B7%25E5%259C%2596.png)
5. Convolution with Tensorflow Function:
tf.nn.conv2d(x, W, strides=[1, 1, 1, 1], padding='SAME')
- x: a four-dimensional tensor of size N × h × w × d.
- W: a four-dimensional tensor of size e × e × d × k.
- strides: a list of ints. 1-D tensor of length 4. The stride of the sliding window for each dimension of input.
- padding: setting padding to 'SAME' means that the borders of x are padded such that the size of the result of the operation is the same as the size of x.
6. Pooling with Tensorflow Function:
tf.nn.max_pool(x, ksize=[1, 2, 2, 1], strides=[1, 2, 2, 1], padding='SAME')
- x: a four-dimensional tensor of size N × h × w × d.
- ksize: a 1-D int Tensor of 4 elements. The size of the window for each dimension of the input tensor.
- strides: A 1-D int Tensor of 4 elements. The stride of the sliding window for each dimension of the input tensor.
- padding: A string, either 'VALID' or 'SAME'.
Reference
[1] Tom Hope, Yehezkel S. Resheff, and Itay Lieder, Learning TensorFlow A Guide to Building Deep Learning Systems , O'Reilly Media (2017)
[2] Nikhil Buduma, Fundamentals of Deep Learning Designing Next-Generation Machine Intelligence Algorithms, O'Reilly Media (2017)
[3] Aurélien Géron, Hands-On Machine Learning with Scikit-Learn and TensorFlow Concepts, Tools, and Techniques to Build Intelligent Systems , O'Reilly Media (2017)
留言
張貼留言