Tensorflow学习:单层神经网络的建立
来源:互联网 发布:scala二维数组 编辑:程序博客网 时间:2024/05/22 06:11
本文内容:简单的建立一个神经网络
注:由于前博客中已经写过了线性回归以及深度神经网络(cnn)的博客,这篇看起来更简单些。
# -*- coding: utf-8 -*-"""Created on Wed May 3 11:19:01 2017E-mail: Eric2014_Lv@sjtu.edu.cn@author: DidiLv"""import tensorflow as tfimport numpy as np# define a layerdef add_layer(inputs, in_size, out_size, activation_function = None): Weights = tf.Variable(tf.random_normal([in_size,out_size])) biases = tf.Variable(tf.zeros([1,out_size]) + 0.1) # better not all zeros Wx_plus_b = tf.matmul(inputs,Weights) + biases if activation_function is None: outputs = Wx_plus_b else: outputs = activation_function(Wx_plus_b) return outputs# create data pointsx_data = np.linspace(-1,1,300)[:, np.newaxis]noise = np.random.normal(0,0.05,x_data.shape)y_data = np.square(x_data) - 0.5 + noise# placeholderxs = tf.placeholder(tf.float32, [None, 1])ys = tf.placeholder(tf.float32, [None, 1])# structurel1 = add_layer(xs, 1, 10, activation_function = tf.nn.relu)prediction = add_layer(l1, 10, 1, activation_function = None)loss = tf.reduce_mean(tf.reduce_sum(tf.square(ys - prediction), reduction_indices= [1]))# triantrain_step = tf.train.GradientDescentOptimizer(0.2).minimize(loss)# initializationinit = tf.global_variables_initializer()with tf.Session() as sess: sess.run(init) for i in range(10000): sess.run(train_step, feed_dict = {xs: x_data, ys: y_data}) if i % 50 == 0: print(sess.run(loss, feed_dict = {xs: x_data, ys: y_data}))
0 0
- Tensorflow学习:单层神经网络的建立
- Tensorflow 搭建神经网络(单层)
- 译文 | 与TensorFlow的第一次接触 第四章:单层神经网络
- tensorflow学习:建立一个最简单的神经网络
- 单层神经网络、多层感知机、深度学习的总结
- 单层卷积神经网络的实现
- Tensorflow建立简易神经网络
- 单层神经网络
- tensorflow学习笔记二——建立一个简单的神经网络
- tensorflow学习笔记二——建立一个简单的神经网络拟合二次函数
- 神经网络学习之单层感知器
- TensorFlow入门(3)-单层神经网络实现方法
- 使用nntool神经网络工具箱建立单层感知器
- 参数自适应的单层 bp 神经网络
- 基于numpy+pandas的单层神经网络
- 单层感知器、线性神经网络、几种数据结构算法的学习报告
- 机器学习+周志华+第五章习题+解决异或问题的单层RBF神经网络
- tensroflow建立一个完整的单层网络
- 《算法导论》第4章 分治策略 个人笔记
- secure boot 的知识
- [编程题] 度度熊回家
- 【Android】判断应用Application、Activity、Service是否处于活动状态
- 二分贪心 U题
- Tensorflow学习:单层神经网络的建立
- cipher加密解密
- HDOJ 2011 多项式求和
- hdu5391Zball in Tina Town(素数鉴别的大猜想)
- 本blog停更,以后将使用个人blog站点:www.haibusuanyun.com
- LeetCode (Permutations)
- 1048: 【亲和数】
- HttpClient4.X 升级 入门 + http连接池使用
- C++在一定范围内生成不重复随机数序列