| 查看: 765 | 回复: 1 | |||
[求助]
tensorflow神经网络问题请教 已有1人参与
|
|
请教下,我这段tensorflow代码误差一直收敛不了是为什么 import tensorflow as tf import numpy as np def 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) 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 # Make up some real data x_data = np.linspace(0.2, 13, 33)[:, np.newaxis] noise = np.random.normal(0, 0.05, x_data.shape) y_data = 2 * x_data + 2.2 + noise # define placeholder for inputs to network xs = tf.placeholder(tf.float32, [None, 1]) ys = tf.placeholder(tf.float32, [None, 1]) # add hidden layer l1 = add_layer(xs, 1, 10, activation_function=tf.nn.relu) # add output layer prediction = add_layer(l1, 10, 1, activation_function=None) # the error between prediciton and real data loss = tf.reduce_mean(tf.reduce_sum(tf.square( ys -prediction), reduction_indices=[1])) train_step = tf.train.GradientDescentOptimizer(0.1).minimize(loss) # important step init = tf.global_variables_initializer() sess= tf.Session() sess.run(init) for i in range(10000): # training sess.run(train_step, feed_dict={xs: x_data, ys: y_data}) if i % 50 == 0: # to see the step improvement print(sess.run(loss, feed_dict={xs: x_data, ys: y_data})) |
» 猜你喜欢
全日制(定向)博士
已经有5人回复
假如你的研究生提出不合理要求
已经有10人回复
萌生出自己或许不适合搞科研的想法,现在跑or等等看?
已经有4人回复
Materials Today Chemistry审稿周期
已经有4人回复
参与限项
已经有3人回复
实验室接单子
已经有4人回复
对氯苯硼酸纯化
已经有3人回复
求助:我三月中下旬出站,青基依托单位怎么办?
已经有12人回复
所感
已经有4人回复
要不要辞职读博?
已经有7人回复
懒青蛙吐泡泡
铁杆木虫 (正式写手)
- 应助: 3 (幼儿园)
- 金币: 5291
- 帖子: 483
- 在线: 184小时
- 虫号: 2245571
- 注册: 2013-01-17
- 性别: GG
- 专业: 非线性光学与量子光学
2楼2018-11-04 10:56:02












回复此楼