Figure 2.1 Dogset images separated by folders, or labels of dog breedYou may download the dataset and then run the `retrain.py` script on Mac, as it doesn't take too long (less than an hour) for the script to run on the relatively small dataset (about 20,000 images in total), but if you do that on a GPU-powered Ubuntu, as set up in the last chapter, the script can complete in just a few minutes. In addition, when retraining with a large image dataset, running on Mac may take hours or days so it makes sense to run it on a GPU-powered machine.
图 2.1:由文件夹或狗的品种分开的狗集图像
您可以下载数据集,然后在 Mac 上运行`retrain.py`脚本,因为该脚本在相对位置上运行不会花费太长时间(少于一小时) 小型数据集(总共约 20,000 张图像),但是,如上一章所述,如果您在 GPU 驱动的 Ubuntu 上执行此操作,则该脚本仅需几分钟即可完成。 此外,当使用大型图像数据集进行再培训时,在 Mac 上运行可能需要花费数小时或数天,因此在 GPU 驱动的计算机上运行它是有意义的。
Figure 2.5 Adding the retrained model file and the label file to app
图 2.5:将重新训练的模型文件和标签文件添加到应用程序
3. 单击 Xcode 中的`RunModelViewController.mm`文件,该文件使用 TensorFlow C++ API 处理输入图像,通过 Inception v1 模型运行它,并获得图像分类结果,并更改行:
...
...
@@ -488,7 +490,7 @@ pod 'TensorFlow-experimental'
![](img/b89b3444-a6a9-45b4-bb02-ddf8388a6992.png)
Figure 2.6 Adding utility files, model files, label file and image files
图 2.6:添加实用程序文件,模型文件,标签文件和图像文件
6. 将`ViewController.m`重命名为`ViewController.mm`,因为我们将在该文件中混合使用 C++ 代码和 Objective-C 代码来调用 TensorFlow C++ API 并处理图像输入和推断结果。 然后,在`@interface ViewController`之前,添加以下`#include`和函数原型:
Figure 7.4: Finding out possible input node namesYou may wonder why we can't fix the `Not found: Op type not registered 'OneShotIterator'` error with a technique we used before, which is to first find out which source file contains the op using the command `grep 'REGISTER.*"OneShotIterator"' tensorflow/core/ops/*.cc`
图 7.4:Finding out possible input node namesYou may wonder why we can't fix the `Not found: Op type not registered 'OneShotIterator'` error with a technique we used before, which is to first find out which source file contains the op using the command `grep 'REGISTER.*"OneShotIterator"' tensorflow/core/ops/*.cc`
(and you'll see the output as `tensorflow/core/ops/dataset_ops.cc:REGISTER_OP("OneShotIterator")`) then add `tensorflow/core/ops/dataset_ops.cc` to `tf_op_files.txt` and rebuild the TensorFlow library. Even if this were feasible, it would complicate the solution as now we need to feed the model with some data related to `OneShotIterator`, instead of the direct user drawing in points.
Figure 9.1: The original, the blurry, and the generated
图 9.1:The original, the blurry, and the generated
10. 现在,将`newckpt`目录复制到`/tmp`,我们可以如下冻结模型:
...
...
@@ -332,7 +332,7 @@ No OpKernel was registered to support Op 'FIFOQueueV2' with these attrs. Registe
![](img/9cb1fa66-5a4e-4a1b-aa51-a16fd9051f57.png)
Figure 9.2: Showing the GAN app in Xcode
图 9.2:Showing the GAN app in Xcode
我们将创建一个按钮,在点击该按钮时,提示用户选择一个模型以生成数字或增强图像:
...
...
@@ -545,7 +545,7 @@ Figure 9.2: Showing the GAN app in Xcode
![](img/0e0f47b1-2efa-4ec0-9eaa-4b21356cad23.png)
Figure 9.3: Showing GAN model selection and results of generated handwritten digits
图 9.3:Showing GAN model selection and results of generated handwritten digits
这些数字看起来很像真实的人类手写数字,都是在训练了基本 GAN 模型之后完成的。 如果您返回并查看进行训练的代码,并且停下来思考一下 GAN 的工作原理,一般来说,则生成器和判别器如何相互竞争,以及 尝试达到稳定的纳什均衡状态,在这种状态下,生成器可以生成区分器无法分辨出真实还是伪造的真实假数据,您可能会更欣赏 GAN 的魅力。
...
...
@@ -553,7 +553,7 @@ Figure 9.3: Showing GAN model selection and results of generated handwritten dig
![](img/63898b4a-4c1d-4605-9fa3-97c8aa00c968.png)
Figure 9.4: The original blurry and enhanced images on iOS
图 9.4:The original blurry and enhanced images on iOS
你知道该怎么做。 是时候将我们的爱献给 Android 了。
...
...
@@ -571,7 +571,7 @@ Figure 9.4: The original blurry and enhanced images on iOS
![](img/f1c741dd-1fc6-41da-9243-3b0840aa9b20.png)
Figure 9.5: Android Studio GAN app overview, showing constant definitions
图 9.5:Android Studio GAN app overview, showing constant definitions