diff --git a/chapter_1/MNIST_data/raw/mnist_train_0.jpg b/chapter_1/MNIST_data/raw/mnist_train_0.jpg new file mode 100644 index 00000000..9106bf61 Binary files /dev/null and b/chapter_1/MNIST_data/raw/mnist_train_0.jpg differ diff --git a/chapter_1/MNIST_data/raw/mnist_train_1.jpg b/chapter_1/MNIST_data/raw/mnist_train_1.jpg new file mode 100644 index 00000000..2fd9615f Binary files /dev/null and b/chapter_1/MNIST_data/raw/mnist_train_1.jpg differ diff --git a/chapter_1/MNIST_data/raw/mnist_train_10.jpg b/chapter_1/MNIST_data/raw/mnist_train_10.jpg new file mode 100644 index 00000000..aa94a238 Binary files /dev/null and b/chapter_1/MNIST_data/raw/mnist_train_10.jpg differ diff --git a/chapter_1/MNIST_data/raw/mnist_train_11.jpg b/chapter_1/MNIST_data/raw/mnist_train_11.jpg new file mode 100644 index 00000000..1ae12448 Binary files /dev/null and b/chapter_1/MNIST_data/raw/mnist_train_11.jpg differ diff --git a/chapter_1/MNIST_data/raw/mnist_train_12.jpg b/chapter_1/MNIST_data/raw/mnist_train_12.jpg new file mode 100644 index 00000000..0f4b467c Binary files /dev/null and b/chapter_1/MNIST_data/raw/mnist_train_12.jpg differ diff --git a/chapter_1/MNIST_data/raw/mnist_train_13.jpg b/chapter_1/MNIST_data/raw/mnist_train_13.jpg new file mode 100644 index 00000000..ca54f169 Binary files /dev/null and b/chapter_1/MNIST_data/raw/mnist_train_13.jpg differ diff --git a/chapter_1/MNIST_data/raw/mnist_train_14.jpg b/chapter_1/MNIST_data/raw/mnist_train_14.jpg new file mode 100644 index 00000000..1d2c42af Binary files /dev/null and b/chapter_1/MNIST_data/raw/mnist_train_14.jpg differ diff --git a/chapter_1/MNIST_data/raw/mnist_train_15.jpg b/chapter_1/MNIST_data/raw/mnist_train_15.jpg new file mode 100644 index 00000000..a099002b Binary files /dev/null and b/chapter_1/MNIST_data/raw/mnist_train_15.jpg differ diff --git a/chapter_1/MNIST_data/raw/mnist_train_16.jpg b/chapter_1/MNIST_data/raw/mnist_train_16.jpg new file mode 100644 index 00000000..9fc184fc Binary files /dev/null and b/chapter_1/MNIST_data/raw/mnist_train_16.jpg differ diff --git a/chapter_1/MNIST_data/raw/mnist_train_17.jpg b/chapter_1/MNIST_data/raw/mnist_train_17.jpg new file mode 100644 index 00000000..58371248 Binary files /dev/null and b/chapter_1/MNIST_data/raw/mnist_train_17.jpg differ diff --git a/chapter_1/MNIST_data/raw/mnist_train_18.jpg b/chapter_1/MNIST_data/raw/mnist_train_18.jpg new file mode 100644 index 00000000..cd9e7585 Binary files /dev/null and b/chapter_1/MNIST_data/raw/mnist_train_18.jpg differ diff --git a/chapter_1/MNIST_data/raw/mnist_train_19.jpg b/chapter_1/MNIST_data/raw/mnist_train_19.jpg new file mode 100644 index 00000000..4ce69276 Binary files /dev/null and b/chapter_1/MNIST_data/raw/mnist_train_19.jpg differ diff --git a/chapter_1/MNIST_data/raw/mnist_train_2.jpg b/chapter_1/MNIST_data/raw/mnist_train_2.jpg new file mode 100644 index 00000000..d4689ebd Binary files /dev/null and b/chapter_1/MNIST_data/raw/mnist_train_2.jpg differ diff --git a/chapter_1/MNIST_data/raw/mnist_train_3.jpg b/chapter_1/MNIST_data/raw/mnist_train_3.jpg new file mode 100644 index 00000000..b66d8def Binary files /dev/null and b/chapter_1/MNIST_data/raw/mnist_train_3.jpg differ diff --git a/chapter_1/MNIST_data/raw/mnist_train_4.jpg b/chapter_1/MNIST_data/raw/mnist_train_4.jpg new file mode 100644 index 00000000..692a5c23 Binary files /dev/null and b/chapter_1/MNIST_data/raw/mnist_train_4.jpg differ diff --git a/chapter_1/MNIST_data/raw/mnist_train_5.jpg b/chapter_1/MNIST_data/raw/mnist_train_5.jpg new file mode 100644 index 00000000..26b83772 Binary files /dev/null and b/chapter_1/MNIST_data/raw/mnist_train_5.jpg differ diff --git a/chapter_1/MNIST_data/raw/mnist_train_6.jpg b/chapter_1/MNIST_data/raw/mnist_train_6.jpg new file mode 100644 index 00000000..bed6bcd6 Binary files /dev/null and b/chapter_1/MNIST_data/raw/mnist_train_6.jpg differ diff --git a/chapter_1/MNIST_data/raw/mnist_train_7.jpg b/chapter_1/MNIST_data/raw/mnist_train_7.jpg new file mode 100644 index 00000000..5ae4b5fc Binary files /dev/null and b/chapter_1/MNIST_data/raw/mnist_train_7.jpg differ diff --git a/chapter_1/MNIST_data/raw/mnist_train_8.jpg b/chapter_1/MNIST_data/raw/mnist_train_8.jpg new file mode 100644 index 00000000..85037b36 Binary files /dev/null and b/chapter_1/MNIST_data/raw/mnist_train_8.jpg differ diff --git a/chapter_1/MNIST_data/raw/mnist_train_9.jpg b/chapter_1/MNIST_data/raw/mnist_train_9.jpg new file mode 100644 index 00000000..6b111789 Binary files /dev/null and b/chapter_1/MNIST_data/raw/mnist_train_9.jpg differ diff --git a/chapter_1/MNIST_data/t10k-images-idx3-ubyte.gz b/chapter_1/MNIST_data/t10k-images-idx3-ubyte.gz new file mode 100644 index 00000000..5ace8ea9 Binary files /dev/null and b/chapter_1/MNIST_data/t10k-images-idx3-ubyte.gz differ diff --git a/chapter_1/MNIST_data/t10k-labels-idx1-ubyte.gz b/chapter_1/MNIST_data/t10k-labels-idx1-ubyte.gz new file mode 100644 index 00000000..a7e14154 Binary files /dev/null and b/chapter_1/MNIST_data/t10k-labels-idx1-ubyte.gz differ diff --git a/chapter_1/MNIST_data/train-images-idx3-ubyte.gz b/chapter_1/MNIST_data/train-images-idx3-ubyte.gz new file mode 100644 index 00000000..b50e4b6b Binary files /dev/null and b/chapter_1/MNIST_data/train-images-idx3-ubyte.gz differ diff --git a/chapter_1/MNIST_data/train-labels-idx1-ubyte.gz b/chapter_1/MNIST_data/train-labels-idx1-ubyte.gz new file mode 100644 index 00000000..707a576b Binary files /dev/null and b/chapter_1/MNIST_data/train-labels-idx1-ubyte.gz differ diff --git a/chapter_1/README.md b/chapter_1/README.md index 9efaf205..51d2e8e4 100644 --- a/chapter_1/README.md +++ b/chapter_1/README.md @@ -39,7 +39,7 @@ python convolutional.py #### 拓展阅读 - 本章介绍的MNIST 数据集经常被用来检验机器学习模型的性能,在它的官网(地址:http://yann.lecun.com/exdb/mnist/ )中,可以找到多达68 种模型在该数据集上的准确率数据,包括相应的论文出处。这些模型包括线性分类器、K 近邻方法、普通的神经网络、卷积神经网络等。 -- 本章的两个MNIST 程序实际上来自于TensorFlow 官方的两个新手教程,地址为https://www.tensorflow.org/get_started/mnist/beginners 和 https://www.tensorflow.org/get_started/mnist/pros 。读者可以将本书的内容和官方的教程对照起来进行阅读。这两个新手教程的中文版地址为http://www.tensorfly.cn/tfdoc/tutorials/mnist_beginners.html 和http://www.tensorfly.cn/tfdoc/tutorials/mnist_pros.html。 +- 本章的两个MNIST 程序实际上来自于TensorFlow 官方的两个新手教程,地址为https://www.tensorflow.org/get_started/mnist/beginners 和 https://www.tensorflow.org/get_started/mnist/pros 。读者可以将本书的内容和官方的教程对照起来进行阅读。这两个新手教程的中文版地址为http://www.tensorfly.cn/tfdoc/tutorials/mnist_beginners.html 和http://www.tensorfly.cn/tfdoc/tutorials/mnist_pros.html 。 - 本章简要介绍了TensorFlow 的tf.Tensor 类。tf.Tensor 类是TensorFlow的核心类,常用的占位符(tf.placeholder)、变量(tf.Variable)都可以看作特殊的Tensor。读者可以参阅https://www.tensorflow.org/programmers_guide/tensors 来更深入地学习它的原理。 - 常用tf.Variable 类来存储模型的参数, 读者可以参阅[https://www.tensorflow.org/programmers_guide/variables](https://www.tensorflow.org/programmers_guide/variables) 详细了解它的运行机制, 文档的中文版地址为http://www.tensorfly.cn/tfdoc/how_tos/ variables.html。 - 只有通过会话(Session)才能计算出tf.Tensor 的值。强烈建议读者 在学习完tf.Tensor 和tf.Variable 后,阅读https://www.tensorflow.org/programmers_guide/graphs 中的内容,该文档描述了TensorFlow 中 计算图和会话的基本运行原理,对理解TensorFlow 的底层原理有很 大帮助。 diff --git a/chapter_2/README.md b/chapter_2/README.md index d51be561..7b133215 100644 --- a/chapter_2/README.md +++ b/chapter_2/README.md @@ -45,4 +45,4 @@ tensorboard --logdir cifar10_eval/ --port 6007 - 关于CIFAR-10 数据集, 读者可以访问它的官方网站https://www.cs.toronto.edu/~kriz/cifar.html 了解更多细节。此外, 网站 http://rodrigob.github.io/are_we_there_yet/build/classification_datasets_results.html#43494641522d3130 中收集了在CIFAR-10 数据集上表 现最好的若干模型,包括这些模型对应的论文。 - ImageNet 数据集上的表现较好的几个著名的模型是深度学习的基石, 值得仔细研读。建议先阅读下面几篇论文:ImageNet Classification with Deep Convolutional Neural Networks(AlexNet 的提出)、Very Deep Convolutional Networks for Large-Scale Image Recognition (VGGNet)、Going Deeper with Convolutions(GoogLeNet)、Deep Residual Learning for Image Recognition(ResNet) -- 在第2.1.3 节中,简要介绍了TensorFlow的一种数据读入机制。事实上,目前在TensorFlow 中读入数据大致有三种方法:(1)用占位符(即placeholder)读入,这种方法比较简单;(2)用队列的形式建立文件到Tensor的映射;(3)用Dataset API 读入数据,Dataset API 是TensorFlow 1.3 版本新引入的一种读取数据的机制,可以参考这 篇中文教程:https://zhuanlan.zhihu.com/p/30751039。 +- 在第2.1.3 节中,简要介绍了TensorFlow的一种数据读入机制。事实上,目前在TensorFlow 中读入数据大致有三种方法:(1)用占位符(即placeholder)读入,这种方法比较简单;(2)用队列的形式建立文件到Tensor的映射;(3)用Dataset API 读入数据,Dataset API 是TensorFlow 1.3 版本新引入的一种读取数据的机制,可以参考这 篇中文教程:https://zhuanlan.zhihu.com/p/30751039 。 diff --git a/chapter_3/README.md b/chapter_3/README.md index 0c1b1b16..659575d2 100644 --- a/chapter_3/README.md +++ b/chapter_3/README.md @@ -122,6 +122,6 @@ python classify_image_inception_v3.py \ #### 拓展阅读 -- TensorFlow Slim 是TensorFlow 中用于定义、训练和验证复杂网络的 高层API。官方已经使用TF-Slim 定义了一些常用的图像识别模型, 如AlexNet、VGGNet、Inception模型、ResNet等。本章介绍的Inception V3 模型也是其中之一, 详细文档请参考: https://github.com/tensorflow/models/tree/master/research/slim。 +- TensorFlow Slim 是TensorFlow 中用于定义、训练和验证复杂网络的 高层API。官方已经使用TF-Slim 定义了一些常用的图像识别模型, 如AlexNet、VGGNet、Inception模型、ResNet等。本章介绍的Inception V3 模型也是其中之一, 详细文档请参考: [https://github.com/tensorflow/models/tree/master/research/slim](https://github.com/tensorflow/models/tree/master/research/slim)。 - 在第3.2节中,将图片数据转换成了TFRecord文件。TFRecord 是 TensorFlow 提供的用于高速读取数据的文件格式。读者可以参考博文( http://warmspringwinds.github.io/tensorflow/tf-slim/2016/12/21/tfrecords-guide/ )详细了解如何将数据转换为TFRecord 文件,以及 如何从TFRecord 文件中读取数据。 - Inception V3 是Inception 模型(即GoogLeNet)的改进版,可以参考论文Rethinking the Inception Architecture for Computer Vision 了解 其结构细节。 diff --git a/chapter_3/data_prepare/pic/label.txt b/chapter_3/data_prepare/pic/label.txt new file mode 100644 index 00000000..40cf801e --- /dev/null +++ b/chapter_3/data_prepare/pic/label.txt @@ -0,0 +1,6 @@ +wood +urban +water +glacier +rock +wetland diff --git a/chapter_3/data_prepare/pic/satellite_train_00000-of-00002.tfrecord b/chapter_3/data_prepare/pic/satellite_train_00000-of-00002.tfrecord new file mode 100644 index 00000000..f8493691 Binary files /dev/null and b/chapter_3/data_prepare/pic/satellite_train_00000-of-00002.tfrecord differ diff --git a/chapter_3/data_prepare/pic/satellite_train_00001-of-00002.tfrecord b/chapter_3/data_prepare/pic/satellite_train_00001-of-00002.tfrecord new file mode 100644 index 00000000..0eb220e8 Binary files /dev/null and b/chapter_3/data_prepare/pic/satellite_train_00001-of-00002.tfrecord differ diff --git a/chapter_3/data_prepare/pic/satellite_validation_00000-of-00002.tfrecord b/chapter_3/data_prepare/pic/satellite_validation_00000-of-00002.tfrecord new file mode 100644 index 00000000..58bff922 Binary files /dev/null and b/chapter_3/data_prepare/pic/satellite_validation_00000-of-00002.tfrecord differ diff --git a/chapter_3/data_prepare/pic/satellite_validation_00001-of-00002.tfrecord b/chapter_3/data_prepare/pic/satellite_validation_00001-of-00002.tfrecord new file mode 100644 index 00000000..8387428a Binary files /dev/null and b/chapter_3/data_prepare/pic/satellite_validation_00001-of-00002.tfrecord differ diff --git a/chapter_3/slim/datasets/dataset_factory.py b/chapter_3/slim/datasets/dataset_factory.py index 141079a6..5aabd696 100644 --- a/chapter_3/slim/datasets/dataset_factory.py +++ b/chapter_3/slim/datasets/dataset_factory.py @@ -22,12 +22,14 @@ from datasets import flowers from datasets import imagenet from datasets import mnist +from datasets import satellite datasets_map = { 'cifar10': cifar10, 'flowers': flowers, 'imagenet': imagenet, 'mnist': mnist, + 'satellite': satellite, } diff --git a/chapter_3/slim/datasets/satellite.py b/chapter_3/slim/datasets/satellite.py new file mode 100644 index 00000000..a93075be --- /dev/null +++ b/chapter_3/slim/datasets/satellite.py @@ -0,0 +1,98 @@ +# Copyright 2016 The TensorFlow Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================== +"""Provides data for the satellite dataset. + +The dataset scripts used to create the dataset can be found at: +tensorflow/models/slim/datasets/download_and_convert_satellite.py +""" + +from __future__ import absolute_import +from __future__ import division +from __future__ import print_function + +import os +import tensorflow as tf + +from datasets import dataset_utils + +slim = tf.contrib.slim + +_FILE_PATTERN = 'satellite_%s_*.tfrecord' + +SPLITS_TO_SIZES = {'train': 4800, 'validation': 1200} + +_NUM_CLASSES = 5 + +_ITEMS_TO_DESCRIPTIONS = { + 'image': 'A color image of varying size.', + 'label': 'A single integer between 0 and 4', +} + + +def get_split(split_name, dataset_dir, file_pattern=None, reader=None): + """Gets a dataset tuple with instructions for reading satellite. + + Args: + split_name: A train/validation split name. + dataset_dir: The base directory of the dataset sources. + file_pattern: The file pattern to use when matching the dataset sources. + It is assumed that the pattern contains a '%s' string so that the split + name can be inserted. + reader: The TensorFlow reader type. + + Returns: + A `Dataset` namedtuple. + + Raises: + ValueError: if `split_name` is not a valid train/validation split. + """ + if split_name not in SPLITS_TO_SIZES: + raise ValueError('split name %s was not recognized.' % split_name) + + if not file_pattern: + file_pattern = _FILE_PATTERN + file_pattern = os.path.join(dataset_dir, file_pattern % split_name) + + # Allowing None in the signature so that dataset_factory can use the default. + if reader is None: + reader = tf.TFRecordReader + + keys_to_features = { + 'image/encoded': tf.FixedLenFeature((), tf.string, default_value=''), + 'image/format': tf.FixedLenFeature((), tf.string, default_value='jpg'), + 'image/class/label': tf.FixedLenFeature( + [], tf.int64, default_value=tf.zeros([], dtype=tf.int64)), + } + + items_to_handlers = { + 'image': slim.tfexample_decoder.Image(), + 'label': slim.tfexample_decoder.Tensor('image/class/label'), + } + + decoder = slim.tfexample_decoder.TFExampleDecoder( + keys_to_features, items_to_handlers) + + labels_to_names = None + if dataset_utils.has_labels(dataset_dir): + labels_to_names = dataset_utils.read_label_file(dataset_dir) + + return slim.dataset.Dataset( + data_sources=file_pattern, + reader=reader, + decoder=decoder, + num_samples=SPLITS_TO_SIZES[split_name], + items_to_descriptions=_ITEMS_TO_DESCRIPTIONS, + num_classes=_NUM_CLASSES, + labels_to_names=labels_to_names) diff --git a/chapter_3/slim/satellite/data/label.txt b/chapter_3/slim/satellite/data/label.txt new file mode 100644 index 00000000..40cf801e --- /dev/null +++ b/chapter_3/slim/satellite/data/label.txt @@ -0,0 +1,6 @@ +wood +urban +water +glacier +rock +wetland diff --git a/chapter_3/slim/satellite/data/satellite_train_00000-of-00002.tfrecord b/chapter_3/slim/satellite/data/satellite_train_00000-of-00002.tfrecord new file mode 100644 index 00000000..f8493691 Binary files /dev/null and b/chapter_3/slim/satellite/data/satellite_train_00000-of-00002.tfrecord differ diff --git a/chapter_3/slim/satellite/data/satellite_train_00001-of-00002.tfrecord b/chapter_3/slim/satellite/data/satellite_train_00001-of-00002.tfrecord new file mode 100644 index 00000000..0eb220e8 Binary files /dev/null and b/chapter_3/slim/satellite/data/satellite_train_00001-of-00002.tfrecord differ diff --git a/chapter_3/slim/satellite/data/satellite_validation_00000-of-00002.tfrecord b/chapter_3/slim/satellite/data/satellite_validation_00000-of-00002.tfrecord new file mode 100644 index 00000000..58bff922 Binary files /dev/null and b/chapter_3/slim/satellite/data/satellite_validation_00000-of-00002.tfrecord differ diff --git a/chapter_3/slim/satellite/data/satellite_validation_00001-of-00002.tfrecord b/chapter_3/slim/satellite/data/satellite_validation_00001-of-00002.tfrecord new file mode 100644 index 00000000..8387428a Binary files /dev/null and b/chapter_3/slim/satellite/data/satellite_validation_00001-of-00002.tfrecord differ diff --git a/chapter_3/slim/satellite/eval_dir/events.out.tfevents.1545840438.MacBook-Pro-5.local b/chapter_3/slim/satellite/eval_dir/events.out.tfevents.1545840438.MacBook-Pro-5.local new file mode 100644 index 00000000..6b9f01c4 Binary files /dev/null and b/chapter_3/slim/satellite/eval_dir/events.out.tfevents.1545840438.MacBook-Pro-5.local differ diff --git a/chapter_3/slim/satellite/train_dir/events.out.tfevents.1545840373.MacBook-Pro-5.local b/chapter_3/slim/satellite/train_dir/events.out.tfevents.1545840373.MacBook-Pro-5.local new file mode 100644 index 00000000..5200cb2b Binary files /dev/null and b/chapter_3/slim/satellite/train_dir/events.out.tfevents.1545840373.MacBook-Pro-5.local differ