tensorflow实现单层感知机对MNIST分类

这篇博客介绍了如何使用TensorFlow实现单层感知机进行MNIST手写数字识别,准确率约为0.891。内容涵盖了tf.placeholder、tf.Variable、tf.reduce_sum和tf.argmax等关键API的用法,提供了代码示例和资源链接。

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

所有代码数据可在百度云下载:

链接: https://pan.baidu.com/s/1c31hKLM 密码: 4tpm

所有涉及tensorflow API用法的,均可查看https://tensorflow.google.cn/api_docs/

下面的代码实现了一个单层感知机(Single Layer Perceptron) y=softmax(wx+b),来处理MNIST手写数字识别问题。

# mnist_slp.py
# -*- coding: utf-8 -*-
import tensorflow as tf
from input_data import read_data_sets
import os

# don't show INFO 
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '1'

# read mnist
mnist = read_data_sets('MNIST_data', one_hot=True)


# single layer perceptron: y = wx + b
# input
x = tf.placeholder(tf.float32, [None, 784])

# weights
W = tf.Variable(tf.random_normal([784,10], stddev=0.1))

# bias
b = tf.Variable(tf.zeros([10]))

# softmax 
y = tf.nn.softmax(tf.matmul(x,W) + b)

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值