-
大小: 3KB文件类型: .zip金币: 1下载: 0 次发布日期: 2021-06-01
- 语言: 其他
- 标签: DeepLearning
资源简介
包含:opt_utils.py,testCases.py,......亲测可用!
代码片段和文件信息
# -*- coding: utf-8 -*-
import numpy as np
import matplotlib.pyplot as plt
import sklearn
import sklearn.datasets
def sigmoid(x):
“““
Compute the sigmoid of x
Arguments:
x -- A scalar or numpy array of any size.
Return:
s -- sigmoid(x)
“““
s = 1/(1+np.exp(-x))
return s
def relu(x):
“““
Compute the relu of x
Arguments:
x -- A scalar or numpy array of any size.
Return:
s -- relu(x)
“““
s = np.maximum(0x)
return s
def load_params_and_grads(seed=1):
np.random.seed(seed)
W1 = np.random.randn(23)
b1 = np.random.randn(21)
W2 = np.random.randn(33)
b2 = np.random.randn(31)
dW1 = np.random.randn(23)
db1 = np.random.randn(21)
dW2 = np.random.randn(33)
db2 = np.random.randn(31)
return W1 b1 W2 b2 dW1 db1 dW2 db2
def initialize_parameters(layer_dims):
“““
Arguments:
layer_dims -- python array (list) containing the dimensions of each layer in our network
Returns:
parameters -- python dictionary containing your parameters “W1“ “b1“ ... “WL“ “bL“:
W1 -- weight matrix of shape (layer_dims[l] layer_dims[l-1])
b1 -- bias vector of shape (layer_dims[l] 1)
Wl -- weight matrix of shape (layer_dims[l-1] layer_dims[l])
bl -- bias vector of shape (1 layer_dims[l])
Tips:
- For example: the layer_dims for the “Planar Data classification model“ would have been [221].
This means W1‘s shape was (22) b1 was (12) W2 was (21) and b2 was (11). Now you have to generalize it!
- In the for loop use parameters[‘W‘ + str(l)] to access Wl where l is the iterative integer.
“““
np.random.seed(3)
parameters = {}
L = len(layer_dims) # number of layers in the network
for l in range(1 L):
parameters[‘W‘ + str(l)] = np.random.randn(layer_dims[l] layer_dims[l-1])* np.sqrt(2 / layer_dims[l-1])
parameters[‘b‘ + str(l)] = np.zeros((layer_dims[l] 1))
assert(parameters[‘W‘ + str(l)].shape == layer_dims[l] layer_dims[l-1])
assert(parameters[‘W‘ + str(l)].shape == layer_dims[l] 1)
return parameters
def forward_propagation(X parameters):
“““
Implements the forward propagation (and computes the loss) presented in Figure 2.
Arguments:
X -- input dataset of shape (input size number of examples)
parameters -- python dictionary containing your parameters “W1“ “b1“ “W2“ “b2“ “W3“ “b3“:
W1 -- weight matrix of shape ()
b1 -- bias vector of shape ()
W2 -- weight matrix of shape ()
b2 -- bias vector of shape ()
W3 -- weight matrix of shape ()
b3 -- bias vector of sha
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 3259 2018-04-10 19:51 testCases.py
文件 7707 2018-04-11 21:41 opt_utils.py
评论
共有 条评论