本文整理汇总了Python中tensorflow.contrib.learn.python.learn.datasets.mnist.load_mnist方法的典型用法代码示例。如果您正苦于以下问题:Python mnist.load_mnist方法的具体用法?Python mnist.load_mnist怎么用?Python mnist.load_mnist使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tensorflow.contrib.learn.python.learn.datasets.mnist
的用法示例。
在下文中一共展示了mnist.load_mnist方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: mnist
# 需要导入模块: from tensorflow.contrib.learn.python.learn.datasets import mnist [as 别名]
# 或者: from tensorflow.contrib.learn.python.learn.datasets.mnist import load_mnist [as 别名]
def mnist(layers, # pylint: disable=invalid-name
activation="sigmoid",
batch_size=128,
mode="train"):
"""Mnist classification with a multi-layer perceptron."""
if activation == "sigmoid":
activation_op = tf.sigmoid
elif activation == "relu":
activation_op = tf.nn.relu
else:
raise ValueError("{} activation not supported".format(activation))
# Data.
data = mnist_dataset.load_mnist()
data = getattr(data, mode)
images = tf.constant(data.images, dtype=tf.float32, name="MNIST_images")
images = tf.reshape(images, [-1, 28, 28, 1])
labels = tf.constant(data.labels, dtype=tf.int64, name="MNIST_labels")
# Network.
mlp = snt.nets.MLP(list(layers) + [10],
activation=activation_op,
initializers=_nn_initializers)
network = snt.Sequential([snt.BatchFlatten(), mlp])
def build():
indices = tf.random_uniform([batch_size], 0, data.num_examples, tf.int64)
batch_images = tf.gather(images, indices)
batch_labels = tf.gather(labels, indices)
output = network(batch_images)
return _xent_loss(output, batch_labels)
return build