Deep Learning Course 4
Week 1 - Convolutional Neural Networks
Step by Step
3.1 - Zero-Padding
1 | X_pad = np.pad(X, ((0, 0), (pad, pad), (pad, pad), (0,0)), mode='constant', constant_values = (0,0)) |
3.2 - Single step of convolution
1 | s = a_slice_prev * W |
3.3 - Convolutional Neural Networks - Forward pass
1 | (m, n_H_prev, n_W_prev, n_C_prev) = A_prev.shape |
4.1 - Forward Pooling
1 | for i in range(m): |
5.2 Pooling layer - backward pass
1 | mask = np.max(x) == x |
5.2.2 - Average pooling - backward pass
1 | (n_H, n_W) = shape |
5.2.3 Putting it together: Pooling backward
1 | (A_prev, hparameters) = cache |
Application
1.1 - Create placeholders
1 | X = tf.placeholder(tf.float32, shape=[None, n_H0, n_W0, n_C0]) |
1.2 - Initialize parameters
1 | W1 = tf.get_variable("W1", [4, 4, 3, 8], initializer = tf.contrib.layers.xavier_initializer(seed = 0)) |
1.3 - Forward propagation
1 | Z1 = tf.nn.conv2d(X, W1, strides = [1,1,1,1], padding = 'SAME') |
1.4 - Compute cost
1 | cost = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(logits = Z3, labels = Y)) |
1.5 Model
1 | X, Y = create_placeholders(n_H0, n_W0, n_C0, n_y) |
Week 2 - Residual Networks
2.1 - The identity block
1 | X = Conv2D(filters = F2, kernel_size = (f, f), strides = (1,1), padding = 'same', name = conv_name_base + '2b', kernel_initializer = glorot_uniform(seed=0))(X) |
2.2 - The convolutional block
1 | X = Conv2D(F2, (f, f), strides = (1,1), padding = 'same', name = conv_name_base + '2b', kernel_initializer = glorot_uniform(seed=0))(X) |
3 - Building your first ResNet model (50 layers)
1 | X = convolutional_block(X, f = 3, filters = [128, 128, 512], stage = 3, block='a', s = 2) |
Week 3 - Autonomous driving - Car detection
2.1 - Model details
1 | box_scores = np.multiply(box_confidence, box_class_probs) |
2.3 - Non-max suppression
iou
1 | xi1 = max(box1_x1, box2_x1) |
yolo_non_max_suppression
1 | nms_indices = tf.image.non_max_suppression(boxes, scores, max_boxes_tensor, iou_threshold=iou_threshold) |
2.4 Wrapping up the filtering
1 | box_confidence, box_xy, box_wh, box_class_probs = yolo_outputs |
3.5 - Run the graph on an image
1 | out_scores, out_boxes, out_classes = sess.run([scores, boxes, classes], feed_dict={yolo_model.input: image_data, K.learning_phase(): 0}) |
Week 4
Deep Learning & Art: Neural Style Transfer
3.1 - Computing the content cost
1 | a_C_unrolled = tf.transpose(a_C) |
3.2.1 - Style matrix
$$\mathbf{G}{gram} = \mathbf{A}{unrolled} \mathbf{A}_{unrolled}^T$$
1 | GA = tf.matmul(A, tf.transpose(A)) |
3.2.2 - Style cost
$$J_{style}^{[l]}(S,G) = \frac{1}{4 \times {n_C}^2 \times (n_H \times n_W)^2} \sum {i=1}^{n_C}\sum{j=1}^{n_C}(G^{(S)}{(gram)i,j} - G^{(G)}{(gram)i,j})^2\tag{2} $$
1 | m, n_H, n_W, n_C = a_G.get_shape().as_list() |
3.2.3 Style Weights
1 | J = alpha * J_content + beta * J_style |
Face Recognition
1.2 - The Triplet Loss
1 | pos_dist = tf.reduce_sum(tf.square(tf.subtract(anchor, positive)), axis=None) |
Translated by gpt-3.5-turbo