提交 2c2f3a1c 编写于 作者: W wizardforcel

2020-12-10 18:44:08

上级 415ec392
......@@ -666,7 +666,7 @@ for (int i=0; i<CAPTION_LEN; i++) {
}
```
We probably have never explained in detail how you get and set a TensorFlow tensor value in C++. But if you have read through the code in the book so far, you should have learned how. This is like RNN learning: if you're trained with enough code examples, you'll be able to write code that makes sense. In summary, first you define a variable with the `Tensor` type, specified with the variable's data type and shape, then you call the `Tensor` class's `tensor` method, passing in the C++ version of the data type and the dimension of the shape, to create a map variable for the tensor. After that, you can simply use the map to get or set the tensor's values.
我们可能从未详细解释过如何在 C++ 中获取和设置 TensorFlow 张量值。 但是,如果您到目前为止已经阅读了本书中的代码,那么您应该已经学会了。 这就像 RNN 学习:如果您接受了足够的代码示例培训,就可以编写有意义的代码。 总而言之,首先使用`Tensor`类型定义变量,并使用该变量的数据类型和形状指定,然后调用`Tensor`类的`tensor`方法,传入数据类型的 C++ 版本和 形状,以创建张量的贴图变量。 之后,您可以简单地使用映射来获取或设置张量的值。
12. 最后,只需遍历`captions`向量并将向量中存储的每个词 ID 转换为一个词,然后将该词添加到`sentence`字符串中,而忽略起始 ID 和结束 ID,然后返回该句子,希望是明智的 自然语言:
......
......@@ -686,7 +686,7 @@ bazel build -c opt --copt="-D__ANDROID_TYPES_FULL__" //tensorflow/contrib/androi
--cpu=armeabi-v7a
```
When using a manually built native library in an Android app, you need to let the app know which CPU instruction sets, also known as **Application Binary Interface** (**ABI**), the library is built for. There are two main categories of ABIs supported by Android: ARM and X86, and armeabi-v7a is the most popular ABI on Android. To find out which ABI your device or emulator uses, run `adb -s <device_id> shell getprop ro.product.cpu.abi`. For example, this command returns `armeabi-v7a` for my Nexus 7 tablet and `x86_64` for my emulator.
在 Android 应用中使用手动构建的本机库时,您需要让该应用知道该库是针对哪个 CPU 指令集(也称为**应用二进制接口****ABI**))构建的。 Android 支持两种主要的 ABI:ARM 和 X86,而`armeabi-v7a`是 Android 上最受欢迎的 ABI。 要找出您的设备或仿真器使用的是哪个 ABI,请运行`adb -s <device_id> shell getprop ro.product.cpu.abi`。 例如,此命令为我的 Nexus 7 平板电脑返回`armeabi-v7a`,为我的模拟器返回`x86_64`
如果您具有支持 x86_64 的虚拟仿真器以在开发过程中进行快速测试,并且在设备上进行最终性能测试,则可能要同时构建两者。
......
......@@ -36,7 +36,7 @@
LSTM 只是解决 RNN 已知梯度消失问题的一种 RNN,我们在第 6 章,“用自然语言描述图像”中引入了 LSTM。 基本上,在训练 RNN 模型的过程中,,如果到 RNN 的输入序列的时间步太长,则使用反向传播更新较早时间步的网络权重可能会得到 0 的梯度值, 导致没有学习发生。 例如,当我们使用 50 天的价格作为输入,并且如果使用 50 天甚至 40 天的时间步长变得太长,则常规 RNN 将是不可训练的。 LSTM 通过添加一个长期状态来解决此问题,该状态决定可以丢弃哪些信息以及需要在许多时间步骤中存储和携带哪些信息。
The other type of RNN that solves the vanishing gradient problem nicely is called **Gated Recurrent Unit** (**GRU**), which simplifies standard LSTM models a bit and is becoming more popular. Both TensorFlow and Keras APIs support basic RNN and LSTM/GRU models. In the next two sections, you'll see concrete TensorFlow and Keras APIs for using RNN and standard LSTM, and you can simply replace "LSTM" with "GRU" in the code to use and compare the results of using the GRU model with RNN and standard LSTM models.
可以很好地解决梯度消失问题的另一种RNN被称为**门控循环单元****GRU**),它稍微简化了标准 LSTM 模型,并且越来越受欢迎。 TensorFlow 和 Keras API 均支持基本的 RNN 和 LSTM/GRU 模型。 在接下来的两部分中,您将看到使用 RNN 和标准 LSTM 的具体 TensorFlow 和 Keras API,并且可以在代码中简单地将`LSTM`替换为`GRU`,以将使用 GRU 模型的结果与 RNN 和标准 LSTM 模型比较。
三种常用技术可以使 LSTM 模型表现更好:
......@@ -223,7 +223,7 @@ with tf.Session() as sess:
(500, 'loss:', 91.966286)
```
You can replace BasicRNNCell in step 4 with BasicLSTMCell and run the training code, but the training using BasicLSTMCell is much slower and the loss value is still pretty big after 500 epochs. We won't experiment with BasicLSTMCell further in this section, but for comparison, you'll see detailed use of stacked LSTM layers, dropout, and bidirectional RNNs all in the next section of using Keras.
您可以在第 4 步中用`BasicLSTMCell`替换`BasicRNNCell`并运行训练代码,但是使用`BasicLSTMCell`进行训练要慢得多,并且在 500 个纪元之后损耗值仍然很大。 在本节中,我们将不再对`BasicLSTMCell`进行实验,但是为了进行比较,在使用 Keras 的下一部分中,您将看到堆叠 LSTM 层,丢弃法和双向 RNN 的详细用法。
......@@ -524,7 +524,7 @@ plt.show()
很容易在堆栈中添加更多 LSTM 层,或者使用诸如学习率和辍学率以及许多恒定设置之类的超参数。 但是,对于使用`pred_len``shift_pred`的不同设置,正确率的差异还没有发现。 也许我们现在应该对接近 60% 的正确率感到满意,并看看如何在 iOS 和 Android 上使用 TensorFlow 和 Keras 训练的模型-我们可以在以后继续尝试改进模型,但是 了解使用 TensorFlow 和 Keras 训练的 RNN 模型是否会遇到任何问题将非常有价值。
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.
正如 FrançoisChollet 指出的那样,“深度学习更多的是艺术而不是科学……每个问题都是独特的,您将不得不尝试并经验地评估不同的策略。目前尚无理论可以提前准确地告诉您应该做什么。 以最佳方式解决问题。您必须尝试并进行迭代。” 希望我们为您使用 TensorFlow 和 Keras API 改善股票价格预测模型提供了一个很好的起点。
本节中最后要做的就是从检查点冻结 Keras 模型-因为我们在虚拟环境中安装了 TensorFlow 和 Keras,而 TensorFlow 是 VirtualEnv 中唯一安装并受支持的深度学习库,Keras 使用 TensorFlow 后端 并通过`saver.save(K.get_session(), '/tmp/keras_' + symbol + '.ckpt')`调用以 TensorFlow 格式生成检查点。 现在运行以下命令冻结检查点(回想我们在训练期间从`print(model.input.op.name)`获得`output_node_name`):
......
......@@ -28,7 +28,7 @@ GAN 是学习生成类似于真实数据或训练集中数据的神经网络。
* 当以生成器的输出作为输入时,使其输出的可能性为实,尽可能接近 0.0,这恰好是生成器的相反目标
* 当输入真实数据作为输入时,使其输出的可能性为实数,尽可能接近 1.0
In the next section, you'll see a detailed code snippet that matches the given description of the generator and the discriminator networks and their training process. If you feel like understanding more about GANs, in addition to our summary overview here, you can search for *"Introduction to GANs"* on YouTube and watch Ian Goodfellow's introduction and tutorial videos on GAN at NIPS (Neural Information Processing Systems) Conference 2016 and ICCV (International Conference on Computer Vision) 2017\. In fact, there are 7 NIPS 2016 Workshop on Adversarial Training videos and 12 ICCV 2017 GAN Tutorial videos on YouTube that you can immerse yourself in.
在下一节中,您将看到与生成器和鉴别器网络及其训练过程的给定描述相匹配的详细代码片段。 如果您想了解更多关于 GAN 的知识,除了这里的摘要概述之外,您还可以在 YouTube 上搜索“GAN 简介”,并观看 2016 年 NIPS(神经信息处理系统)和 ICCV(国际计算机视觉会议)2017 大会上的 Ian Goodfellow 的 GAN 入门和教程视频。 事实上,YouTube 上有 7 个 NIPS 2016 对抗训练讲习班视频和 12 个 ICCV 2017 GAN 指导视频,您可以自己投入其中。
在生成者和区分者两个参与者的竞争目标下,GAN 是一个寻求两个对手之间保持平衡的系统。 如果两个玩家都具有无限的能力并且可以进行最佳训练,那么纳什均衡(继 1994 年诺贝尔经济学奖得主约翰·纳什和电影主题《美丽心灵》之后) 一种状态,在这种状态下,任何玩家都无法通过仅更改其自己的策略来获利,这对应于生成器生成数据的状态,该数据看起来像真实数据,而判别器无法从假数据中分辨真实数据。
......
......@@ -132,7 +132,7 @@ ctl.!default {
请注意,`"hw:0,0"``aplay -l`为 USB 扬声器设备返回的卡 0,设备 0 信息匹配。 现在,您可以使用`aplay test.wav`命令在扬声器上测试录制的音频播放。
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.
有时,Pi 板重新启动后,系统会自动更改 USB 扬声器的卡号,并且在运行`aplay test.wav`时您听不到声音。 在这种情况下,您可以再次运行`aplay -l`来找到为 USB 扬声器设置的新卡号,并相应地更新`~/.asoundrc`文件。
如果要调节扬声器的音量,请使用`amixer set PCM -- 100%`命令,其中 100% 将音量设置为最大。
......@@ -154,7 +154,7 @@ GoPiGo 是一个流行的工具包,可将您的 Raspberry Pi 板变成移动
![](img/a745c220-8c27-4b70-bef4-bc8dcbc518d8.png)
Figure 12\. 1 Raspberry Pi robot with GoPiGo Kit and camera, USB speaker, and USB microphone
图 12.1:具有 GoPiGo 套件和相机,USB 扬声器和 USB 麦克风的 Raspberry Pi 机器人
现在,使用 Raspberry Pi 电源打开 Pi 机器人,并在启动后使用`ssh pi@<your_pi_board_ip>`连接到它。 要安装 GoPiGo Python 库,以便我们可以使用 [GoPiGo 的 Python API](http://gopigo3.readthedocs.io/en/master/api-basic.html) 控制机器人,请运行以下命令 ,它将执行一个 shell 脚本,该脚本创建一个新的`/home/pi/Dexter`目录并在其中安装所有库和固件文件:
......@@ -172,7 +172,7 @@ bash GoPiGo3/Firmware/gopigo3_flash_firmware.sh
要测试基本的 GoPiGo Python API,请先运行 iPython,然后逐行输入以下代码:
Be sure to put your GoPiGo Raspberry Pi robot on a safe surface as it'll start moving around. During the final test, you should use the GoPiGo battery pack to power the robot so it can move freely. But in the development and initial tests, you definitely should use the power adapter to save the battery unless you use a rechargeable battery. Always be careful if you put your robot on your desk as it may fall over if you issue a command causing it to make a bad move.
当 GoPiGo Raspberry Pi 机器人开始移动时,请确保将其放在安全的表面上。 在最终测试期间,应使用 GoPiGo 电池组为机器人供电,使其可以自由移动。 但是在开发和初始测试中,除非您使用充电电池,否则绝对应该使用电源适配器来节省电池。 如果将机器人放在桌子上,请务必小心,因为如果发出命令导致机器人动作不佳,机器人可能会跌落。
```py
import easygopigo3 as easy
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册