基本信息
源码名称:吴恩达 Programming Assignments of Deep Learning Sp.pdf
源码大小:23.45M
文件格式:.pdf
开发语言:Python
更新时间:2020-05-09
友情提示:(无需注册或充值,赞助后即可获取资源下载链接)
嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300
本次赞助数额为: 2 元×
微信扫码支付:2 元
×
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
源码介绍
Contents 1 Neural Networks and Deep Learning 1 1.1 Python Basics with numpy (optional) . . . . . . . . . . . . . . . . . . . . 1 1.1.1 About iPython Notebooks . . . . . . . . . . . . . . . . . . . . . . . 1 1.1.2 Building basic functions with numpy . . . . . . . . . . . . . . . . . 2 1.1.2.1 sigmoid function, np.exp() . . . . . . . . . . . . . . . . . 2 1.1.2.2 Sigmoid gradient . . . . . . . . . . . . . . . . . . . . . . . 4 1.1.2.3 Reshaping arrays . . . . . . . . . . . . . . . . . . . . . . . 5 1.1.2.4 Normalizing rows . . . . . . . . . . . . . . . . . . . . . . 6 1.1.2.5 Broadcasting and the softmax function . . . . . . . . . . 7 1.1.3 Vectorization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 1.1.3.1 Implement the L1 and L2 loss functions . . . . . . . . . . 12 1.2 Logistic Regression with a Neural Network mindset . . . . . . . . . . . . . 14 1.2.1 Packages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 1.2.2 Overview of the Problem set . . . . . . . . . . . . . . . . . . . . . 15 1.2.3 General Architecture of the learning algorithm . . . . . . . . . . . 18 1.2.4 Building the parts of our algorithm . . . . . . . . . . . . . . . . . . 19 1.2.4.1 Helper functions . . . . . . . . . . . . . . . . . . . . . . . 19 1.2.4.2 Initializing parameters . . . . . . . . . . . . . . . . . . . . 19 1.2.4.3 Forward and Backward propagation . . . . . . . . . . . . 20 1.2.4.4 Optimization . . . . . . . . . . . . . . . . . . . . . . . . . 21 1.2.5 Merge all functions into a model . . . . . . . . . . . . . . . . . . . 25 1.2.6 Further analysis (optional/ungraded exercise) . . . . . . . . . . . . 28 1.2.7 Test with your own image (optional/ungraded exercise) . . . . . . 30 1.2.8 Code of Logistic Regression with a Neural Network . . . . . . . . . 31 1.3 Planar data classification with a hidden layer . . . . . . . . . . . . . . . . 37 1.3.1 Packages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37 1.3.2 Dataset . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38 1.3.3 Simple Logistic Regression . . . . . . . . . . . . . . . . . . . . . . . 39 1.3.4 Neural Network model . . . . . . . . . . . . . . . . . . . . . . . . . 40 1.3.4.1 Defining the neural network structure . . . . . . . . . . . 41 1.3.4.2 Initialize the model’s parameters . . . . . . . . . . . . . . 42 1.3.4.3 The Loop . . . . . . . . . . . . . . . . . . . . . . . . . . . 43 1.3.4.4 Integrate parts 1.3.4.1, 1.3.4.2 and 1.3.4.3 in nn_model() 48 1.3.4.5 Tuning hidden layer size (optional/ungraded exercise) . . 51 1.3.5 Code of Neural Network With a Hidden Layer . . . . . . . . . . . 54 1.4 Building your Deep Neural Network: Step by Step . . . . . . . . . . . . . 61 1.4.1 Packages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61 1.4.2 Outline of the Assignment . . . . . . . . . . . . . . . . . . . . . . . 62 1.4.3 Initialization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63 1.4.3.1 2-layer Neural Network . . . . . . . . . . . . . . . . . . . 63 1.4.3.2 L-layer Neural Network . . . . . . . . . . . . . . . . . . . 64 1.4.4 Forward propagation module . . . . . . . . . . . . . . . . . . . . . 66 1.4.4.1 Linear Forward . . . . . . . . . . . . . . . . . . . . . . . . 66 1.4.4.2 Linear-Activation Forward . . . . . . . . . . . . . . . . . 67 1.4.4.3 L-Layer Model . . . . . . . . . . . . . . . . . . . . . . . . 68 1.4.5 Cost function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70 1.4.6 Backward propagation module . . . . . . . . . . . . . . . . . . . . 71 1.4.6.1 Linear backward . . . . . . . . . . . . . . . . . . . . . . . 71 1.4.6.2 Linear-Activation backward . . . . . . . . . . . . . . . . . 73 1.4.6.3 L-Model Backward . . . . . . . . . . . . . . . . . . . . . . 74 1.4.6.4 Update Parameters . . . . . . . . . . . . . . . . . . . . . 76 1.4.6.5 Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . 77 1.4.7 Code of Deep Neural Network . . . . . . . . . . . . . . . . . . . . . 78 1.5 Deep Neural Network for Image Classification: Application . . . . . . . . 86 1.5.1 Packages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86 1.5.2 Dataset . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87 1.5.3 Architecture of your model . . . . . . . . . . . . . . . . . . . . . . 88 1.5.3.1 2-layer neural network . . . . . . . . . . . . . . . . . . . . 88 1.5.3.2 L-layer deep neural network . . . . . . . . . . . . . . . . 89 1.5.3.3 General methodology . . . . . . . . . . . . . . . . . . . . 90 1.5.4 Two-layer neural network . . . . . . . . . . . . . . . . . . . . . . . 90 1.5.5 L-layer Neural Network . . . . . . . . . . . . . . . . . . . . . . . . 94 1.5.6 Results Analysis . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97 1.5.7 Test with your own image (optional/ungraded exercise) . . . . . . 97 1.5.8 Code of Deep Neural Network for Image Classification: Application 99 2 Improving Deep Neural Networks: Hyperparameter tuning, Regularization and Optimization 104 2.1 Practical aspects of Deep Learning . . . . . . . . . . . . . . . . . . . . . . 104 2.1.1 Initialization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104 2.1.1.1 Packages . . . . . . . . . . . . . . . . . . . . . . . . . . . 105 2.1.1.2 Neural Network model . . . . . . . . . . . . . . . . . . . . 105 2.1.1.3 Zero initialization . . . . . . . . . . . . . . . . . . . . . . 107 2.1.1.4 Random initialization . . . . . . . . . . . . . . . . . . . . 111 2.1.1.5 He initialization . . . . . . . . . . . . . . . . . . . . . . . 114 2.1.1.6 Conclusions . . . . . . . . . . . . . . . . . . . . . . . . . . 117 2.1.1.7 Code of initialization . . . . . . . . . . . . . . . . . . . . 118 2.1.2 Regularization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123 2.1.2.1 Non-regularized model . . . . . . . . . . . . . . . . . . . . 124 2.1.2.2 L2 Regularization . . . . . . . . . . . . . . . . . . . . . . 128 2.1.2.3 Dropout . . . . . . . . . . . . . . . . . . . . . . . . . . . 133 2.1.2.4 Conclusions . . . . . . . . . . . . . . . . . . . . . . . . . . 139 2.1.3 Gradient Checking . . . . . . . . . . . . . . . . . . . . . . . . . . . 140 2.1.3.1 How does gradient checking work? . . . . . . . . . . . . . 140 2.1.3.2 1-dimensional gradient checking . . . . . . . . . . . . . . 141 2.1.3.3 N-dimensional gradient checking . . . . . . . . . . . . . . 144 2.2 Optimization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151 2.2.1 Packages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151 2.2.2 Gradient Descent . . . . . . . . . . . . . . . . . . . . . . . . . . . . 152 2.2.3 Mini-Batch Gradient descent . . . . . . . . . . . . . . . . . . . . . 155 2.2.4 Momentum . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 158 2.2.5 Adam . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 161 2.2.6 Model with different optimization algorithms . . . . . . . . . . . . 165 2.2.6.1 Mini-batch Gradient descent . . . . . . . . . . . . . . . . 168 2.2.6.2 Mini-batch gradient descent with momentum . . . . . . . 169 2.2.6.3 Mini-batch with Adam mode . . . . . . . . . . . . . . . . 170 2.2.6.4 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . 172 2.3 Tensorflow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 173 2.3.1 Exploring the Tensorflow Library . . . . . . . . . . . . . . . . . . . 173 2.3.1.1 Linear function . . . . . . . . . . . . . . . . . . . . . . . . 175 2.3.1.2 Computing the sigmoid . . . . . . . . . . . . . . . . . . . 176 2.3.1.3 Computing the Cost . . . . . . . . . . . . . . . . . . . . . 178 2.3.1.4 Using One Hot encodings . . . . . . . . . . . . . . . . . . 179 2.3.1.5 Initialize with zeros and ones . . . . . . . . . . . . . . . . 180 2.3.2 Building your first neural network in tensorflow . . . . . . . . . . . 181 2.3.2.1 Problem statement: SIGNS Dataset . . . . . . . . . . . . 182 2.3.2.2 Create placeholders . . . . . . . . . . . . . . . . . . . . . 184 2.3.2.3 Initializing the parameters . . . . . . . . . . . . . . . . . 185 2.3.2.4 Forward propagation in tensorflow . . . . . . . . . . . . . 186 2.3.2.5 Compute cost . . . . . . . . . . . . . . . . . . . . . . . . 187 2.3.2.6 Backward propagation & parameter updates . . . . . . . 189 2.3.2.7 Building the model . . . . . . . . . . . . . . . . . . . . . 189 2.3.2.8 Test with your own image (optional / ungraded exercise) 193 2.3.2.9 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . 194 3 Convolutional Neural Networks 195 3.1 Convolutional Neural Networks: Step by Step . . . . . . . . . . . . . . . . 195 3.1.1 Packages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 195 3.1.2 Outline of the Assignment . . . . . . . . . . . . . . . . . . . . . . . 196 3.1.3 Convolutional Neural Networks . . . . . . . . . . . . . . . . . . . . 196 3.1.3.1 Zero-Padding . . . . . . . . . . . . . . . . . . . . . . . . . 197 3.1.3.2 Single step of convolution . . . . . . . . . . . . . . . . . . 199 3.1.3.3 Convolutional Neural Networks - Forward pass . . . . . . 201 3.1.4 Pooling layer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 204 3.1.4.1 Forward Pooling . . . . . . . . . . . . . . . . . . . . . . . 205 3.1.5 Backpropagation in convolutional neural networks (OPTIONAL / UNGRADED) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 206 3.1.5.1 Convolutional layer backward pass . . . . . . . . . . . . . 207 3.1.5.2 Pooling layer - backward pass . . . . . . . . . . . . . . . 210 3.2 Convolutional Neural Networks: Application . . . . . . . . . . . . . . . . 215 3.2.1 TensorFlow model . . . . . . . . . . . . . . . . . . . . . . . . . . . 215 3.2.2 Create placeholders . . . . . . . . . . . . . . . . . . . . . . . . . . 217 3.2.3 Initialize parameters . . . . . . . . . . . . . . . . . . . . . . . . . . 218 3.2.4 Forward propagation . . . . . . . . . . . . . . . . . . . . . . . . . . 219 3.2.5 Compute cost . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 221 3.2.6 Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 221 3.3 Keras Tutorial - The Happy House (not graded) . . . . . . . . . . . . . . 226 3.3.1 The Happy House . . . . . . . . . . . . . . . . . . . . . . . . . . . 226 3.3.2 Building a model in Keras . . . . . . . . . . . . . . . . . . . . . . . 228 3.3.3 Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 233 3.3.4 Test with your own image (Optional) . . . . . . . . . . . . . . . . 234 3.3.5 Other useful functions in Keras (Optional) . . . . . . . . . . . . . 235 3.4 Residual Networks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 237 3.4.1 The problem of very deep neural networks . . . . . . . . . . . . . . 237 3.4.2 Building a Residual Network . . . . . . . . . . . . . . . . . . . . . 238 3.4.2.1 The identity block . . . . . . . . . . . . . . . . . . . . . . 239 3.4.2.2 The convolutional block . . . . . . . . . . . . . . . . . . . 242 3.4.3 Building your first ResNet model (50 layers) . . . . . . . . . . . . . 245 3.4.4 Test on your own image (Optional/Ungraded) . . . . . . . . . . . . 250 3.5 Car detection with YOLOv2 . . . . . . . . . . . . . . . . . . . . . . . . . . 253 3.5.1 Problem Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . 254 3.5.2 YOLO . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 255 3.5.2.1 Model details . . . . . . . . . . . . . . . . . . . . . . . . . 255 3.5.2.2 Filtering with a threshold on class scores . . . . . . . . . 258 3.5.2.3 Non-max suppression . . . . . . . . . . . . . . . . . . . . 260 3.5.2.4 Wrapping up the filtering . . . . . . . . . . . . . . . . . . 263 3.5.3 Test YOLO pretrained model on images . . . . . . . . . . . . . . . 265 3.5.3.1 Defining classes, anchors and image shape . . . . . . . . . 265 3.5.3.2 Loading a pretrained model . . . . . . . . . . . . . . . . . 265 3.5.3.3 Convert output of the model to usable bounding box tensors266 3.5.3.4 Filtering boxes . . . . . . . . . . . . . . . . . . . . . . . . 266 3.5.3.5 Run the graph on an image . . . . . . . . . . . . . . . . . 267 3.6 Face Recognition for the Happy House . . . . . . . . . . . . . . . . . . . . 271 3.6.1 Naive Face Verification . . . . . . . . . . . . . . . . . . . . . . . . . 272 3.6.2 Encoding face images into a 128-dimensional vector . . . . . . . . 273 3.6.2.1 Using an ConvNet to compute encodings . . . . . . . . . 273 3.6.2.2 The Triplet Loss . . . . . . . . . . . . . . . . . . . . . . . 274 3.6.3 Loading the trained model . . . . . . . . . . . . . . . . . . . . . . . 276 3.6.4 Applying the model . . . . . . . . . . . . . . . . . . . . . . . . . . 277 3.6.4.1 Face Verification . . . . . . . . . . . . . . . . . . . . . . . 277 3.6.4.2 Face Recognition . . . . . . . . . . . . . . . . . . . . . . . 280 3.7 Art generation with Neural Style Transfer . . . . . . . . . . . . . . . . . . 283 3.7.1 Problem Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . 283 3.7.2 Transfer Learning . . . . . . . . . . . . . . . . . . . . . . . . . . . 284 3.7.3 Neural Style Transfer . . . . . . . . . . . . . . . . . . . . . . . . . 284 3.7.3.1 Computing the content cost . . . . . . . . . . . . . . . . . 284 3.7.3.2 Computing the style cost . . . . . . . . . . . . . . . . . . 287 3.7.3.3 Defining the total cost to optimize . . . . . . . . . . . . . 292 3.7.4 Solving the optimization problem . . . . . . . . . . . . . . . . . . . 292 3.7.5 Test with your own image (Optional/Ungraded) . . . . . . . . . . 298 3.7.6 Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 299