完整实现多层神经网络识别图片中的猫
原coursera课程主页,在网易云课堂中也有课程资源不过没有编程练习。
本次编程利用上次作业中完成的各个函数,完整实现一个多层神经网络,进过训练来识别图片中是否有猫。
代码及训练测试数据下载
代码中没注释,不过coursera里的解释很详细。
import time
import numpy as np
import h5py
import matplotlib.pyplot as plt
import scipy
from PIL import Image
from scipy import ndimage
from dnn_app_utils_v2 import *
plt.rcParams['figure.figsize'] = (5.0, 4.0) # set default size of plots
plt.rcParams['image.interpolation'] = 'nearest'
plt.rcParams['image.cmap'] = 'gray'
np.random.seed(1)
train_x_orig,train_y,test_x_orig,test_y,classes=load_dataset()
'''
index=11
plt.imshow(train_x_orig[index])
print('y='+str(train_y[0,index])+",It's a "+classes[train_y[0,index]].decode('utf-8')+' picture.')
plt.show()
'''
m_train=train_x_orig.shape[0]
num_px=train_x_orig.shape[1]
m_test=test_x_orig.shape[0]
print ("Number of training examples: " + str(m_train))