Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/tensorflow/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Tensorflow 询问预测值错误的简单中性模型审查_Tensorflow - Fatal编程技术网

Tensorflow 询问预测值错误的简单中性模型审查

Tensorflow 询问预测值错误的简单中性模型审查,tensorflow,Tensorflow,我的代码如下,你会发现。 我想得到优化网络模型的正确模型。 但最终的计算值和实际情况相差甚远。 我认为网络代码有问题。 你介意检查并复习一下下面的内容并给我一些提示吗? 请非常感谢。 附件不允许上载此网站。 您可以制作简单的数据表并轻松地完成另一项工作 data2_10000.txt #n0 n1 #n2 n3 #y1 #y2 #y3 2.0 1.7 3.8 5.2 26.4 5.5 8.4 1.6 1.4 3.7 1.7 16.9 2.4 5.0

我的代码如下,你会发现。 我想得到优化网络模型的正确模型。 但最终的计算值和实际情况相差甚远。 我认为网络代码有问题。 你介意检查并复习一下下面的内容并给我一些提示吗? 请非常感谢。 附件不允许上载此网站。 您可以制作简单的数据表并轻松地完成另一项工作

data2_10000.txt 
    #n0 n1  #n2 n3  #y1 #y2 #y3
    2.0 1.7 3.8 5.2 26.4    5.5 8.4
    1.6 1.4 3.7 1.7 16.9    2.4 5.0
    0.2 2.3 3.3 3.9 2.7 0.2 6.8
    1.0 1.9 0.2 5.3 1.2 1.1 -2.0
    0.9 0.1 0.3 3.7 8.9 0.7 3.8
    1.2 1.9 3.9 4.3 18.8    1.2 7.6
    1.5 2.0 1.0 0.5 6.0 2.0 -0.9
    1.0 2.3 3.9 0.2 19.0    0.7 3.6
    1.6 1.1 1.6 2.1 5.7 2.3 2.8
    1.4 1.9 0.9 1.0 5.1 1.8 -0.5
    2.0 0.8 3.2 0.3 10.6    5.0 3.2
    0.6 2.3 2.9 0.8 8.0 0.3 3.0
    1.7 0.7 3.9 1.6 10.2    2.6 5.2
    1.6 1.2 3.0 3.0 12.2    2.5 5.5
    1.6 1.5 1.5 5.1 7.2 2.6 5.4
    1.4 0.6 0.8 4.6 2.2 1.9 4.6
    0.2 2.3 2.5 1.1 2.2 0.2 3.1
    1.2 0.2 1.0 3.0 3.5 1.1 3.9


import tensorflow as tf
import numpy as np
import matplotlib.pyplot as plt
import tensorflow as tf
import numpy as np

xy = np.genfromtxt('data2_10000.txt', delimiter='', dtype='float32')
x_data = xy[:, 0:-3]
y_data = xy[:, -1:]
row_x = x_data.shape[0]; column_x = x_data.shape[1]
row_y = y_data.shape[0]; column_y = y_data.shape[1]
#########
X = tf.placeholder(tf.float32)
Y = tf.placeholder(tf.float32)

hidden_layer_1st = 5  
W1 = tf.Variable(tf.random_uniform([column_x,hidden_layer_1st], -10.,10.))
W2 = tf.Variable(tf.random_uniform([hidden_layer_1st, column_y], -10., 10.)) # raw code
b1 = tf.Variable(tf.zeros([hidden_layer_1st])) # 
b2 = tf.Variable(tf.zeros([column_y])) # 
L1 = tf.add(tf.matmul(X, W1), b1)
L1 = tf.nn.relu(L1)
model_init = tf.add(tf.matmul(L1, W2), b2)
model1 = tf.nn.relu(model_init)
model = tf.nn.softmax(model1)
cost = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits_v2(labels=Y, logits=model))
optimizer = tf.train.AdamOptimizer(learning_rate=0.01)
train_op = optimizer.minimize(cost)

init = tf.global_variables_initializer()
sess = tf.Session()
sess.run(init)
i_value = []
cost_value = []
for step in range(10000):
    sess.run(train_op, feed_dict={X: x_data, Y: y_data})
    if (step + 1) % 500 == 0:
        i_value.append(step+1)
        cost_step = sess.run(cost, feed_dict={X: x_data, Y: y_data})
        cost_value.append(cost_step)
        print(step + 1, cost_step)
plt.plot(i_value,cost_value)
plt.ylabel('step')
plt.xlabel('cost')
plt.title('cost optimization and flow')
plt.show()

prediction = tf.argmax(model, 1)
target = tf.argmax(Y, 1)
print('prediction :', sess.run(prediction, feed_dict={X: x_data}))
print('target :', sess.run(target, feed_dict={Y: y_data}))
is_correct = tf.equal(prediction, target)
accuracy = tf.reduce_mean(tf.cast(is_correct, tf.float32))
print('정확도: %.2f' % sess.run(accuracy * 100, feed_dict={X: x_data, Y: y_data}))

x1 = [[2.0, 1.7, 3.8, 5.2], [1.6, 1.4, 3.7, 1.7]] 
cal1 = sess.run(L1, feed_dict={X : x1})
W1_factor = sess.run(W1); W2_factor = sess.run(W2)
b1_factor = sess.run(b1); b2_factor = sess.run(b2)
cal1 = sess.run(model_init, feed_dict={X : x1})
cal2 = sess.run(model1, feed_dict={X : x1})
cal3 = sess.run(model, feed_dict={X : x1})
print(cal1)
print(cal2)
print(cal3)

你得到了什么价值?你想用这个模型做什么?另外,为什么要使用旧的TensorFlow 1.x代码而不是新的TensorFlow 2.x代码?在我看来,2.x更容易使用。