用tensorflow构建两层简单神经网络(全连接)

本文通过使用TensorFlow在China University Mooc的北京大学人工智能实践中,详细介绍了如何构建并运行一个简单的两层全连接神经网络。该网络包含输入层、隐藏层和输出层,使用随机初始化的权重矩阵,并通过会话计算特定输入数据的前向传播结果。

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

中国大学Mooc 北京大学 人工智能实践:Tensorflow笔记(week3)
#coding:utf-8
#两层简单神经网络(全连接)

import tensorflow as tf

#定义输入和参数
#用placeholder实现输入定义(sess.run中喂一组数据)
x = tf.placeholder(tf.float32, shape = (None, 2))
w1 = tf.Variable(tf.random_normal([2, 3], stddev = 1, seed = 1))
w2 = tf.Variable(tf.random_normal([3, 1], stddev = 1, seed = 1))

#定义向前传播过程
a = tf.matmul(x, w1)
y = tf.matmul(a, w2)


#用会话计算结果
with tf.Session() as sess:
    init_op = tf.global_variables_initializer()
    sess.run(init_op)
    print("the result of this exercise is \n", sess.run(y, feed_dict = {x:[[0.7, 0.5], [0.2, 0.3], [0.3, 0.4], [0.4, 0.5]]}))
    print("w1\n", sess.run(w1))
    print("w2\n", sess.run(w2))

  

转载于:https://www.cnblogs.com/wbloger/p/10126856.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值