神经网络——吴恩达第一次作业

题目要求:构建一个单结点的神经网络,能够识别64*64的cat图片。其中训练集在train_catvnoncat中,测试集在test_catvnoncat中。

所需资源和包:
链接: https://pan.baidu.com/s/1pslul3qqeU2QvKptTtEOhQ 提取码: 348w
解答:

一:前提准备

1:首先数据是以.h5的形式进行存储,熟悉h5的操作

#测试H5的属性
f = h5py.File('./test_catvnoncat.h5','r')
f.keys() #可以查看所有的主键
print([key for key in f.keys()])

print('first, we get values of x:', f['list_classes'][:])#
print('****************************************************\n')
print('then, we get values of y:', f['test_set_x'][:])
print('****************************************************\n')
print('then, we get values of y:', f['test_set_y'][:])

print(f['test_set_x'][:].shape)
print(f['test_set_y'][:].shape)

2:从数据集从挑选一张图片进行展示

#展示图片
train_dataset = h5py.File('./train_catvnoncat.h5', "r")#matlab文件
train_set_x_orig = np.array(train_dataset["train_set_x"][:]) # your train set features
index = 24
plt.imshow(train_set_x_orig[index])
plt.show()
print("this is picture")

3:查看数据集的维度等信息

#测试图片的数量
train_dataset = h5py.File('./train_catvnoncat.h5', "r")#matlab文件
train_set_x = np.array(train_dataset["train_set_x"][:]) # your train set features
train_set_y = np.array(train_dataset["train_set_y"][:]) # your train set labels

test_dataset = h5py.File('./test_catvnoncat.h5', "r")
test_set_x = np.array(test_dataset["test_set_x"][:]) # your test set features
test_set_y = np.array(test_dataset["test_set_y"][:]) # your test set labels

#shape表示所有维,shape[i]表示第i维
m_train = train_set_x.shape[0] #训练集里图片的数量。
m_test = test_set_x.shape[0] #测试集里图片的数量。
num_px = train_set_x.shape[1] #训练、测试集里面的图片的宽度和高度(均为64x64)。

#现在看一看我们加载的东西的具体情况
print ("训练集的数量: m_train = " + str(m_train))
print ("测试集的数量 : m_test = " + str(m_test))
print ("每张图片的宽/高 : num_px = " + str(
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值