代码:
#-*- coding:utf-8 -*- #author : zhangwei import os import tensorflow as tf from tensorflow.examples.tutorials.mnist import input_data os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2' mnist = input_data.read_data_sets("MNIST_data" , one_hot=True) print '-----------------------开始设计图--------------------------' with tf.Graph().as_default(): with tf.name_scope('Input'): x = tf.placeholder(tf.float32 , shape=[None , 784] , name='input_x') y = tf.placeholder(tf.float32 , shape=[None , 10] , name='input_y') with tf.name_scope('Inference'): w = tf.Variable(tf.truncated_normal([784 , 10]) , name='Inference_w') b = tf.Variable(tf.zeros([10]) , name='Inference_b') logits = tf.add(tf.matmul(x , w) , b) with tf.name_scope('Softmax'): y_pred = tf.nn.softmax(logits) with tf.name_scope('Loss'): cross_entropy = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(logits=y_pred , labels=y) , name='Cross_entropy') writer = tf.summary.FileWriter(logdir='/home/zhangwei' , graph=tf.get_default_graph()) writer.close()