1. import tensorflow as tfimport numpy as np
  2.  
  3. 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
  4.  
  5. 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
  6.  
  7. x_batch=tf.placeholder(tf.float32,[None,1])y_batch=tf.placeholder(tf.float32,[None,1])
  8.  
  9. 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]))
  10.  
  11. train_step=tf.train.GradientDescentOptimizer(0.1).minimize(loss)
  12.  
  13. init=tf.initialize_all_variables()sess=tf.Session()sess.run(init)
  14.  
  15. 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实现最简单的神经网络的更多相关文章

  1. 机器学习之路: tensorflow 一个最简单的神经网络

    git: https://github.com/linyi0604/MachineLearning/tree/master/07_tensorflow/ import tensorflow as tf ...

  2. tensorflow学习笔记四:mnist实例--用简单的神经网络来训练和测试

    刚开始学习tf时,我们从简单的地方开始.卷积神经网络(CNN)是由简单的神经网络(NN)发展而来的,因此,我们的第一个例子,就从神经网络开始. 神经网络没有卷积功能,只有简单的三层:输入层,隐藏层和输 ...

  3. tensorflow笔记(二)之构造一个简单的神经网络

    tensorflow笔记(二)之构造一个简单的神经网络 版权声明:本文为博主原创文章,转载请指明转载地址 http://www.cnblogs.com/fydeblog/p/7425200.html ...

  4. TensorFlow入门,基本介绍,基本概念,计算图,pip安装,helloworld示例,实现简单的神经网络

    TensorFlow入门,基本介绍,基本概念,计算图,pip安装,helloworld示例,实现简单的神经网络

  5. TensorFlow 深度学习笔记 卷积神经网络

    Convolutional Networks 转载请注明作者:梦里风林 Github工程地址:https://github.com/ahangchen/GDLnotes 欢迎star,有问题可以到Is ...

  6. ensorflow学习笔记四:mnist实例--用简单的神经网络来训练和测试

    http://www.cnblogs.com/denny402/p/5852983.html ensorflow学习笔记四:mnist实例--用简单的神经网络来训练和测试   刚开始学习tf时,我们从 ...

  7. 使用TensorFlow v2.0构建卷积神经网络

    使用TensorFlow v2.0构建卷积神经网络. 这个例子使用低级方法来更好地理解构建卷积神经网络和训练过程背后的所有机制. CNN 概述 MNIST 数据集概述 此示例使用手写数字的MNIST数 ...

  8. TensorFlow实现与优化深度神经网络

    TensorFlow实现与优化深度神经网络 转载请注明作者:梦里风林Github工程地址:https://github.com/ahangchen/GDLnotes欢迎star,有问题可以到Issue ...

  9. tensorflow rnn 最简单实现代码

    tensorflow rnn 最简单实现代码 #!/usr/bin/env python # -*- coding: utf-8 -*- import tensorflow as tf from te ...

随机推荐

  1. Linux下SSH远程连接断开后让程序继续运行解决办法

    一.screen安装 yum  install screen   #CentOS安装 sudo apt-get install screen #ubuntu安装 二.screen常用命令 screen ...

  2. spark DAG 笔记

    DAG,有向无环图,Directed Acyclic Graph的缩写,常用于建模. Spark中使用DAG对RDD的关系进行建模,描述了RDD的依赖关系,这种关系也被称之为lineage,RDD的依 ...

  3. B/S架构

    B/S架构即浏览器和服务器架构模式.它是随着Internet技术的兴起,对C/S架构的一种变化或者改进的架构.在这种架构下,用户工作界面是通过WWW浏览器来实现,极少部分事务逻辑在前端(Browser ...

  4. 蓝鲸DevOps深度解析系列(2):蓝盾流水线初体验

    关注嘉为科技,获取运维新知 前面一篇文章<蓝鲸DevOps深度解析系列(1):蓝盾平台总览>,我们总览了蓝鲸DevOps平台的背景.应用场景.特点和能力: ​ 接下来我们继续解析蓝盾平台的 ...

  5. Commander

    原文:https://www.npmjs.com/package/commander Commander.js Installation npm install commander --save Op ...

  6. Altium Designer添加元件库文件

    1 默认元件库路径 C:\Users\Public\Documents\Altium\AD 10.0.0.20340\Library 2 创建元件原理图库 图2.1 新建schlib 图2.2 绘制元 ...

  7. 8.5 GOF设计模式四: 观察者模式Observer

    GOF设计模式四: 观察者模式Observer  现实中遇到的问题  当有许多不同的客户都对同一数据源感兴趣,对相同的数据有不同的处理方式,该如 何解决?5.1 定义: 观察者模式  观察者模式 ...

  8. python3 doc2vec文本聚类实现

    import sys #doc2vev import gensim import sklearn import numpy as np from gensim.models.doc2vec impor ...

  9. js的一些常用方法

    1.判断是否为一个空对象 let a={}; console.log(Object.keys(arr).length==0);//true 2.从数组中取出重复的数据 var arr = [" ...

  10. IntelliJ IDEA激活

    以前一直使用eclipse,直到后来发现了IntelliJ IDEA,就爱上了它. 不过可惜的是,community版本虽然是免费的,不过功能相对较少,而ultimate版本的又需要花钱.但是我穷啊, ...