***启发式**:启发式是用于解决给定问题的技术,该技术在短期内解决该问题是实用且有用的,但不能保证是最优的。 这更像是对应该采用何种方法解决问题的有根据的猜测。 在 AI 中,我们经常遇到无法检查所有可能性以选择最佳选项的情况。 因此,我们需要使用启发式方法来实现目标。 它们在机器人,搜索引擎等领域的 AI 中得到了广泛使用。
**通用问题解决器**(**GPS**)是由 Herbert Simon,J.C。Shaw 和 Allen Newell 提出的 AI 程序。 它是 AI 世界中第一个有用的计算机程序。 目的是使其能够作为通用的问题解决机器。 当然,以前有很多软件程序,但是这些程序执行特定的任务。 GPS 是第一个旨在解决任何一般问题的程序。 GPS 应该针对每个问题使用相同的基本算法来解决所有问题。
**通用问题解决器**(**GPS**)是由 Herbert Simon,J.C. Shaw 和 Allen Newell 提出的 AI 程序。 它是 AI 世界中第一个有用的计算机程序。 目的是使其能够作为通用的问题解决机器。 当然,以前有很多软件程序,但是这些程序执行特定的任务。 GPS 是第一个旨在解决任何一般问题的程序。 GPS 应该针对每个问题使用相同的基本算法来解决所有问题。
分类器的性能以`precision`,`recall`和`f1-scores`为特征。 精度是指分类的准确性,召回率是指检索到的项目数占应检索的项目总数的百分比。 好的分类器将具有较高的精度和较高的查全率,但是通常在这两者之间需要权衡。 因此,我们有`f1-score`来表征。 F1 分数是精度和查全率的谐波平均值,使 F1 分数在精度和查全率之间取得了很好的平衡。
分类器的性能以`precision`,`recall`和`f1-scores`为特征。 精度是指分类的准确性,召回率是指检索到的项目数占应检索的项目总数的百分比。 好的分类器将具有较高的精度和较高的查全率,但是通常在这两者之间需要权衡。 因此,我们有`f1-score`来表征。 F1 得分是精度和查全率的谐波平均值,使 F1 得分在精度和查全率之间取得了很好的平衡。
@@ -910,7 +910,7 @@ Picture quantized with 24 vectors
RGB histogram of the original image (top) and quantized version (bottom)For readers who are not familiar with histograms, we can briefly describe them as having a dataset`X`and a fixed number of bins. Each bin is assigned to a range (starting from *min(X)* and ending in *max(X)*) and each range (*a, b*) is associated with the number of samples such that *a ≤ x < b*. The resulting plot is proportional to an approximation of the actual probability distribution that generated`X`. In our case, on the x-axis, there are all possible values for each pixel per channel (8-bit), while the y-axis represents the estimated frequency (*Nx / Total number of pixels*).
@@ -90,7 +90,7 @@ TensorFlow 是 Google 的开放源代码框架,用于构建机器学习 AI 应
As we have to stop with a specific TensorFlow version at certain points to get the book published, we'll continue to test run all the code in the book with every new major TensorFlow release, and update the code and test results accordingly on the book's source code repository at [http://github.com/jeffxtang/mobiletfbook](http://github.com/jeffxtang/mobiletfbook). If you have any questions about the code or the book, you may also post an issue directly on the repository.
另一个问题是 TensorFlow Mobile 和 TensorFlow Lite 之间的选择。 该书在大多数章节(1 至 10)中介绍了 TensorFlow Mobile。 TensorFlow Lite 可能是在移动设备上运行 TensorFlow 的未来,它在 Google I / O 2018 上仍处于开发人员预览版中,这就是 Google 希望您“使用 TensorFlow Mobile 覆盖生产案例”的原因。 即使在 TensorFlow Lite 正式发布后,根据 Google 的说法,“ TensorFlow Mobile 不会很快消失”-实际上,在本书出版之前我们测试了最新的 TensorFlow 1.8.0 版本,我们发现 使用 TensorFlow Mobile 变得更加简单
另一个问题是 TensorFlow Mobile 和 TensorFlow Lite 之间的选择。 该书在大多数章节(1 至 10)中介绍了 TensorFlow Mobile。 TensorFlow Lite 可能是在移动设备上运行 TensorFlow 的未来,它在 Google I/O 2018 上仍处于开发人员预览版中,这就是 Google 希望您“使用 TensorFlow Mobile 覆盖生产案例”的原因。 即使在 TensorFlow Lite 正式发布后,根据 Google 的说法,“ TensorFlow Mobile 不会很快消失”-实际上,在本书出版之前我们测试了最新的 TensorFlow 1.8.0 版本,我们发现 使用 TensorFlow Mobile 变得更加简单
如果 TensorFlow Lite 在所有用例中完全取代 TensorFlow Mobile 的那一天(具有 Lite 更好的性能和更小的尺寸)终于到了,那么您从书本中学到的技能将只会为您做好准备。 同时,在那个不可预见的未来到来之前,您可以阅读这本书并了解如何使用 TensorFlow Mobile 这样的老大哥在您的移动应用程序中运行所有这些功能强大的 TensorFlow 模型。
If you're a little confused about the buzz words machine learning, deep learning, machine intelligence, and artificial intelligence (AI), here's a quick summary: machine intelligence and AI are really just the same thing; machine learning is a field, also the most popular one, of AI; deep learning is one special type of machine learning, and is also the modern and most effective approach to solving complicated problems such as computer vision, speech recognition and synthesis, and natural language processing. So in this book, when we say AI, we primarily mean deep learning, the savior that took AI from the long winter to the summer. For more information about the AI winter and deep learning, you can check out [https://en.wikipedia.org/wiki/AI_winter](https://en.wikipedia.org/wiki/AI_winter) and [http://www.deeplearningbook.org](http://www.deeplearningbook.org).
...
...
@@ -225,7 +225,7 @@ Android Studio 是开发 Android 应用程序的最佳工具,并且 TensorFlow
在我们开始运行示例 TensorFlow iOS 和 Android 应用程序之前,让我们澄清一下。 TensorFlow 当前有两种在移动设备上开发和部署深度学习应用程序的方法:TensorFlow Mobile 和 TensorFlow Lite。 TensorFlow Mobile 从一开始就是 TensorFlow 的一部分,而 TensorFlow Lite 是开发和部署 TensorFlow 应用程序的较新方法,因为它具有更好的性能和更小的应用程序尺寸。 但是有一个关键因素可以让我们在本书中专注于 TensorFlow Mobile,同时仍在一个章节中介绍 TensorFlow Lite:从 TensorFlow 1.8 和 2018 年 5 月的 Google I / O 开始,TensorFlow Lite 仍在开发人员预览版中。 现在,准备投入生产的移动 TensorFlow 应用程序,您必须按照 Google 的建议使用 TensorFlow Mobile。
在我们开始运行示例 TensorFlow iOS 和 Android 应用程序之前,让我们澄清一下。 TensorFlow 当前有两种在移动设备上开发和部署深度学习应用程序的方法:TensorFlow Mobile 和 TensorFlow Lite。 TensorFlow Mobile 从一开始就是 TensorFlow 的一部分,而 TensorFlow Lite 是开发和部署 TensorFlow 应用程序的较新方法,因为它具有更好的性能和更小的应用程序尺寸。 但是有一个关键因素可以让我们在本书中专注于 TensorFlow Mobile,同时仍在一个章节中介绍 TensorFlow Lite:从 TensorFlow 1.8 和 2018 年 5 月的 Google I/O 开始,TensorFlow Lite 仍在开发人员预览版中。 现在,准备投入生产的移动 TensorFlow 应用程序,您必须按照 Google 的建议使用 TensorFlow Mobile。
我们决定现在专注于 TensorFlow Mobile 的另一个原因是,虽然 TensorFlow Lite 仅对模型运算符提供了有限的支持,但 TensorFlow Mobile 支持自定义以添加默认情况下 TensorFlow Mobile 不支持的新运算符,您会发现它经常发生在我们的各种模型中 AI 应用程序的模型。
To further improve the accuracy, you can play with the `retrain.py`'s other parameters such as training steps (`--how_many_training_steps`), learning rate (`--learning_rate`), and data augmentation (`--flip_left_right`, `--random_crop`, `--random_scale`, `--random_brightness`). Generally, this is a tedious process that involves a lot of "dirty work" as called by Andrew Ng, one of the best-known deep learning experts, in his *Nuts and Bolts of Applying Deep Learning* speech (video is available at: [https://www.youtube.com/watch?v=F1ka6a13S9I](https://www.youtube.com/watch?v=F1ka6a13S9I)).
TensorFlow's documentation ([https://www.tensorflow.org/performance/quantization](https://www.tensorflow.org/performance/quantization)) offers more details on quantization and why it works.
As François Chollet points out, "deep learning is more an art than a science... every problem is unique and you will have to try and evaluate different strategies empirically. There is currently no theory that will tell you in advance precisely what you should do to optimally solve a problem. You must try and iterate." Hopefully we have provided a good starting point for you to improve the stock price prediction models using TensorFlow and Keras APIs.
...
...
@@ -709,7 +709,7 @@ Could not create TensorFlow Graph: Invalid argument: No OpKernel was registered
![](img/4114a6b9-15da-41f7-b535-bf04c7fb4dad.png)Figure 8.6 Predicting with the Keras RNN model
我们无法确定哪个模型能在没有进一步研究的情况下更好地工作,但是我们可以确定的是,我们的两个 RNN 模型都使用 TensorFlow 和 Keras API 从头开始训练了,其准确性接近 60%, 在 iOS 上运行良好,这很值得我们付出努力,因为我们正在尝试建立一个许多专家认为将达到与随机选择相同的性能的模型,并且在此过程中,我们学到了一些新奇的东西-使用 TensorFlow 和 Keras 构建 RNN 模型并在 iOS 上运行它们。 在下一章中,我们只剩下一件事了:如何在 Android 上使用模型? 我们会遇到新的障碍吗?
我们无法确定哪个模型能在没有进一步研究的情况下更好地工作,但是我们可以确定的是,我们的两个 RNN 模型都使用 TensorFlow 和 Keras API 从头开始训练了,其准确性接近 60%, 在 iOS 上运行良好,这很值得我们付出努力,因为我们正在尝试建立一个许多专家认为将达到与随机选择相同的性能的模型,并且在此过程中,我们学到了一些新奇的东西-使用 TensorFlow 和 Keras 构建 RNN 模型并在 iOS 上运行它们。 在下一章中,我们只剩下一件事了:如何在 Android 上使用模型? 我们会遇到新的障碍吗?
...
...
@@ -858,9 +858,9 @@ Figure 8.8 Using the Keras model to make stock price predictions on Amazon
在本章中,我们首先对表示不屑一顾,试图通过使用 TensorFlow 和 Keras RNN API 预测股价来击败市场。 我们首先讨论了 RNN 和 LSTM 模型是什么以及如何使用它们进行股价预测。 然后,我们使用 TensorFlow 和 Keras 从零开始构建了两个 RNN 模型,接近测试正确率的 60%。 最后,我们介绍了如何冻结模型并在 iOS 和 Android 上使用它们,并使用自定义 TensorFlow 库修复了 iOS 上可能出现的运行时错误。
在本章中,我们首先对表示不屑一顾,试图通过使用 TensorFlow 和 Keras RNN API 预测股价来击败市场。 我们首先讨论了 RNN 和 LSTM 模型是什么以及如何使用它们进行股价预测。 然后,我们使用 TensorFlow 和 Keras 从零开始构建了两个 RNN 模型,接近测试正确率的 60%。 最后,我们介绍了如何冻结模型并在 iOS 和 Android 上使用它们,并使用自定义 TensorFlow 库修复了 iOS 上可能出现的运行时错误。
如果您对我们尚未建立正确预测比率为 80%或 90%的模型感到有些失望,则可能需要继续进行“尝试并迭代”过程,以查看是否以该正确比率预测股票价格 可能的。 但是,您肯定会从使用 TensorFlow 和 Keras API 的 RNN 模型构建,培训和测试中学到的技能以及在 iOS 和 Android 上运行的技能而受益。
如果您对我们尚未建立正确预测比率为 80% 或 90% 的模型感到有些失望,则可能需要继续进行“尝试并迭代”过程,以查看是否以该正确比率预测股票价格 可能的。 但是,您肯定会从使用 TensorFlow 和 Keras API 的 RNN 模型构建,培训和测试中学到的技能以及在 iOS 和 Android 上运行的技能而受益。
如果您对使用深度学习技术打败市场感兴趣并感到兴奋,让我们在 GAN(Generative Adversarial Networks)上的下一章中进行研究,该模型试图击败能够分辨真实数据与虚假数据之间差异的对手, 并且越来越擅长生成看起来像真实数据的数据,欺骗对手。 GAN 实际上被深度学习的一些顶级研究人员誉为是过去十年中深度学习中最有趣和令人兴奋的想法。
在前九章中,我们使用 TensorFlow Mobile 在移动设备上运行各种由 TensorFlow 和 Keras 构建的强大的深度学习模型。 正如我们在第 1 章,“移动 TensorFlow 入门”中提到的那样,Google 还提供了 TensorFlow Lite(可替代 TensorFlow Mobile 的版本)在移动设备上运行模型。 尽管自 Google I / O 2018 起它仍在开发人员预览中,但 Google 打算“ 大大简化开发人员针对小型设备的模型定位的体验。” 因此,值得详细研究 TensorFlow Lite 并为未来做好准备。
在前九章中,我们使用 TensorFlow Mobile 在移动设备上运行各种由 TensorFlow 和 Keras 构建的强大的深度学习模型。 正如我们在第 1 章,“移动 TensorFlow 入门”中提到的那样,Google 还提供了 TensorFlow Lite(可替代 TensorFlow Mobile 的版本)在移动设备上运行模型。 尽管自 Google I/O 2018 起它仍在开发人员预览中,但 Google 打算“ 大大简化开发人员针对小型设备的模型定位的体验。” 因此,值得详细研究 TensorFlow Lite 并为未来做好准备。
如果您是 iOS 开发人员,或者同时使用 iOS 和 Android,则 Apple 一年一度的**全球开发人员大会**(**WWDC**)是您不容错过的活动。 在 WWDC 2017 中,Apple 宣布了新的 Core ML 框架,以支持 iOS(以及所有其他 Apple OS 平台:macOS,tvOS 和 watchOS)上的深度学习模型和标准机器学习模型的运行。 自 iOS 11 起,Core ML 就可用了,截至 2018 年 5 月,Core ML 已占到 80%的标记份额。至少了解您可以在 iOS 应用中使用 Core ML 的基本知识绝对有意义。
如果您是 iOS 开发人员,或者同时使用 iOS 和 Android,则 Apple 一年一度的**全球开发人员大会**(**WWDC**)是您不容错过的活动。 在 WWDC 2017 中,Apple 宣布了新的 Core ML 框架,以支持 iOS(以及所有其他 Apple OS 平台:macOS,tvOS 和 watchOS)上的深度学习模型和标准机器学习模型的运行。 自 iOS 11 起,Core ML 就可用了,截至 2018 年 5 月,Core ML 已占到 80% 的标记份额。至少了解您可以在 iOS 应用中使用 Core ML 的基本知识绝对有意义。
因此,我们将在本章涵盖 TensorFlow Lite 和 Core ML,并通过以下主题展示两者的优势和局限性:
在 Google I / O 2016 中,有一个名为*的会话,该会话如何使用 Cloud Vision 和 Speech API* 构建智能的 RasPi Bot(您可以在 YouTube 上观看视频)。 它使用 Google 的 Cloud API 执行图像分类以及语音识别和合成。 在本章中,我们将了解如何在设备上离线实现演示中的任务以及增强学习,从而展示 TensorFlow 在 Raspberry Pi 上的强大功能。
在 Google I/O 2016 中,有一个名为*的会话,该会话如何使用 Cloud Vision 和 Speech API* 构建智能的 RasPi Bot(您可以在 YouTube 上观看视频)。 它使用 Google 的 Cloud API 执行图像分类以及语音识别和合成。 在本章中,我们将了解如何在设备上离线实现演示中的任务以及增强学习,从而展示 TensorFlow 在 Raspberry Pi 上的强大功能。
总而言之,我们将在本章中涵盖以下主题,以构建一个可以移动,看到,聆听,说话和学习的机器人:
...
...
@@ -134,7 +134,7 @@ ctl.!default {
Occasionally, after the Pi board reboots, the card number for the USB speaker gets changed by the system automatically and you won't hear the audio when running `aplay test.wav`. In that case, you can run `aplay -l` again to find the new card number set for the USB speaker and update the `~/``.asoundrc` file accordingly.
如果要调节扬声器的音量,请使用`amixer set PCM -- 100%`命令,其中 100%将音量设置为最大。
如果要调节扬声器的音量,请使用`amixer set PCM -- 100%`命令,其中 100% 将音量设置为最大。
您可以在单独的终端中运行相机应用程序,因此,当机器人根据您的语音命令走动时,它会识别出所看到的新图像并说出结果。 这就是构建一个基本的 Raspberry Pi 机器人所需的全部内容,该机器人可以听,动,看和说-Google I / O 2016 演示所做的事情,却不使用任何 Cloud API。 它远不是一个能听懂自然人的语音,进行有趣的对话或执行有用且不重要的任务的幻想机器人。 但是,借助预训练,再训练或其他强大的 TensorFlow 模型,并使用各种传感器,您当然可以为我们构建的 Pi 机器人增加越来越多的智能和物理动力。
您可以在单独的终端中运行相机应用程序,因此,当机器人根据您的语音命令走动时,它会识别出所看到的新图像并说出结果。 这就是构建一个基本的 Raspberry Pi 机器人所需的全部内容,该机器人可以听,动,看和说-Google I/O 2016 演示所做的事情,却不使用任何 Cloud API。 它远不是一个能听懂自然人的语音,进行有趣的对话或执行有用且不重要的任务的幻想机器人。 但是,借助预训练,再训练或其他强大的 TensorFlow 模型,并使用各种传感器,您当然可以为我们构建的 Pi 机器人增加越来越多的智能和物理动力。
在下一节中,您将看到如何在 Pi 上运行经过预训练和再训练的 TensorFlow 模型,我们将向您展示如何向使用 TensorFlow 构建和训练的机器人添加强大的强化学习模型。 毕竟,强化学习的反复试验方式及其与环境交互以获取最大回报的本质,使得强化学习成为机器人非常合适的机器学习方法。