GithubHelp home page GithubHelp logo

tensorflow_practice_mooc's Introduction

tensorflow_practice_mooc

1 - 前向传播

def forward(x, regularizer):
    w = 
    b = 
    y = 
    return y
    
def get_weight(shape, regularizer):
    w = tf.Variable()
    tf.add_to_collection("loss", ...)
    return w

def get_bias(shape):
    b = 
    return b

2 - 反向传播

def backward():
    x = tf.placeholder()
    y = tf.placeholder()
    y_hat = 
    global_step = tf.Variable(0, trainable=False)
    loss = 
    <正则化指数衰减学习率滑动平均>
    train = 
    实例化saver
    with tf.Session() as sess:
        初始化所有变量
        for i in range(STEPS):
            sess.run(train, feed_dict={x:, y:})
            if i % 轮数 == 0:
                print()
                saver.save()

2.1 - 正则化

2.1.1 - 反向传播

ce = tf.nn.sparse_softmax_cross_entropy_with_logits(logits=y_hat, labels=tf.argmax(y, 1))
cem = tf.reduce_mean(ce)
loss = cem + tf.add_n(tf.get_collection("losses"))

2.1.2 - 前向传播

if regularizer != None:
    tf.add_to_collection("losses", tf.contrib.layers.l2_regularizer(regularizer)(w))

2.2 - 指数衰减学习率

learning_rate = tf.train.exponential_decay(LEARNING_RATE_BASE, 
                                            global_step, 
                                            LEARNING_RATE_STEP, 
                                            LEARNING_RATE_DECAY, 
                                            staircase = True)

2.3 - 滑动平均

ema = tf.train.ExponentialMovingAverage(MOVING_AVERAGE_DECAY, global_step)
ema_op = ema.apply(tf.trainable_variables())
with tf.control_dependencies([train_step, ema_op]):
    train_op = tf.no_op(name="train")

3 - 测试模型

def test(mnist):
    with tf.Graph().as_default() as g:  # tf.Graph()加载计算图中的节点
        定义xyy_hat
        实例化可以计算滑动平均值的saver对象
        正确率运算图定义
        while True:
            with tf.Session() as sess:
                不再初始化所有变量而是加载ckpt模型ckpt = tf.train.get_checkpoint_path(存储路径)
                如果已经有了ckpt模型if ckpt and ckpt.model_checkpoint_path:
                    恢复模型到当前会话 saver.restore(sess, ckpt.model_checkpoint_path)
                    恢复轮数 global_step =
                    执行正确率的计算 accuracy_score = 
                    打印
                如果没有模型提示模型没有找到

4 - 实例

LeNet for mnist.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.