| 2 | 1/1 | 返回列表 |
| 查看: 788 | 回復: 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})) |
| 2 | 1/1 | 返回列表 |
| 最具人氣熱帖推薦 [查看全部] | 作者 | 回/看 | 最后發(fā)表 | |
|---|---|---|---|---|
|
[考研] 一志愿鄭大材料工程290求調劑 +18 | Youth_ 2026-03-30 | 18/900 |
|
|---|---|---|---|---|
|
[考研] 291求調劑 +16 | Y-cap 2026-03-29 | 19/950 |
|
|
[考研] 調劑 +3 | 好好讀書。 2026-04-01 | 3/150 |
|
|
[考研] 085600,材料與化工321分,求調劑 +11 | 大饞小子 2026-03-27 | 11/550 |
|
|
[考研] 317求調劑 +14 | 蛋黃咸肉粽 2026-03-26 | 15/750 |
|
|
[考研] 求調劑 +4 | 圖鑒212 2026-03-30 | 5/250 |
|
|
[考研] 材料調劑 +6 | 一樣YWY 2026-04-01 | 6/300 |
|
|
[考研] 085602化學工程268分蹲調劑 +6 | 月照花林。 2026-04-01 | 6/300 |
|
|
[考研] 一志愿中農0710生物學,微生物方向總分338求調劑 +3 | 柒xxxx. 2026-03-26 | 3/150 |
|
|
[考研] 070300一志愿211,312分求調劑院校 +13 | 小黃鴨寶 2026-03-30 | 13/650 |
|
|
[考研] 一志愿華南師范361分,化學求調劑 +4 | Nicole88888 2026-04-01 | 4/200 |
|
|
[考研] 301求調劑 +8 | axibli 2026-04-01 | 8/400 |
|
|
[考研] 一志愿南昌大學324求調劑 +6 | hanamiko 2026-03-29 | 6/300 |
|
|
[考研] 313求調劑 +6 | 賣個關子吧 2026-03-31 | 6/300 |
|
|
[考研] 269求調劑 +4 | 我想讀研11 2026-03-31 | 4/200 |
|
|
[考研] 求調劑 +7 | 青春裁為三截 2026-03-29 | 7/350 |
|
|
[考研] 081200-314 +3 | LILIQQ 2026-03-27 | 4/200 |
|
|
[考研] 308求調劑 +7 | 墨墨漠 2026-03-27 | 7/350 |
|
|
[考研] 272求調劑 +7 | 腳滑的守法公民 2026-03-27 | 7/350 |
|
|
[考研] 315調劑 +4 | 0860求調劑 2026-03-26 | 5/250 |
|