逻辑回归学习(一)

本文介绍了一个使用TensorFlow实现的手写数字识别模型。该模型采用简单的全连接网络结构,通过MNIST数据集训练并评估。文章展示了如何定义输入、权重、偏置等变量,并利用softmax函数进行分类预测,最后计算交叉熵损失。

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

代码:

#-*- 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()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值