資源簡介
coursera的吳恩達的課編程練習所需的所需包和數據,可以方便學員自己在本地練習

代碼片段和文件信息
import?numpy?as?np
import?matplotlib.pyplot?as?plt
import?h5py
def?sigmoid(Z):
????“““
????Implements?the?sigmoid?activation?in?numpy
????
????Arguments:
????Z?--?numpy?array?of?any?shape
????
????Returns:
????A?--?output?of?sigmoid(z)?same?shape?as?Z
????cache?--?returns?Z?as?well?useful?during?backpropagation
????“““
????
????A?=?1/(1+np.exp(-Z))
????cache?=?Z
????
????return?A?cache
def?relu(Z):
????“““
????Implement?the?RELU?function.
????Arguments:
????Z?--?Output?of?the?linear?layer?of?any?shape
????Returns:
????A?--?Post-activation?parameter?of?the?same?shape?as?Z
????cache?--?a?python?dictionary?containing?“A“?;?stored?for?computing?the?backward?pass?efficiently
????“““
????
????A?=?np.maximum(0Z)
????
????assert(A.shape?==?Z.shape)
????
????cache?=?Z?
????return?A?cache
def?relu_backward(dA?cache):
????“““
????Implement?the?backward?propagation?for?a?single?RELU?unit.
????Arguments:
????dA?--?post-activation?gradient?of?any?shape
????cache?--?‘Z‘?where?we?store?for?computing?backward?propagation?efficiently
????Returns:
????dZ?--?Gradient?of?the?cost?with?respect?to?Z
????“““
????
????Z?=?cache
????dZ?=?np.array(dA?copy=True)?#?just?converting?dz?to?a?correct?object.
????
????#?When?z?<=?0?you?should?set?dz?to?0?as?well.?
????dZ[Z?<=?0]?=?0
????
????assert?(dZ.shape?==?Z.shape)
????
????return?dZ
def?sigmoid_backward(dA?cache):
????“““
????Implement?the?backward?propagation?for?a?single?SIGMOID?unit.
????Arguments:
????dA?--?post-activation?gradient?of?any?shape
????cache?--?‘Z‘?where?we?store?for?computing?backward?propagation?efficiently
????Returns:
????dZ?--?Gradient?of?the?cost?with?respect?to?Z
????“““
????
????Z?=?cache
????
????s?=?1/(1+np.exp(-Z))
????dZ?=?dA?*?s?*?(1-s)
????
????assert?(dZ.shape?==?Z.shape)
????
????return?dZ
def?load_data():
????train_dataset?=?h5py.File(‘datasets/train_catvnoncat.h5‘?“r“)
????train_set_x_orig?=?np.array(train_dataset[“train_set_x“][:])?#?your?train?set?features
????train_set_y_orig?=?np.array(train_dataset[“train_set_y“][:])?#?your?train?set?labels
????test_dataset?=?h5py.File(‘datasets/test_catvnoncat.h5‘?“r“)
????test_set_x_orig?=?np.array(test_dataset[“test_set_x“][:])?#?your?test?set?features
????test_set_y_orig?=?np.array(test_dataset[“test_set_y“][:])?#?your?test?set?labels
????classes?=?np.array(test_dataset[“list_classes“][:])?#?the?list?of?classes
????
????train_set_y_orig?=?train_set_y_orig.reshape((1?train_set_y_orig.shape[0]))
????test_set_y_orig?=?test_set_y_orig.reshape((1?test_set_y_orig.shape[0]))
????
????return?train_set_x_orig?train_set_y_orig?test_set_x_orig?test_set_y_orig?classes
def?initialize_parameters(n_x?n_h?n_y):
????“““
????Argument:
????n_x?--?size?of?the?input?layer
????n_h?--?size?of?the?hidden?layer
????n_y?--?size?of?the?output?layer
????
????Returns:
????parameters?--?python?dictionary?containing?your?parameters:
????????????????????W1?--?weight?matrix?of?shape?(n_h?n_x)
????????????????????b1?--?bias?vector?of?shape
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2017-08-27?19:55??datasets\
?????文件?????2572022??2017-08-27?19:55??datasets\train_catvnoncat.h5
?????文件??????616958??2017-08-27?19:55??datasets\test_catvnoncat.h5
?????文件???????14776??2017-08-27?19:55??dnn_app_utils_v2.py
評論
共有 條評論