Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added chapter_1/MNIST_data/raw/mnist_train_0.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added chapter_1/MNIST_data/raw/mnist_train_1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added chapter_1/MNIST_data/raw/mnist_train_10.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added chapter_1/MNIST_data/raw/mnist_train_11.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added chapter_1/MNIST_data/raw/mnist_train_12.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added chapter_1/MNIST_data/raw/mnist_train_13.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added chapter_1/MNIST_data/raw/mnist_train_14.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added chapter_1/MNIST_data/raw/mnist_train_15.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added chapter_1/MNIST_data/raw/mnist_train_16.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added chapter_1/MNIST_data/raw/mnist_train_17.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added chapter_1/MNIST_data/raw/mnist_train_18.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added chapter_1/MNIST_data/raw/mnist_train_19.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added chapter_1/MNIST_data/raw/mnist_train_2.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added chapter_1/MNIST_data/raw/mnist_train_3.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added chapter_1/MNIST_data/raw/mnist_train_4.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added chapter_1/MNIST_data/raw/mnist_train_5.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added chapter_1/MNIST_data/raw/mnist_train_6.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added chapter_1/MNIST_data/raw/mnist_train_7.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added chapter_1/MNIST_data/raw/mnist_train_8.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added chapter_1/MNIST_data/raw/mnist_train_9.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added chapter_1/MNIST_data/t10k-images-idx3-ubyte.gz
Binary file not shown.
Binary file added chapter_1/MNIST_data/t10k-labels-idx1-ubyte.gz
Binary file not shown.
Binary file added chapter_1/MNIST_data/train-images-idx3-ubyte.gz
Binary file not shown.
Binary file added chapter_1/MNIST_data/train-labels-idx1-ubyte.gz
Binary file not shown.
2 changes: 1 addition & 1 deletion chapter_1/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 的底层原理有很 大帮助。
2 changes: 1 addition & 1 deletion chapter_2/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion chapter_3/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 了解 其结构细节。
6 changes: 6 additions & 0 deletions chapter_3/data_prepare/pic/label.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
wood
urban
water
glacier
rock
wetland
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
2 changes: 2 additions & 0 deletions chapter_3/slim/datasets/dataset_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}


Expand Down
98 changes: 98 additions & 0 deletions chapter_3/slim/datasets/satellite.py
Original file line number Diff line number Diff line change
@@ -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)
6 changes: 6 additions & 0 deletions chapter_3/slim/satellite/data/label.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
wood
urban
water
glacier
rock
wetland
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.