首页 技术 正文
技术 2022年11月11日
0 收藏 562 点赞 2,468 浏览 2560 个字
import tensorflow as tfinput1 = tf.constant(1)
print(input1)input2 = tf.Variable(2,tf.int32)
print(input2)input2 = input1
sess = tf.Session()
print(sess.run(input2))

吴裕雄 python深度学习与实践(10)

import tensorflow as tfinput1 = tf.placeholder(tf.int32)
input2 = tf.placeholder(tf.int32)output = tf.add(input1, input2)sess = tf.Session()
print(sess.run(output, feed_dict={input1:[1], input2:[2]}))

吴裕雄 python深度学习与实践(10)

import numpy as np
import tensorflow as tf"""
这里是一个非常好的大数据验证结果,随着数据量的上升,集合的结果也越来越接近真实值,
这也是反馈神经网络的一个比较好的应用
这里不是很需要各种激励函数
而对于dropout,这里可以看到加上dropout,loss的值更快。
随着数据量的上升,结果就更加接近于真实值。
"""inputX = np.random.rand(3000,1)
noise = np.random.normal(0, 0.05, inputX.shape)
outputY = inputX * 4 + 1 + noise#这里是第一层
weight1 = tf.Variable(np.random.rand(inputX.shape[1],4))
bias1 = tf.Variable(np.random.rand(inputX.shape[1],4))
x1 = tf.placeholder(tf.float64, [None, 1])
y1_ = tf.matmul(x1, weight1) + bias1y = tf.placeholder(tf.float64, [None, 1])
loss = tf.reduce_mean(tf.reduce_sum(tf.square((y1_ - y)), reduction_indices=[1]))
train = tf.train.GradientDescentOptimizer(0.25).minimize(loss) # 选择梯度下降法init = tf.initialize_all_variables()
sess = tf.Session()
sess.run(init)for i in range(1000):
sess.run(train, feed_dict={x1: inputX, y: outputY})print(weight1.eval(sess))
print("---------------------")
print(bias1.eval(sess))
print("------------------结果是------------------")x_data = np.matrix([[1.],[2.],[3.]])
print(sess.run(y1_,feed_dict={x1: x_data}))

吴裕雄 python深度学习与实践(10)

import numpy as npaa = np.random.rand(5,4)
print(aa)
print(np.shape(aa))

吴裕雄 python深度学习与实践(10)

import tensorflow as tf
import numpy as np"""
这里是一个非常好的大数据验证结果,随着数据量的上升,集合的结果也越来越接近真实值,
这也是反馈神经网络的一个比较好的应用
这里不是很需要各种激励函数
而对于dropout,这里可以看到加上dropout,loss的值更快。
随着数据量的上升,结果就更加接近于真实值。
"""inputX = np.random.rand(3000,1)
noise = np.random.normal(0, 0.05, inputX.shape)
outputY = inputX * 4 + 1 + noise#这里是第一层
weight1 = tf.Variable(np.random.rand(inputX.shape[1],4))
bias1 = tf.Variable(np.random.rand(inputX.shape[1],4))
x1 = tf.placeholder(tf.float64, [None, 1])
y1_ = tf.matmul(x1, weight1) + bias1
#这里是第二层
weight2 = tf.Variable(np.random.rand(4,1))
bias2 = tf.Variable(np.random.rand(inputX.shape[1],1))
y2_ = tf.matmul(y1_, weight2) + bias2y = tf.placeholder(tf.float64, [None, 1])loss = tf.reduce_mean(tf.reduce_sum(tf.square((y2_ - y)), reduction_indices=[1]))
train = tf.train.GradientDescentOptimizer(0.25).minimize(loss) # 选择梯度下降法init = tf.initialize_all_variables()
sess = tf.Session()
sess.run(init)for i in range(1000):
sess.run(train, feed_dict={x1: inputX, y: outputY})print(weight1.eval(sess))
print("---------------------")
print(weight2.eval(sess))
print("---------------------")
print(bias1.eval(sess))
print("---------------------")
print(bias2.eval(sess))
print("------------------结果是------------------")x_data = np.matrix([[1.],[2.],[3.]])
print(sess.run(y2_,feed_dict={x1: x_data}))

吴裕雄 python深度学习与实践(10)

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:8,951
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,477
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,290
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,107
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,739
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,773