The gradient concept is used in the back propagation process to update network weights so it can learn to generate better outputs. If you're not familiar with the back propagation process, one of the most fundamental and powerful algorithms in neural networks, you should definitely spend some time understanding it – just Google "backprop" and the top five results won't disappoint. Vanishing gradient means that, during the deep neural network back propagation learning process, network weights in earlier layers barely get updated so the network never converges; exploding gradient means that those weights get updated too wildly, causing the network to diverge a lot. So, if someone has a closed mind and never learns, or if someone gets crazy about new things as fast as he loses interest, you know what kind of gradient problem they seem to have.
The gradient concept is used in the back propagation process to update network weights so it can learn to generate better outputs. If you're not familiar with the back propagation process, one of the most fundamental and powerful algorithms in neural networks, you should definitely spend some time understanding it – just Google "backprop" and the top five results won't disappoint. Vanishing gradient means that, during the deep neural network back propagation learning process, network weights in earlier layers barely get updated so the network never converges; exploding gradient means that those weights get updated too wildly, causing the network to diverge a lot. So, if someone has a closed mind and never learns, or if someone gets crazy about new things as fast as he loses interest, you know what kind of gradient problem they seem to have.
...
@@ -46,7 +46,7 @@ The gradient concept is used in the back propagation process to update network w
...
@@ -46,7 +46,7 @@ The gradient concept is used in the back propagation process to update network w
在本部分中,我们将首先总结训练训练名为 im2txt 的 Show and Tell 模型的过程,该模型记录在[https://github.com/tensorflow/models/tree/master/research/im2txt](https://github.com/tensorflow/models/tree/master/research/im2txt)中, 一些提示,以帮助您更好地了解该过程。 然后,我们将展示 im2txt 模型项目随附的 Python 代码的一些关键更改,以便冻结该模型以准备在移动设备上使用。
在本部分中,我们将首先总结训练训练名为 im2txt 的 Show and Tell 模型的过程,该模型记录在[这个页面](https://github.com/tensorflow/models/tree/master/research/im2txt)中, 一些提示,以帮助您更好地了解该过程。 然后,我们将展示 im2txt 模型项目随附的 Python 代码的一些关键更改,以便冻结该模型以准备在移动设备上使用。
...
@@ -62,7 +62,7 @@ The gradient concept is used in the back propagation process to update network w
...
@@ -62,7 +62,7 @@ The gradient concept is used in the back propagation process to update network w
如果我们在 iOS 或 Android 应用程序中使用新的模型文件`image2text_frozen_stripped.pb`,则`No OpKernel was registered to support Op 'DecodeJpeg' with these attrs.` 肯定会消失。 但是发生另一个错误, `Not a valid TensorFlow Graph serialization: Input 0 of node ExpandDims_6 was passed float from input_feed:0 incompatible with expected int64`。 如果您通过名为 TensorFlow for Poets 2 的不错的 Google TensorFlow 代码实验室( [https://codelabs.developers.google.com/codelabs/tensorflow-for-poets-2](https://codelabs.developers.google.com/codelabs/tensorflow-for-poets-2) ),可能会想起来 还有另一个名为`optimize_for_inference`的工具,其功能类似于`strip_unused`,并且可以很好地用于代码实验室中的图像分类任务。 您可以像这样运行它:
如果我们在 iOS 或 Android 应用程序中使用新的模型文件`image2text_frozen_stripped.pb`,则`No OpKernel was registered to support Op 'DecodeJpeg' with these attrs.` 肯定会消失。 但是发生另一个错误, `Not a valid TensorFlow Graph serialization: Input 0 of node ExpandDims_6 was passed float from input_feed:0 incompatible with expected int64`。 如果您通过名为 TensorFlow for Poets 2 的[不错的 Google TensorFlow 代码实验室](https://codelabs.developers.google.com/codelabs/tensorflow-for-poets-2),可能会想起来,还有另一个名为`optimize_for_inference`的工具,其功能类似于`strip_unused`,并且可以很好地用于代码实验室中的图像分类任务。 您可以像这样运行它:
If you don't have a good understanding of all these details, don't worry; to develop powerful mobile apps using a model built by others, you don't have to understand all the details, but in the next chapter we'll also discuss in greater detail how you can build a RNN model from scratch for stock prediction, and with that, you'll have a better understanding of all the RNN stuff.
If you don't have a good understanding of all these details, don't worry; to develop powerful mobile apps using a model built by others, you don't have to understand all the details, but in the next chapter we'll also discuss in greater detail how you can build a RNN model from scratch for stock prediction, and with that, you'll have a better understanding of all the RNN stuff.
那么,我们如何使用 RNN 和 LSTM 测试股价预测? 我们将在[https://www.alphavantage.co](https://www.alphavantage.co)上使用免费的 API 收集特定股票代码的每日股票价格数据,将其解析为训练集和测试集,并在每次输入时提供 对 RNN / LSTM 模型的一批训练输入(每个训练输入有 20 个时间步长,即,连续 20 天的价格),对模型进行训练,然后进行测试以查看模型在测试数据集中的准确性。 我们将同时使用 TensorFlow 和 Keras API 进行测试,并比较常规 RNN 和 LSTM 模型之间的差异。 我们还将测试三个略有不同的序列输入和输出,看看哪个是最好的:
那么,我们如何使用 RNN 和 LSTM 测试股价预测? 我们将在[这个页面](https://www.alphavantage.co)上使用免费的 API 收集特定股票代码的每日股票价格数据,将其解析为训练集和测试集,并在每次输入时提供 对 RNN / LSTM 模型的一批训练输入(每个训练输入有 20 个时间步长,即,连续 20 天的价格),对模型进行训练,然后进行测试以查看模型在测试数据集中的准确性。 我们将同时使用 TensorFlow 和 Keras API 进行测试,并比较常规 RNN 和 LSTM 模型之间的差异。 我们还将测试三个略有不同的序列输入和输出,看看哪个是最好的:
* 根据过去 N 天预测一天的价格
* 根据过去 N 天预测一天的价格
* 根据过去 N 天预测 M 天的价格
* 根据过去 N 天预测 M 天的价格
...
@@ -62,7 +62,7 @@ The other type of RNN that solves the vanishing gradient problem nicely is calle
...
@@ -62,7 +62,7 @@ The other type of RNN that solves the vanishing gradient problem nicely is calle
首先,您需要在[https://www.alphavantage.co](https://www.alphavantage.co)索取免费的 API 密钥,以便获取任何股票代码的股价数据。 取得 API 密钥后,打开终端并运行以下命令(将`<your_api_key>`替换为您自己的密钥后)以获取 Amazon(amzn)和 Google(goog)的每日库存数据,或将它们替换为您的任何符号 利益:
首先,您需要在[这里](https://www.alphavantage.co)索取免费的 API 密钥,以便获取任何股票代码的股价数据。 取得 API 密钥后,打开终端并运行以下命令(将`<your_api_key>`替换为您自己的密钥后)以获取 Amazon(amzn)和 Google(goog)的每日库存数据,或将它们替换为您的任何符号 利益:
自 2012 年深度学习起步以来,有人认为 Ian Goodfellow 在 2014 年提出的**生成对抗网络**( **GAN** )比这更有趣或更有前途, *生成对抗网络*( [https://arxiv.org/abs/1406.2661](https://arxiv.org/abs/1406.2661) )。 实际上, Facebook AI 研究主管和之一,深度学习研究人员之一的 Yann LeCun 将 GAN 和对抗训练称为*,“这是近十年来机器学习中最有趣的想法。 ”* 因此,我们如何在这里不介绍它,以了解 GAN 为什么如此令人兴奋,以及如何构建 GAN 模型并在 iOS 和 Android 上运行它们?
自 2012 年深度学习起步以来,有人认为 Ian Goodfellow 在 2014 年提出的[**生成对抗网络**](https://arxiv.org/abs/1406.2661)( **GAN** )比这更有趣或更有前途。 实际上, Facebook AI 研究主管和之一,深度学习研究人员之一的 Yann LeCun 将 GAN 和对抗训练称为*,“这是近十年来机器学习中最有趣的想法。 ”* 因此,我们如何在这里不介绍它,以了解 GAN 为什么如此令人兴奋,以及如何构建 GAN 模型并在 iOS 和 Android 上运行它们?
在本章中,我们将首先概述 GAN 是什么,它如何工作以及为什么它具有如此巨大的潜力。 然后,我们将研究两个 GAN 模型:一个基本的 GAN 模型可用于生成类似人的手写数字,另一个更高级的 GAN 模型可将低分辨率的图像增强为高分辨率的图像。 我们将向您展示如何在 Python 和 TensorFlow 中构建和训练此类模型,以及如何为移动部署准备模型。 然后,我们将提供带有完整源代码的 iOS 和 Android 应用程序,它们使用这些模型来生成手写数字并增强图像。 在本章的最后,您应该准备好进一步探索各种基于 GAN 的模型,或者开始构建自己的模型,并了解如何在移动应用程序中运行它们。
在本章中,我们将首先概述 GAN 是什么,它如何工作以及为什么它具有如此巨大的潜力。 然后,我们将研究两个 GAN 模型:一个基本的 GAN 模型可用于生成类似人的手写数字,另一个更高级的 GAN 模型可将低分辨率的图像增强为高分辨率的图像。 我们将向您展示如何在 Python 和 TensorFlow 中构建和训练此类模型,以及如何为移动部署准备模型。 然后,我们将提供带有完整源代码的 iOS 和 Android 应用程序,它们使用这些模型来生成手写数字并增强图像。 在本章的最后,您应该准备好进一步探索各种基于 GAN 的模型,或者开始构建自己的模型,并了解如何在移动应用程序中运行它们。
...
@@ -47,7 +47,7 @@ If you're interested in knowing more about the Nash Equilibrium, Google *"khan a
...
@@ -47,7 +47,7 @@ If you're interested in knowing more about the Nash Equilibrium, Google *"khan a
但是,由于生成器和鉴别器的动态或竞争目标,训练 GAN 达到 Nash 平衡状态是一个棘手且困难的问题。 实际上,这仍然是一个开放的研究问题–伊恩·古德费洛(Ian Goodfellow)在 2017 年 8 月对安德鲁·伍(Andrew Ng)进行的*深度学习英雄*采访中(YouTube 上的搜索 *ian goodfellow andrew ng* )说,如果我们 可以使 GAN 变得像深度学习一样可靠,我们将看到 GAN 取得更大的成功,否则我们最终将用其他形式的生成模型代替它们。
但是,由于生成器和鉴别器的动态或竞争目标,训练 GAN 达到 Nash 平衡状态是一个棘手且困难的问题。 实际上,这仍然是一个开放的研究问题–伊恩·古德费洛(Ian Goodfellow)在 2017 年 8 月对安德鲁·伍(Andrew Ng)进行的*深度学习英雄*采访中(YouTube 上的搜索 *ian goodfellow andrew ng* )说,如果我们 可以使 GAN 变得像深度学习一样可靠,我们将看到 GAN 取得更大的成功,否则我们最终将用其他形式的生成模型代替它们。
尽管在 GAN 的培训方面存在挑战,但是在培训期间您已经可以应用许多有效的已知技巧( [https://github.com/soumith/ganhacks](https://github.com/soumith/ganhacks) )–我们不会介绍 它们在这里,但是如果您有兴趣调整我们将在本章中描述的模型或许多其他 GAN 模型( [https://github.com/eriklindernoren/Keras-GAN](https://github.com/eriklindernoren/Keras-GAN) ),或构建自己的 GAN 模型。
尽管在 GAN 的培训方面存在挑战,但是在培训期间您已经可以应用[许多有效的已知技巧](https://github.com/soumith/ganhacks) – 我们在这里不会介绍它们,但是如果您有兴趣调整我们将在本章中描述的模型或[许多其他 GAN 模型](https://github.com/eriklindernoren/Keras-GAN) ),或构建自己的 GAN 模型。
...
@@ -67,7 +67,7 @@ If you're interested in knowing more about the Nash Equilibrium, Google *"khan a
...
@@ -67,7 +67,7 @@ If you're interested in knowing more about the Nash Equilibrium, Google *"khan a
在本章中,我们快速浏览了 GAN 的美好世界。 我们介绍了 GAN 的含义以及它们为何如此有趣的原因-生成器和鉴别器相互竞争并尝试击败的方式听起来对大多数人来说很有吸引力。 然后,我们详细介绍了如何训练基本 GAN 模型和更高级的图像分辨率增强模型以及如何为移动设备准备它们的详细步骤。 最后,我们向您展示了如何使用这些模型构建 iOS 和 Android 应用程序。 如果您对整个过程和结果感到兴奋,那么您肯定会想进一步探索 GAN,这是一个快速发展的领域,在该领域中,新型 GAN 已经迅速开发出来,以克服先前模型的缺点; 例如,正如我们在*增强图像分辨率*小节的 GAN 高级模型中看到的那样,开发了需要配对图像进行训练的 pix2pix 模型的同一位研究人员提出了一种称为 CycleGAN( [https://junyanz.github.io/CycleGAN](https://junyanz.github.io/CycleGAN) ),删除了图像配对的要求。 如果您对我们生成的数字或增强的图像的质量不满意,则可能还应该进一步探索 GAN,以了解如何改进 GAN 模型。 正如我们之前提到的,GAN 仍很年轻,研究人员仍在努力稳定培训,如果可以稳定的话,将会取得更大的成功。 至少到目前为止,您已经获得了如何在移动应用中快速部署 GAN 模型的经验。 由您决定是关注最新,最出色的 GAN 并在移动设备上使用它们,还是暂时搁置您的移动开发人员的帽子,会全力以赴来构建新的或改进现有的 GAN 模型。
在本章中,我们快速浏览了 GAN 的美好世界。 我们介绍了 GAN 的含义以及它们为何如此有趣的原因-生成器和鉴别器相互竞争并尝试击败的方式听起来对大多数人来说很有吸引力。 然后,我们详细介绍了如何训练基本 GAN 模型和更高级的图像分辨率增强模型以及如何为移动设备准备它们的详细步骤。 最后,我们向您展示了如何使用这些模型构建 iOS 和 Android 应用程序。 如果您对整个过程和结果感到兴奋,那么您肯定会想进一步探索 GAN,这是一个快速发展的领域,在该领域中,新型 GAN 已经迅速开发出来,以克服先前模型的缺点; 例如,正如我们在*增强图像分辨率*小节的 GAN 高级模型中看到的那样,开发了需要配对图像进行训练的 pix2pix 模型的同一位研究人员提出了一种称为 [CycleGAN](https://junyanz.github.io/CycleGAN) 的模型,删除了图像配对的要求。 如果您对我们生成的数字或增强的图像的质量不满意,则可能还应该进一步探索 GAN,以了解如何改进 GAN 模型。 正如我们之前提到的,GAN 仍很年轻,研究人员仍在努力稳定培训,如果可以稳定的话,将会取得更大的成功。 至少到目前为止,您已经获得了如何在移动应用中快速部署 GAN 模型的经验。 由您决定是关注最新,最出色的 GAN 并在移动设备上使用它们,还是暂时搁置您的移动开发人员的帽子,会全力以赴来构建新的或改进现有的 GAN 模型。
如果 GAN 在深度学习社区中引起了极大的兴奋,那么 AlphaGo 在 2016 年和 2017 年击败最优秀的人类 GO 玩家的成就无疑令所有人都感到惊讶。 此外,在 2017 年 10 月,AlphaGo Zero(一种完全基于自学强化学习而无需任何人类知识的新算法)被推举为击败 AlphaGo 100-0,令人难以置信。 2017 年 12 月,与仅在 GO 游戏中定位的 AlphaGo 和 AlphaGo Zero 不同,AlphaZero(一种可在许多具有挑战性的领域实现*“超人表现”* 的算法)被发布。 在下一章中,我们将看到如何使用最新最酷的 AlphaZero 来构建和训练用于玩简单游戏的模型,以及如何在移动设备上运行该模型。
如果 GAN 在深度学习社区中引起了极大的兴奋,那么 AlphaGo 在 2016 年和 2017 年击败最优秀的人类 GO 玩家的成就无疑令所有人都感到惊讶。 此外,在 2017 年 10 月,AlphaGo Zero(一种完全基于自学强化学习而无需任何人类知识的新算法)被推举为击败 AlphaGo 100-0,令人难以置信。 2017 年 12 月,与仅在 GO 游戏中定位的 AlphaGo 和 AlphaGo Zero 不同,AlphaZero(一种可在许多具有挑战性的领域实现*“超人表现”* 的算法)被发布。 在下一章中,我们将看到如何使用最新最酷的 AlphaZero 来构建和训练用于玩简单游戏的模型,以及如何在移动设备上运行该模型。
You can also pick a prebuilt TensorFlow Lite model, such as the MobileNet models available at [https://github.com/tensorflow/models/blob/master/research/slim/nets/mobilenet_v1.md](https://github.com/tensorflow/models/blob/master/research/slim/nets/mobilenet_v1.md), which we used for retraining in [Chapter 2](../Text/02.html), *Classifying Images with Transfer Learning*. Each of the MobileNet model `tgz` files that you can download there contains a converted TensorFlow Lite model. For example, the `MobileNet_v1_1.0_224.tgz` file contains a `mobilenet_v1_1.0_224.tflite` file that you can use directly on mobile. If you use such a prebuilt TensorFlow Lite model, you can skip steps 2 and 3.
You can also pick a prebuilt TensorFlow Lite model, such as the MobileNet models available at [https://github.com/tensorflow/models/blob/master/research/slim/nets/mobilenet_v1.md](https://github.com/tensorflow/models/blob/master/research/slim/nets/mobilenet_v1.md), which we used for retraining in [Chapter 2](../Text/02.html), *Classifying Images with Transfer Learning*. Each of the MobileNet model `tgz` files that you can download there contains a converted TensorFlow Lite model. For example, the `MobileNet_v1_1.0_224.tgz` file contains a `mobilenet_v1_1.0_224.tflite` file that you can use directly on mobile. If you use such a prebuilt TensorFlow Lite model, you can skip steps 2 and 3.
3. 使用 TensorFlow Lite 转换器工具将 TensorFlow 模型转换为 TensorFlow Lite 模型。 在下一节中,您将看到一个详细的示例。
3. 使用 TensorFlow Lite 转换器工具将 TensorFlow 模型转换为 TensorFlow Lite 模型。 在下一节中,您将看到一个详细的示例。
4. 在 iOS 或 Android 上部署 TensorFlow Lite 模型-对于 iOS,使用 C ++ API 加载和运行模型; 对于 Android,请使用 Java API(围绕 C ++ API 的包装器)加载和运行模型。 与我们之前在 TensorFlow Mobile 项目中使用的`Session`类不同,C ++和 Java API 均使用 TensorFlow-lite 特定的`Interpreter`类来推断模型。 在接下来的两个部分中,我们将向您展示 iOS C ++代码和 Android Java 代码以使用`Interpreter`。
4. 在 iOS 或 Android 上部署 TensorFlow Lite 模型-对于 iOS,使用 C ++ API 加载和运行模型; 对于 Android,请使用 Java API(围绕 C ++ API 的包装器)加载和运行模型。 与我们之前在 TensorFlow Mobile 项目中使用的`Session`类不同,C ++和 Java API 均使用 TensorFlow-lite 特定的`Interpreter`类来推断模型。 在接下来的两个部分中,我们将向您展示 iOS C ++代码和 Android Java 代码以使用`Interpreter`。
...
@@ -58,7 +58,7 @@ If you run a TensorFlow Lite model on Android, and if the Android device is Andr
...
@@ -58,7 +58,7 @@ If you run a TensorFlow Lite model on Android, and if the Android device is Andr
有两个用于 iOS 的 TensorFlow Lite 示例应用程序,名为[simple and camera]的,类似于 TensorFlow Mobile iOS 应用程序 simple 和 camera,但在 TensorFlow 1.5-1.8 的官方版本中的 TensorFlow Lite API 中实现 [https://github.com/tensorflow/tensorflow/releases](https://github.com/tensorflow/tensorflow/releases) ,并且可能也在最新的 TensorFlow 回购中。 您可以运行以下命令来准备和运行这两个应用,类似地在[的“ iOS 演示应用”下进行了记录:https://github.com/tensorflow/tensorflow/tree/master/tensorflow/contrib/lite](https://github.com/tensorflow/tensorflow/tree/master/tensorflow/contrib/lite) :
有两个用于 iOS 的 TensorFlow Lite 示例应用程序,名为[simple and camera]的,类似于 TensorFlow Mobile iOS 应用程序 simple 和 camera,但在 TensorFlow 1.5-1.8 的官方版本中的 TensorFlow Lite API 中实现 [https://github.com/tensorflow/tensorflow/releases](https://github.com/tensorflow/tensorflow/releases) ,并且可能也在最新的 TensorFlow 仓库中。 您可以运行以下命令来准备和运行这两个应用,类似地在[的“ iOS 演示应用”下进行了记录:https://github.com/tensorflow/tensorflow/tree/master/tensorflow/contrib/lite](https://github.com/tensorflow/tensorflow/tree/master/tensorflow/contrib/lite) :