def get_mnist_data(): tf_data_sets = read_data_sets("../../../dat/mnist-tf", one_hot=False) convert = lambda data_set: DataSet( data_set.images.reshape((-1, 28, 28, 1)), data_set.labels) return Data(train=convert(tf_data_sets.train), validation=convert(tf_data_sets.validation), test=convert(tf_data_sets.test))
@contact : [email protected] @desc : This tutorial will introduce how to combine TFLearn and Tensorflow, using TFLearn trainer with regular Tensorflow graph. """ from __future__ import print_function import tensorflow as tf import tflearn # -------------------------------------- # High-Level API: Using TFLearn wrappers # -------------------------------------- # Using MNIST Dataset import tflearn.datasets.mnist as mnist mnist_data = mnist.read_data_sets(one_hot=True) # User defined placeholders with tf.Graph().as_default(): # Placeholders for data and labels X = tf.placeholder(shape=(None, 784), dtype=tf.float32) Y = tf.placeholder(shape=(None, 10), dtype=tf.float32) net = tf.reshape(X, [-1, 28, 28, 1]) # Using TFLearn wrappers for network building net = tflearn.conv_2d(net, 32, 3, activation='relu') net = tflearn.max_pool_2d(net, 2) net = tflearn.local_response_normalization(net) net = tflearn.dropout(net, 0.8) net = tflearn.conv_2d(net, 64, 3, activation='relu')
#! /usr/bin/env python # -*- coding: utf-8 -*- __author__ = "maxim" import tensorflow as tf tf.python.control_flow_ops = tf import tflearn import tflearn.data_utils as du # Data loading and preprocessing import tflearn.datasets.mnist as mnist data = mnist.read_data_sets("/home/maxim/p/dat/mnist-tf", one_hot=True) X, Y, valX, valY, testX, testY = data.train.images, data.train.labels, \ data.validation.images, data.validation.labels, \ data.test.images, data.test.labels X = X.reshape([-1, 28, 28, 1]) valX = valX.reshape([-1, 28, 28, 1]) testX = testX.reshape([-1, 28, 28, 1]) X, mean = du.featurewise_zero_center(X) valX = du.featurewise_zero_center(valX, mean) testX = du.featurewise_zero_center(testX, mean) # Building Residual Network net = tflearn.input_data(shape=[None, 28, 28, 1]) net = tflearn.conv_2d(net, 64, 3, activation='relu', bias=False) # Residual blocks net = tflearn.residual_bottleneck(net, 3, 16, 64) net = tflearn.residual_bottleneck(net, 1, 32, 128, downsample=True) net = tflearn.residual_bottleneck(net, 2, 32, 128)
""" This tutorial will introduce how to combine TFLearn and Tensorflow, using TFLearn trainer with regular Tensorflow graph. """ import tensorflow as tf import tflearn # -------------------------------------- # High-Level API: Using TFLearn wrappers # -------------------------------------- # Using MNIST Dataset import tflearn.datasets.mnist as mnist mnist_data = mnist.read_data_sets(one_hot=True) # User defined placeholders with tf.Graph().as_default(): # Placeholders for data and labels X = tf.placeholder(shape=(None, 784), dtype=tf.float32) Y = tf.placeholder(shape=(None, 10), dtype=tf.float32) net = tf.reshape(X, [-1, 28, 28, 1]) # Using TFLearn wrappers for network building net = tflearn.conv_2d(net, 32, 3, activation='relu') net = tflearn.max_pool_2d(net, 2) net = tflearn.local_response_normalization(net) net = tflearn.dropout(net, 0.8) net = tflearn.conv_2d(net, 64, 3, activation='relu') net = tflearn.max_pool_2d(net, 2)
""" This tutorial will introduce how to combine TFLearn and Tensorflow, using TFLearn trainer with regular Tensorflow graph. """ import tensorflow as tf import tflearn # -------------------------------------- # High-Level API: Using TFLearn wrappers # -------------------------------------- import tflearn.datasets.mnist as mnist mnist_data = mnist.read_data_sets('data/', one_hot=True) # User define placeholders with tf.Graph().as_default(): # placeholders for data and labels X = tf.placeholder(shape=[None, 784], dtype=tf.float32) Y = tf.placeholder(shape=[None, 10], dtype=tf.float32) net = tf.reshape(X, [-1, 28, 28, 1]) # Using TFLearn wrappers for network building net = tflearn.conv_2d(net, 32, 3, activation='relu') net = tflearn.max_pool_2d(net, 2) net = tflearn.local_response_normalization(net) net = tflearn.dropout(net, 0.8) net = tflearn.conv_2d(net, 64, 3, activation='relu')
import tensorflow as tf import tflearn import tflearn.datasets.mnist as mnist mnist_data = mnist.read_data_sets(one_hot=True) with tf.Graph().as_default(): # placeholders for data and labels X = tf.placeholder(shape=(None, 784), dtype=tf.float32) Y = tf.placeholder(shape=(None, 10), dtype=tf.float32) net = tf.reshape(X, [-1, 28, 28, 1]) net = tflearn.conv_2d(net, 32, 3, activation='relu') net = tflearn.max_pool_2d(net, 2) net = tflearn.local_response_normalization(net) net = tflearn.dropout(net, 0.8) net = tflearn.conv_2d(net, 64, 3, activation='relu') net = tflearn.max_pool_2d(net, 2) net = tflearn.local_response_normalization(net) net = tflearn.dropout(net, 0.8) net = tflearn.fully_connected(net, 128, activation='tanh') net = tflearn.dropout(net, 0.8) net = tflearn.fully_connected(net, 256, activation='tanh') net = tflearn.dropout(net, 0.8) net = tflearn.fully_connected(net, 10, activation='linear') loss = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(net, Y)) optimizer = tf.train.AdamOptimizer(learning_rate=0.01).minimize(loss) with tf.Session() as sess: sess.run(tf.global_variables_initializer()) batch_size = 128 for epoch in range(2): avg_cost = 0 total_batch = int(mnist_data.train.num_examples / batch_size)
def load_data(one_hot=False): mnist_data = mnist.read_data_sets(SOURCE + 'mnist/data/', one_hot=one_hot) return mnist_data.train.images, mnist_data.train.labels, mnist_data.test.images, mnist_data.test.labels