首页 > 其他 > 详细

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

时间:2018-12-16 16:21:26      阅读:307      评论:0      收藏:0      [点我收藏+]

中国大学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))

  

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

原文:https://www.cnblogs.com/wbloger/p/10126856.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!