用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 ...
随机推荐
- 在线预览-Java 使用 Print2Flash 实现Office文档在线阅读
近期项目上遇到一个需求是用户上传的文档进行在线浏览,之前有过一篇使用 OpenOffice 将 word 转换成 html 页面进行展示的.现在介绍一个新的工具那就是 Print2Flash . ...
- C语言--第1次作业2.0版
1.本章学习总结 1.1思维导图 1.2本章学习体会及代码量学习体会 1.2.1学习体会 经过一周C语言的正式课堂学习,不同于暑期时扒视频囫囵吞枣式学习,林丽老师的讲解详细异常,尽管已经学习了一部分内 ...
- shell 按行读取文件的内容
test.py: #coding=utf- import subprocess compilePopen = subprocess.Popen('gcc haha',shell=True,stderr ...
- object的wait()、notify()、notifyAll()、方法和Condition的await()、signal()方法
wait().notify()和notifyAll()是 Object类 中的方法 从这三个方法的文字描述可以知道以下几点信息: 1)wait().notify()和notifyAll()方法是本地方 ...
- layui
给大家推荐个比较好用的前端ui框架layui,遵循原生HTML/CSS/JS的书写与组织形式,门槛极低,拿来即用,而且layui除了ie6/7不兼容其他都兼容,而且还是响应式布局 1,获得layui后 ...
- roc曲线和auc
只是为了复习一下,在评价分类器的性能好坏时,通常用recall和precision, PS:CNN做图像分类还是用了loss 和 accuracy 使用ROC的目的在于更好的(直观+量化)评价分类模型 ...
- Failed to find configured root that contains
这个主要问题是在android系统下7.0 拍照时,Android提供FileProvider类来供应用之间共享数据. 出现这个问题多为xml文件 path 类型和代码中调用的类型不同导致的 以下为多 ...
- 微信小程序 swiper轮播 自定义indicator-dots样式
index.wxml <view class="swiperContainer"> <swiper bindchange="swiperChange&q ...
- @validated各种坑
1.@validate不起作用 经过各种测试,在@validate后加了个modelattribute("form")就不验证了,坑.. 2.错误信息的properties配置文件 ...
- 【IDEA填坑】xml不编译
今天在maven编译Springboot项目的时候,发现src/main/resources下的配置文件编译失败(就是war包中没有放入xml配置文件导致程序启动失败),经查询资料,发现新版本的IDE ...