前言
上一篇逻辑回归的已经不知道是猴年马月写的,这里贴一下eager模式的。很多都api化,好处代码清晰,缺点是有些原来可能就没有那么清晰了。下面我们直接看代码
''' Logistic Regression with Eager API.
A logistic regression learning algorithm example using TensorFlow's Eager API.
This example is using the MNIST database of handwritten digits
(http://yann.lecun.com/exdb/mnist/)
Author: Aymeric Damien
Project: https://github.com/aymericdamien/TensorFlow-Examples/
'''
from __future__ import absolute_import, division, print_function
import tensorflow as tf
# Set Eager API
tf.enable_eager_execution()
tfe = tf.contrib.eager
# Import MNIST data
from tensorflow.examples.tutorials.mnist import input_data
mnist = input_data.read_data_sets("/tmp/data/", one_hot=False)
# Parameters
learning_rate = 0.1
batch_size = 128
num_steps = 1000
display_step = 100
#这里使用tf.data,高级的api博文会介绍到相关的内容
dataset = tf.data.Dataset.from_tensor_slices(
(mnist.train.images, mnist.train.labels))
dataset = dataset.repeat(