2017-09-29 4 views
0

방금 ​​스택 오버플로 및 다른 포럼을 탐색했지만 내 도움이되는 항목을 찾을 수 없습니다. 문제. 하지만 그것은 this question과 관련이있는 것 같습니다.Tensorflow는 '(?, 128)'모양의 Tensor 'x : 0'에 대해 모양 값 (1,)을 입력 할 수 없습니다.

현재 Tensorflow의 MNIST 튜토리얼에 따라 내가 저장 한 Tensorflow (128 입력 및 11 출력)의 숙련 된 모델이 있습니다.

성공한 것으로 보입니다. 이제이 폴더에 3 개의 파일 (.meta, .ckpt.data 및 .index)이있는 모델이 있습니다.

ValueError: Cannot feed value of shape (1,) for Tensor 'x:0', which has shape '(?, 128)' Altough I print the shape of the 'unknowndata' and it matches the (1, 128). I also tried it with

sess.run(prediction, feed_dict={X: unknownData})) # with transposed etc. but nothing worked for me there I got the other error 

TypeError: unhashable type: 'list'

나는 단지이 아름다운 어떤 예측을 원하는 ...이

#encoding[0] => numpy ndarray (128,) # anyway a list with only one entry 
#unknowndata = np.array(encoding[0])[None] 
unknowndata = np.expand_dims(encoding[0], axis=0) 
print(unknowndata.shape) # Output (1, 128) 

# Restore pre-trained tf model 
with tf.Session() as sess: 
    #saver.restore(sess, "models/model_1.ckpt") 
    saver = tf.train.import_meta_graph('models/model_1.ckpt.meta') 
    saver.restore(sess,tf.train.latest_checkpoint('models/./')) 
    y = tf.get_collection('final tensor') # tf.nn.softmax(tf.matmul(y2, W3) + b3) 
    X = tf.get_collection('input') # tf.placeholder(tf.float32, [None, 128]) 

    # W1 = tf.get_collection('vars')[0] 
    # b1 = tf.get_collection('vars')[1] 
    # W2 = tf.get_collection('vars')[2] 
    # b2 = tf.get_collection('vars')[3] 
    # W3 = tf.get_collection('vars')[4] 
    # b3 = tf.get_collection('vars')[5] 

    # y1 = tf.nn.relu(tf.matmul(X, W1) + b1) 
    # y2 = tf.nn.relu(tf.matmul(y1, W2) + b2) 
    # yLog = tf.matmul(y2, W3) + b3 
    # y = tf.nn.softmax(yLog) 

    prediction = tf.argmax(y, 1) 

    print(sess.run(prediction, feed_dict={i: d for i,d in zip(X, unknowndata.T)})) 
    # also had sess.run(prediction, feed_dict={X: unknowndata.T}) and also not transposed, still errors 

# Output: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] # one should be 1 obviously with a specific percentage 

난 단지 문제가 실행 : 그러나, 나는 그것을 복원 할 및 예측을 위해 사용 Tensorflow는 훈련 된 모델입니다.

+1

안녕하세요. 오신 것을 환영합니다. StackOverflow! 여기서 사람들은 최대한 많은 것을 돕기 위해 바쁘다. 그래서 모든 사람이 코드의 벽을 읽을 시간이 없을 것이다. 게시물을 [** Minimal, Complete and Verifyable example **] (https://stackoverflow.com/help/mcve)에 포함 시키려면 게시물을 [편집] (https://stackoverflow.com/posts/46496213/edit)하는 것이 좋습니다.). 도움이 될 답변을 얻는 데 도움이됩니다. – LW001

+1

'sess.run (예측, feed_dict = {X [0] : unknownData}))'방법에 대해? – lejlot

+0

그게 내가 시도하고 작동하지만 거기에 오직 128 데이터 중 하나의 샘플을 필요로하고 그들 모두가 맞지 않아? 산출물은 또한 제게 열한 번 제로를 줄 것입니다 (최소한 하나는 거기에 있어야한다고 생각하는 사람은 아무도 없습니다) – lenlehm

답변

0

prediction 텐서는 y에서 argmax에 의해 얻어진다. sess.run을 실행하면 prediction 만 반환하는 대신 출력 피드에 y을 추가 할 수 있습니다.

output_feed = [prediction, y] 
preds, probs = sess.run(output_feed, print(sess.run(prediction, feed_dict={i: d for i,d in zip(X, unknowndata.T)})) 

preds 모델의 예측을 가질 것이며 probs는 확률 스코어를 가질 것이다.

1

문제를 발견했습니다. 먼저 모든 값 (가중치 및 바이어스를 별도로 복원해야 함)을 복원해야합니다. 두 번째는 내 경우, 훈련 모델에서와 동일한 입력을 만들어야합니다 다음

X = tf.placeholder(tf.float32, [None, 128]) 

하고 그냥 예측 전화 :

sess.run(prediction, feed_dict={X: unknownData}) 

하지만 어떤 비율 분포를 얻을 수 있지만하지 않습니다 softmax 기능으로 인해 그렇게 기대합니다. 아무도 그걸 액세스하는 방법을 알고 있습니까?

관련 문제