实验说明
本实验为吴恩达课后编程作业第二课第三周内容,通过引导我们将完成一个深度学习框架,使我们可以更轻松地构建神经网络。编程框架不仅可以缩短编码时间,而且有时还可以执行加速代码的优化。
数据集下载地址:[https://github.com/stormstone/deeplearning.ai/tree/c38b8ea7cc7fef5caf88be6e06f4e3452690fde7]
工具:Jupyter Notebook (tensorflow) + Python 3.6.3
问题陈述:一天下午,我和一些朋友决定教我们的电脑破译手语。 我们花了几个小时在白墙前拍照,想出了以下数据集。 现在,您的工作是构建一种算法,以促进从语言障碍者到不懂手语的人的通信。
训练集:1080个图像(64乘64像素)的符号表示从0到5的数字(每个数字180个图像)。
测试集:120张图片(64乘64像素)的符号,表示从0到5的数字(每个数字20张图片)。
以下是每个数字的示例,以及如何解释我们如何表示标签。 在我们将图像重新降低到64 x 64像素之前,这些是原始图片。
1、Exploring the Tensorflow Library
1.1 首先导入库:
import math
import numpy as np
import h5py
import matplotlib.pyplot as plt
import tensorflow as tf
from tensorflow.python.framework import ops
from tf_utils import load_dataset, random_mini_batches, convert_to_one_hot, predict
%matplotlib inline
np.random.seed(1)
1.2 加载数据集:
X_train_orig, Y_train_orig, X_test_orig, Y_test_orig, classes = load_dataset()
print(X_train_orig.shape)
print(Y_train_orig.shape)
print(X_test_orig.shape)
print(Y_test_orig.shape)
运行结果展示:
1.3 图片示例
index = 2
plt.imshow(X_train_orig[index])
print ("y = " + str(np.squeeze(Y_train_orig[:, index])))
运行结果展示:
1.4 输出数据集信息
# Flatten the training and test images
X_train_flatten = X_train_orig.reshape(X_train_orig.shape[0], -1).T
X_test_flatten = X_test_orig.reshape(X_test_orig.shape[0], -1).T
# Normalize image vectors
X_train = X_train_flatten/255.
X_test = X_test_flatten/255.
# Convert training and test labels to one hot matrices
Y_train = convert_to_one_hot(Y_train_orig, 6)
Y_test = convert_to_one_hot(Y_test_orig, 6)
print ("number of training examples = " + str(X_train.shape[1]))
print ("number of test examples = " + str(X_test.shape[1]))
print ("X_train shape: " + str(X_train.shape))
print ("Y_train shape: " + str(Y_train.shape))
print ("X_test shape: " + str(X_test.shape))
print ("Y_test shape: " + str(Y_test.shape))
print(Y_test_orig[0][9])
print(Y_test_orig[0][8])
print(Y_test_orig[0][7])
print(Y_test_orig[0][6]