| 查看: 923 | 回复: 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})) |
» 猜你喜欢
极限拉扯,如何抉择
已经有15人回复
申请科研项目纯靠实力能成功吗?
已经有8人回复
中科院海洋所招收海洋材料相关领域博士研究生及研究助理
已经有4人回复
40+中年人失业后,还能找到好工作吗?
已经有3人回复
二审4个多月了还是Awaiting Reviewer Scores
已经有4人回复
OpenAI又攻克数学难题了,离AI做有机合成还有多远?
已经有13人回复
课题组会帮你通过考核么?
已经有7人回复
入职后第一次管课题组的专利缴费,对账才发现官费比别人多掏了一倍
已经有6人回复
售一区SCI文章T0P,我:8O.551.O54,科目全,可十急
已经有9人回复
售SCI一区文章,我:8O5.5.1.O5.4,科目全,可伽急
已经有10人回复
懒青蛙吐泡泡
铁杆木虫 (正式写手)
- 应助: 3 (幼儿园)
- 金币: 5301
- 帖子: 483
- 在线: 184小时
- 虫号: 2245571
- 注册: 2013-01-17
- 性别: GG
- 专业: 非线性光学与量子光学
2楼2018-11-04 10:56:02










回复此楼
200