一、对项目8【tensorflow入门】建造入门级神经网络的代码进行改造
核心内容:
1、打开cmd命令提示符。
输入python -m pip install matplotlib进行自动的安装,系统会自动下载安装包。
2、导入工具包:import matplotlib.pyplot as plt
3、输入代码:with tf.name_scope('xxx'): 具体见程序。
4、核心代码!!!:writer = tf.summary.FileWriter("logs/",sess.graph) 注释见代码。
踩雷:莫烦视频中的tf.train.SummaryWriter已不适用,应当改为tf.summary.FileWriter 注意大小写。
import tensorflow as tf
import numpy as np
import matplotlib.pyplot as plt #Python中画图的工具包
#添加神经层的函数
def add_layer(inputs,in_size,out_size,activation_function=None):
with tf.name_scope('layer'):
with tf.name_scope('weights'):
Weights = tf.Variable(tf.random_normal([in_size,out_size]),name='W') #二维
with tf.name_scope('biases'):
biases = tf.Variable(tf.zeros