2017-02-10 3 views
2

x_data를 feed_dict로 전달하려고했지만 오류가 발생했습니다. 코드에서 무엇이 잘못되었는지 확신 할 수 없습니다.Tensorflow : 1 차원 데이터의 모양이 일치하지 않습니다.

InvalidArgumentError (see above for traceback): You must feed a value for placeholder tensor 'x_12' with dtype int32 and shape [1000] 
    [[Node: x_12 = Placeholder[dtype=DT_INT32, shape=[1000], _device="/job:localhost/replica:0/task:0/cpu:0"]()]] 

내 코드 :

import tensorflow as tf 
import numpy as np 
model = tf.global_variables_initializer() 
#define x and y 
x = tf.placeholder(shape=[1000],dtype=tf.int32,name="x") 
y = tf.Variable(5*x**2-3*x+15,name = "y") 
x_data = tf.pack(np.random.randint(0,100,size=1000)) 
print(x_data) 
print(x) 
with tf.Session() as sess: 
    sess.run(model) 
    print(sess.run(y,feed_dict={x:x_data})) 

은 내가 xx_data의 모양을 확인하고 내가 한 차원 데이터로 작업하고

Tensor("pack_8:0", shape=(1000,), dtype=int32) 
Tensor("x_14:0", shape=(1000,), dtype=int32) 

동일합니다. 도움을 주시면 감사하겠습니다.

답변

1

두 가지를 변경하려면 먼저 yTensor으로 변경해야합니다. here을 주석으로 그리고 둘째로 나는 Tensorx_data을 변경하지 않은 :

옵션 feed_dict 인수는 그래프 텐서의 값을 대체하기 위해 호출 할 수 있습니다. feed_dict의 각 키는 다음 유형 중 하나 일 수 있습니다.

키가 Tensor 인 경우 해당 값은 해당 텐소와 동일한 dtype으로 변환 할 수있는 파이썬 스칼라, 문자열, 목록 또는 numpy ndarray 일 수 있습니다. 또한 키가 자리 표시자인 경우 값의 모양이 자리 표시 자와의 호환성을 검사합니다. 나를 위해 작동

변경된 코드 :

import tensorflow as tf 
import numpy as np 
model = tf.global_variables_initializer() 
#define x and y 
x = tf.placeholder(shape=[1000],dtype=tf.int32,name="x") 
y = 5*x**2-3*x+15 # without tf.Variable, making it a tf.Tensor 
x_data = np.random.randint(0,100,size=1000) # without tf.pack 
print(x_data) 
print(x) 
with tf.Session() as sess: 
    sess.run(model) 
    print(sess.run(y,feed_dict={x:x_data})) 
관련 문제