学习进度笔记7

Posted on 2021-01-10 22:04  九天龙凤  阅读(27)  评论(0编辑  收藏  举报

观看Tensorflow案例实战视频课程07 逻辑回归框架

import numpy as np
import tensorflow as tf
import matplotlib.pyplot as plt
import input_data
mnist=input_data.read_data_sets('data/',one_hot=True)
trainimg=mnist.train.images
trainlabel=mnist.train.lables
testimg=mnist.test.images
testlabel=mnist.test.labels
print("MNIST loaded")
print(trainimg.shape)
print(trainlabel.shape)
print(testimg.shape)
print(testlabel.shape)
#print(trainimg)
print(trainlabel[0])
x=tf.placeholder("float",[None,784])
y=tf.placeHolder("float",[None,10])#None is for infinite
W=tf.Variable(tf.zeros([784,10]))
b=tf.Variable(tf.zeros[10])
#LOGISTIC REGRESSION MODEL
actv=tf.nn.softmax(tf.matmul(x,W)+b)
#COST FUNCTION
cost=tf.reduce_mean(-tf.reduce_sum(y*tf.log(actv),reduction_indices=1))
#OPTIMIZER
learning_rate=0.01
optm=tf.train.GradientDescentOptimizer(learning_rate).minimize(cost)