Tensorflow
Welcome to the Tensorflow Tutorial! In this notebook you will learn all the basics of Tensorflow. You will implement useful functions and draw the parallel with what you did using Numpy. You will understand what Tensors and operations are, as well as how to execute them in a computation graph(欢迎来到Tensorflow教程! 在这个笔记本中,您将学习Tensorflow的所有基础知识。 你将实现有用的函数,并与使用Numpy所做的操作并行。 您将了解张量和操作是什么,以及如何在计算图中执行它们).
After completing this assignment you will also be able to implement your own deep learning models using Tensorflow. In fact, using our brand new SIGNS dataset, you will build a deep neural network model to recognize numbers from 0 to 5 in sign language with a pretty impressive accuracy(完成这项任务后,您还可以使用Tensorflow实现您自己的深度学习模型。事实上,使用我们全新的SIGNS数据集,你将建立一个深度神经网络模型来识别从0到5的数字,以一种相当令人印象深刻的准确性。).
TensorFlow Tutorial
Welcome to this week’s programming assignment. Until now, you’ve always used numpy to build neural networks. Now we will step you through a deep learning framework that will allow you to build neural networks more easily. Machine learning frameworks like TensorFlow, PaddlePaddle, Torch, Caffe, Keras, and many others can speed up your machine learning development significantly. All of these frameworks also have a lot of documentation, which you should feel free to read. In this assignment, you will learn to do the following in TensorFlow(欢迎来到本周的编程作业。到目前为止,您总是使用numpy来构建神经网络。现在我们将通过一个深度学习框架,让你更容易地建立神经网络。机器学习框架如TensorFlow,PaddlePaddle,Torch, Caffe, Keras等,可以大大加快机器学习的速度。所有这些框架都有大量的文档,您可以随意阅读。在这个作业中,您将学习在TensorFlow中执行以下操作。):
- Initialize variables(初始化变量)
- Start your own session(开始你自己的会话)
- Train algorithms(训练算法)
- Implement a Neural Network(实现神经网络)
Programing frameworks can not only shorten your coding time, but sometimes also perform optimizations that speed up your code(编程框架不仅可以缩短您的编码时间,而且有时还可以执行加速代码的优化。).
1 - Exploring the Tensorflow Library¶
To start, you will import the library:
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)
Now that you have imported the library, we will walk you through its different applications. You will start with an example, where we compute for you the loss of one training example(现在您已经导入了库,我们将介绍它的不同应用。你将从一个例子开始,在这里我们计算一个训练样本的损失。).
y_hat = tf.constant(36, name='y_hat') # Define y_hat constant. Set to 36.
y = tf.constant(39, name='y') # Define y. Set to 39
loss = tf.Variable((y - y_hat)**2, name='loss') # Create a variable for the loss
init = tf.global_variables_initializer() # When init is run later (session.run(init)),
# the loss variable will be initialized and ready to be computed
with tf.Session() as session: # Create a session and print the output
session.run(init) # Initializes the variables
print(session.run(loss)) # Prints the loss