深度学习框架tensorflow学习与应用9(tensorboard可视化)

本文介绍了TensorFlow模型的保存与加载机制,包括.meta图和检查点文件的作用。在训练过程中,若遇到CUDA库问题,如'cupti64_90.dll'无法打开,可通过特定解决方式进行修复。在Windows 10环境下,需在指定路径下运行tensorboard命令。同时,展示了如何利用tensorboard进行变量统计可视化。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


import tensorflow as tf
from tensorflow.examples.tutorials.mnist import input_data
from tensorflow.contrib.tensorboard.plugins import projector

# In[2]:

# 载入数据集
mnist = input_data.read_data_sets("G:/ATAGLIRL_tensorflow/MNIST_data/", one_hot=True)
# 运行次数
max_steps = 5001
# 图片数量
image_num = 10000  #可以改的,这是是3000张
#文件路径
DIR= "G:/ATAGLIRL_tensorflow/"

# 定义会话
sess = tf.Session()

# 载入图片
embedding = tf.Variable(tf.stack(mnist.test.images[:image_num]), trainable=False, name='embedding')


# 参数概要
def variable_summaries(var):
    with tf.name_scope('summaries'):
        mean = tf.reduce_mean(var)
        tf.summary.scalar('mean', mean)  # 平均值
        with tf.name_scope('stddev'):
            stddev = tf.sqrt(tf.reduce_mean(tf.square(var - mean)))
        tf.summary.scalar('stddev', stddev)  # 标准差
        tf.summary.scalar('max', tf.reduce_max(var))  # 最大值
        tf.summary.scalar('min', tf.reduce_min(var))  # 最小值
        tf.summary.histogram('histogram', var)  # 直方图


# 命名空间
with tf.name_scope('input'):
    # 这里的none表示第一个维度可以是任意的长度
    x = tf.placeholder(tf.float32, [None, 784], name='x-input')
    # 正确的标签
    y = tf.placeholder(tf.float32, [None, 10], name='y-input')

# 显示图片
with tf.name_scope('input_reshape'):
    #输入不确定所以是-1
    image_shaped_input = tf.reshape(x, [-1, 28, 28, 1])
    tf.summary.image('input', image_shaped_input, 10)

with tf.name_scope('layer1'):
    # 创建一个简单神经网络
    with tf.name_scope('weights1'):
        W1 = tf.Variable(tf.truncated_normal([784, 500],stddev=0.1),name='W1')
        variable_summaries(W1)
    with tf.name_scope('biases1'):
        b1 = tf.Variable(tf.zeros([500])+0.1,name='b1')
        variable_summaries(b1)
    with tf.name_scope('wx_plus_b1'):
        wx_plus_b1 = tf.matmul(x, W1) + b1
    # with tf.name_scope('softmax'):
    #     prediction = tf.nn.softmax(wx_plus_b)
   
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值