要运行脚本,请先从[http://download.tensorflow.org/models/speech_commands_v0.01.zip 下载预训练的音频识别模型,然后将其解压缩到`/tmp`,或者`scp`我们在](http://download.tensorflow.org/models/speech_commands_v0.01.zip)[第 5 章](../Text/05.html) , *中使用的模型了解简单语音命令* 和到 Pi 板的`/tmp`目录,然后运行 :
要运行脚本,请先从[这里](http://download.tensorflow.org/models/speech_commands_v0.01.zip)下载预训练的音频识别模型,然后将其解压缩到`/tmp`,或者对我们在[第 5 章](../Text/05.html)“了解简单语音命令”中使用的模型使用`scp`到 Pi 板的`/tmp`目录,然后运行:
在之前的章节中,我们主要使用 Python 训练和测试 TensorFlow 模型,然后再使用本机 TensorFlow C ++库的 Java 接口代码在使用 C ++或 Android 的 iOS 中运行模型。 在 Raspberry Pi 上,您可以选择直接使用 TensorFlow Python API 或 C ++ API 在 Pi 上运行 TensorFlow 模型,尽管通常仍会在功能更强大的模型上进行训练 电脑。 有关完整的 TensorFlow Python API 文档,请参见[https://www.tensorflow.org/api_docs/python](https://www.tensorflow.org/api_docs/python)。
在之前的章节中,我们主要使用 Python 训练和测试 TensorFlow 模型,然后再使用本机 TensorFlow C ++库的 Java 接口代码在使用 C ++或 Android 的 iOS 中运行模型。 在 Raspberry Pi 上,您可以选择直接使用 TensorFlow Python API 或 C ++ API 在 Pi 上运行 TensorFlow 模型,尽管通常仍会在功能更强大的模型上进行训练 电脑。 有关完整的 TensorFlow Python API 文档,请参见[这里](https://www.tensorflow.org/api_docs/python)。
要使用 GoPiGo Python API 使机器人根据您的语音命令移动,请首先在`listen.py`中添加以下两行:
We covered AlphaGo and AlphaZero in the last chapter, and Jim Fleming wrote an interesting blog entry titled Before AlphaGo there was TD-Gammon ([https://medium.com/jim-fleming/before-alphago-there-was-td-gammon-13deff866197](https://medium.com/jim-fleming/before-alphago-there-was-td-gammon-13deff866197)), which was the first reinforcement learning application that trains itself using a neural network as an evaluation function to beat human Backgammon champions. Both the blog entry and the book, *Reinforcement Learning: An Introduction* by *Sutton* and *Barto*, have in-depth descriptions of TD-Gammon; you can also Google "Temporal Difference Learning and TD-Gammon" for the original paper if you want to know more about using neural networks as a powerful universal function.
请注意,kernel 只是权重的另一个名称,(4,4),(4,),(4,1)和(1,)是权重的形状和对第一个(输入到隐藏)和 第二层(隐藏到输出)。 如果您从 iPython 多次运行脚本,则`tf`对象的默认图形将包含先前运行的可训练变量,因此,除非调用`tf.reset_default_graph()`,否则需要使用`gvs = [(g, v) for g, v in gvs if g != None]`删除那些过时的训练变量, 将返回 None 渐变(有关`computer_gradients`的更多信息,请参见[https://www.tensorflow.org/api_docs/python/tf/train/AdamOptimizer#compute_gradients](https://www.tensorflow.org/api_docs/python/tf/train/AdamOptimizer#compute_gradients))。
请注意,kernel 只是权重的另一个名称,(4,4),(4,),(4,1)和(1,)是权重的形状和对第一个(输入到隐藏)和 第二层(隐藏到输出)。 如果您从 iPython 多次运行脚本,则`tf`对象的默认图形将包含先前运行的可训练变量,因此,除非调用`tf.reset_default_graph()`,否则需要使用`gvs = [(g, v) for g, v in gvs if g != None]`删除那些过时的训练变量, 将返回 None 渐变(有关`computer_gradients`的更多信息,请参见[这里](https://www.tensorflow.org/api_docs/python/tf/train/AdamOptimizer#compute_gradients))。