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实现最简单的神经网络的更多相关文章

  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. 何给域名配置https证书

    原文链接:https://www.cnblogs.com/ymwang/p/6893105.html http和https的区别就是,后者在网络传输过程中会很安全,原因就是给http安装了SSL证书. ...

  2. C# 批量新增的两种方法。

    public class Test { private static readonly string strConnection = ""; public static void ...

  3. 修改vim的颜色主题 及显示行号

    1.打开vim窗口,输入命令:color 或者colorscheme后回车查看当前颜色主题. 2. 输入:colorscheme <主题> 即可设置当前vim的颜色主题. sample: ...

  4. git commit -m 提交的内容换行

    网上说只需要通过单引号来换行,一直没理解,后面终于试出来了.总结一句话就是. . 先输入第一个引号,按Enter即可换行,完成后再补齐后面的引号 // 步骤一: 输入第一行 git commit -m ...

  5. Antd Select组件结合使用出现must set key for <rc-animate> children问题

    一.以下情况可能导致错误发生 出现这个问题的首要条件是因为Select的mode 设置成multiple or tags 1. Select的defaultValue使用了空字符串 例如: const ...

  6. git命令合并分支代码

    对于复杂的系统,我们可能要开好几个分支来开发,那么怎样使用git合并分支呢? 合并步骤:1.进入要合并的分支(如开发分支合并到master,则进入master目录)git checkout maste ...

  7. 【转载】Java性能优化之JVM GC(垃圾回收机制)

    文章来源:https://zhuanlan.zhihu.com/p/25539690 Java的性能优化,整理出一篇文章,供以后温故知新. JVM GC(垃圾回收机制) 在学习Java GC 之前,我 ...

  8. WebvirtCloud安装(CentOS7)

    1.安装依赖包wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repoyum -y install p ...

  9. LeetCode--030--串联所有单词的字串(java)

    给定一个字符串 s 和一些长度相同的单词 words.找出 s 中恰好可以由 words 中所有单词串联形成的子串的起始位置. 注意子串要与 words 中的单词完全匹配,中间不能有其他字符,但不需要 ...

  10. poj3162

    这题卡常数了,nlogn链式前向星过了,用vector的O(n)没过. #include <iostream> #include <cstdio> #include <c ...