用tensorflow实现最简单的神经网络
import tensorflow as tfimport numpy as np
def add_layer(inputs,in_size,out_size,activation_function=None): """initialize the Weights and biases""" Weights=tf.Variable(tf.random_normal([in_size,out_size])) biases=tf.Variable(tf.zeros([1,out_size])+0.1) W_biases=tf.matmul(inputs,Weights)+biases if activation_function is None: outputs=W_biases else: outputs=activation_function(W_biases) return outputs
x_data=np.linspace(-1,1,300)[:,newaxis]noise=np.random.normal(0,0.05,x_data.shape)y_data=np.square(x_data)-0.5+noise
x_batch=tf.placeholder(tf.float32,[None,1])y_batch=tf.placeholder(tf.float32,[None,1])
l1=add_layer(xs,1,10,activation_function=tf.nn.relu)prediction=(l1,10,1,activation_function=None)loss=tf.reduce_mean(tf.reduce_sum(tf.square(ys-prediction),reduction_indices=[1]))
train_step=tf.train.GradientDescentOptimizer(0.1).minimize(loss)
init=tf.initialize_all_variables()sess=tf.Session()sess.run(init)
for i in range(1500): sess.run(train_step,feed_dict={xs:x_data,ys:y_data}) if i%100==0: print(sess.run(loss,feen_dict={xs:x_data,ys:y_data}))
用tensorflow实现最简单的神经网络的更多相关文章
- 机器学习之路: tensorflow 一个最简单的神经网络
git: https://github.com/linyi0604/MachineLearning/tree/master/07_tensorflow/ import tensorflow as tf ...
- tensorflow学习笔记四:mnist实例--用简单的神经网络来训练和测试
刚开始学习tf时,我们从简单的地方开始.卷积神经网络(CNN)是由简单的神经网络(NN)发展而来的,因此,我们的第一个例子,就从神经网络开始. 神经网络没有卷积功能,只有简单的三层:输入层,隐藏层和输 ...
- tensorflow笔记(二)之构造一个简单的神经网络
tensorflow笔记(二)之构造一个简单的神经网络 版权声明:本文为博主原创文章,转载请指明转载地址 http://www.cnblogs.com/fydeblog/p/7425200.html ...
- TensorFlow入门,基本介绍,基本概念,计算图,pip安装,helloworld示例,实现简单的神经网络
TensorFlow入门,基本介绍,基本概念,计算图,pip安装,helloworld示例,实现简单的神经网络
- TensorFlow 深度学习笔记 卷积神经网络
Convolutional Networks 转载请注明作者:梦里风林 Github工程地址:https://github.com/ahangchen/GDLnotes 欢迎star,有问题可以到Is ...
- ensorflow学习笔记四:mnist实例--用简单的神经网络来训练和测试
http://www.cnblogs.com/denny402/p/5852983.html ensorflow学习笔记四:mnist实例--用简单的神经网络来训练和测试 刚开始学习tf时,我们从 ...
- 使用TensorFlow v2.0构建卷积神经网络
使用TensorFlow v2.0构建卷积神经网络. 这个例子使用低级方法来更好地理解构建卷积神经网络和训练过程背后的所有机制. CNN 概述 MNIST 数据集概述 此示例使用手写数字的MNIST数 ...
- TensorFlow实现与优化深度神经网络
TensorFlow实现与优化深度神经网络 转载请注明作者:梦里风林Github工程地址:https://github.com/ahangchen/GDLnotes欢迎star,有问题可以到Issue ...
- tensorflow rnn 最简单实现代码
tensorflow rnn 最简单实现代码 #!/usr/bin/env python # -*- coding: utf-8 -*- import tensorflow as tf from te ...
随机推荐
- linux命令行安装teamviewer
teamviewer最新版本为14,但是Ubuntu14.04不支持,安装13版本即可. sudo dpkg -i teamviewer_13.2.26559_amd64.deb若报错,即缺少依赖,运 ...
- tomcat中显示本地图片①(已解决)
解决方案 我直接放源码了. 原理就是:我虽然调用的是虚拟目录,但是会映射到对应路径的实际 第一步:(在tomcat的 server.xml中创建一个虚拟目录) 虚拟目录创建方式: <Contex ...
- js中关于数组处理的一些小技巧
1 reduce方法同时实现map和filter 假设现在有一个数组,然后遍历它的每一项(map的功能)然后筛选出其中的一部分(filter的功能).如果使用map和filter的话,我们需要遍历这个 ...
- [名词解释 ] transparent
1.材质,效果透明. 2.思想透明,容易获取(思维简单,单纯) 3.后台静默(of a process or interface) functioning without the user being ...
- requests库爬取猫眼电影“最受期待榜”榜单 --网络爬虫
目标站点:https://maoyan.com/board/6 # coding:utf8 import requests, re, json from requests.exceptions imp ...
- Python自学:第三章 使用del语句删除元素
motorcycles = ["honda", "yamaha", "suzuki"] print(motorcycles) del mot ...
- python-*args和**kwargs作用和区别
1. *args 不定长的参数:*args 无论你传递一个参数还是二个还是多个都可以.(*args传入的是无命名参数,例如:add(1,2,3,4,5)存储的是元祖)args可以自定义其他名称 def ...
- 记录Sql2012附加Sql2008的数据库出错的解决方案
只需要对要附加的数据文件[右键]->[属性]->[安全]->(选择“Authenticated Users”用户)[编辑]->让“Authenticated Users”用户具 ...
- Linux进程管理的学习
uptime 简洁显示服务器负载 uptime 显示内核版本 uname -r dstat命令 cpu.内存.io等查看工具 dstat dstat --top-cpu dstat --top-io ...
- Mock.js常用占位符——Basic、Date、Color
1. Basic 在通过占位符引用方法时, Mock.mock('@boolean') : Mock.mock('@boolean()') 都可以调用方法 方法 含义 使用举例 Random.bo ...