吴裕雄 python深度学习与实践(10)
import tensorflow as tf input1 = tf.constant(1)
print(input1) input2 = tf.Variable(2,tf.int32)
print(input2) input2 = input1
sess = tf.Session()
print(sess.run(input2))

import tensorflow as tf input1 = 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]}))

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) + bias1 y = 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}))

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

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) + bias2 y = 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深度学习与实践(18)
# coding: utf-8 import time import numpy as np import tensorflow as tf import _pickle as pickle impo ...
- 吴裕雄 python深度学习与实践(17)
import tensorflow as tf from tensorflow.examples.tutorials.mnist import input_data import time # 声明输 ...
- 吴裕雄 python深度学习与实践(16)
import struct import numpy as np import matplotlib.pyplot as plt dateMat = np.ones((7,7)) kernel = n ...
- 吴裕雄 python深度学习与实践(15)
import tensorflow as tf import tensorflow.examples.tutorials.mnist.input_data as input_data mnist = ...
- 吴裕雄 python深度学习与实践(14)
import numpy as np import tensorflow as tf import matplotlib.pyplot as plt threshold = 1.0e-2 x1_dat ...
- 吴裕雄 python深度学习与实践(13)
import numpy as np import matplotlib.pyplot as plt x_data = np.random.randn(10) print(x_data) y_data ...
- 吴裕雄 python深度学习与实践(12)
import tensorflow as tf q = tf.FIFOQueue(,"float32") counter = tf.Variable(0.0) add_op = t ...
- 吴裕雄 python深度学习与实践(11)
import numpy as np from matplotlib import pyplot as plt A = np.array([[5],[4]]) C = np.array([[4],[6 ...
- 吴裕雄 python深度学习与实践(7)
import cv2 import numpy as np img = np.mat(np.zeros((,))) cv2.imshow("test",img) cv2.waitK ...
随机推荐
- Curl追踪请求延时问题
背景原因:测试环境发现一个连接内网访问和外网访问延迟差别很大,内网访问很快.外网访问很慢.于是我们用curl来诊断问题所在的区域! 命令如下: curl -o /dev/null -s -w %{ti ...
- 【SpringData学习】
1.注解@Modifying 在springData中,大部分给出的接口都是查询的,那要进行删除和更新的时候,大部分都需要使用@Query 进行手写代码.并且需要使用@Modifying注解. 使用场 ...
- python实现简单的定时任务
1.首先安装 schedule 模块 命令行安装 pip install schedule pyCharm编辑器安装 File->setting->project:youProject-& ...
- Android SDK的下载与安装
一.Android SDK简介 Android SDK(Software Development Kit,软件开发工具包)被软件开发工程师用于为特定的软件包.软件框架.硬件平台.操作系统等建立应用软件 ...
- ios-项目启动页面
项目运行启动页面: 点工程项目targets-(或Images.xcasets)-LaunchImage(iphone四种规格图片:320*480/350*568/640*960/640*1136)将 ...
- PythonStudy——赋值运算符 Assignment operator
eg: num = 10 num += 1 # 等价于 num = num + 1 => 11 print(num) 特殊操作: 1.链式赋值 a = b = num print(a, b, n ...
- Dynamics 365 CRM 添加自定义按钮
在添加自定义按钮之前,我们需要下载这个工具 RibbonWorkbench, 它是专门针对自定义命令栏和Ribbon区域. 下载之后是一个zip压缩包. 怎样安装RibbonWorkbench: Se ...
- grafna与饼状图
官网: https://grafana.com/plugins/grafana-piechart-panel/installation https://grafana.com/p ...
- mvc ajax访问后台时session过期无法跳转到Login页面问题解决
public class BaseController : Controller { protected User UserInfo { set { Session["UserInfo&qu ...
- QQ群成员发言次数统计(正则表达式版)
1.先将QQ群的消息记录以.txt文件格式导出来,保存路径及名称自己定义(在本文我导出到Y盘,命名为test.txt) 2.程序如下: data statistics1; if _n_=1 then ...