吴恩达深度学习1-Week4课后作业-深层神经网络

这篇博客详细介绍了吴恩达深度学习课程第4周的作业,涉及使用深层神经网络对catvnoncat.h5数据集进行学习和预测。作者通过构建2层和L层神经网络,展示了前向传播和反向传播的过程,并提供了相关代码,加深了对深度学习模型的理解。
摘要由CSDN通过智能技术生成

一、Deeplearning-assignment

在本周作业的编程中,主要通过构建两层神经网络和L层神经网络对catvnoncat.h5数据集进行学习和预测,并得到对test数据集的预测准确度以及判断一张图片是否为猫。

在前面的作业中,我们通过逻辑回归模型对该数据集进行了学习和预测,准确度为70%(可以翻看之前的博客和参阅相关代码结果),今天主要构建深层神经网络对数据集进行学习。

由上图可以看出,输入X中的每一列是一个(64 * 64 * 3,1)的列向量,即(12288,1)。

2层神经网络结构图:

从图中我们可以看到,首先喂入一个X,通过线性运算得到Z1,接着通过非线性激活函数RELU得到A1,并作为输入赋给第二层,同样通过线性运算得到Z2,最后通过sigmoid函数得到预测值A2,完成前向传播过程。

L层神经网络结构图:

与2层神经网络类似,L层神经网络的前向传播是进行L - 1次(线性运算+RELU),最后通过sigmoid得到预测值。

下面看看代码。


二、相关算法代码

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_data()
# index = 7
# plt.imshow(train_x_orig[index])
# plt.show()
# print("y = " + str(train_y[0, index]) + ". It's a " +
#       classes[train_y[0, index]].decode("utf-8") + " picture.")

# 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))
# print("Number of testing examples: " + str(m_test))
# print("Each image is of size: (" + str(num_px) + ", " + str(num_px) + ", 3)")
# print("train_x_orig shape: " + str(train_x_orig.shape))
# print("train_y 
  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值