本文章内容:
Coursera吴恩达深度学习课程,
第四课: 卷积神经网络(Convolutional Neural Networks)
第一周: 卷积神经网络(Foundations of Convolutional Neural Networks)
编程作业,记错本。
Convolutional Neural Networks: Application
you will:
- Implement helper functions that you will use when implementing a TensorFlow model
- Implement a fully functioning ConvNet using TensorFlow
- Build and train a ConvNet in TensorFlow for a classification problem
1.0 - TensorFlow model
1.1 - Create placeholders
TensorFlow requires that you create placeholders for the input data that will be fed into the model when running the session.
X = tf.placeholder(tf.float32, shape=[None, n_H0, n_W0, n_C0])
Y = tf.placeholder(tf.float32, shape=[None, n_y])
1.2 - Initialize parameters
You will initialize weights/filters W1W1 and W2W2 using tf.contrib.layers.xavier_initializer(seed = 0)
. You don't need to worry about bias variables as you will soon see that TensorFlow functions take care of the bias.
Note also that you will only initialize the weights/filters for the conv2d functions.
TensorFlow initializes the layers for the fully connected part automatically.
W1 = tf.get_variable("W1",[4,4,3,8],initializer = tf.contrib.layers.xavier_initializer(seed = 0) )
W2 = tf.get_variable('W2',[2, 2, 8, 16],initializer=tf.contrib.layers.xavier_initializer(seed = 0) )
1.2 - Forward propagation
In TensorFlow, there are built-in functions that carry out the convolution steps for you.
-
tf.nn.conv2d(X,W1, strides = [1,s,s,1], padding = 'SAME'): given an input XX and