zoukankan      html  css  js  c++  java
  • 学习进度笔记8

    观看Tensorflow案例实战视频课程08 迭代完成逻辑回归模型

    #PREDICTION
    pred=tf.equal(tf.argmax(actv,1),tf.argmax(y,1))
    #ACCURACY
    accr=tf.reduce_mean(tf.cast(pred,"float"))
    #INITIALIZER
    init=tf.global_variables_initializer()
    
    sess=tf.InteractiveSession()
    
    arr=np.array([[31,23,4,24,27,34],
                  [18,3,25,0,6,35],
                  [28,14,33,22,20,8],
                  [13,30,21,19,7,9],
                  [16,1,26,32,2,29],
                  [17,12,5,11,10,15]])
    tf.rank(arr).eval()#维度
    tf.shape(arr).eval()#行列
    tf.argmax(arr,0).eval()#按列最大值索引
    #0->31(arr[0,0])
    #3->30(arr[3,1])
    #2->33(arr[2,2])
    tf.argmax(arr,1).eval()#按行最大值索引
    #5->34(arr[0,5])
    #5->35(arr[1,5])
    #2->33(arr[2,2])
    
    training_epochs=50
    batch_size=100
    display_step=5
    #SESSION
    sess=tf.Session()
    sess.run(init)
    #MINI-BATCH LEARNING
    for epoch in range(training_epochs):
        avg_cost=0
        num_batch=int(mnist.train.num_examples/batch_size)
        for i in range(num_batch):
           batch_xs,batch_ys=mnist.train.next_batch(batch_size)
           sess.run(optm,feed_dict={x:batch_xs,y:batch_ys})
           feeds={x:batch_xs,y:batch_ys}
           avg_cost+=sess.run(cost,feed_dict=feeds)/num_batch
        #DISPLAY
        if epoch % display_step==0:
            feeds_train={x:batch_xs,y:batch_ys}
            feeds_test={x:mnist.test.images,y:mnist.test.labels}
            train_acc=sess.run(accr,feed_dict=feeds_train)
            test_acc=sess.run(accr,feed_dict=feeds_test)
            print("Epoch:%03d/%03d cost:%.9f train_acc:%.3f test_acc:%.3f"
                  % (epoch,training_epochs,avg_cost,train_acc,test_acc))
    print("DONE")
  • 相关阅读:
    react hooks子给父传值
    npm安装依赖 and 删除依赖
    react 阻止事件冒泡
    http 500状态码
    vue中插槽slot的使用
    怎样在vue项目中使用axios处理接口请求
    GET 与 POST 其实没有什么区别
    LazyMan
    什么是微服务,什么是分布式
    思索 p5.js 的最佳实践
  • 原文地址:https://www.cnblogs.com/zql-42/p/14587662.html
Copyright © 2011-2022 走看看