2017-10-12 2 views
0

모양이 여러 번 시도한 후에 모양 값 (128,)을 입력 할 수 없으므로이 오류를 해결하는 데 도움을 요청하십시오. 나는 csv 및 numpy 라이브러리에 의해 numpy 배열로 변형 된 로컬 csv 파일을 사용하여 deep autoencoder 네트워크를 교육하려고합니다. 그러나이 데이터는 절대로 내 자리 표시 자의 텐서로 공급되지 않습니다. 여기Tensorflow - ValueError : Tensor 'Placeholder_142 : 0'에 대해 '(?, 3433)

class Deep_Autoencoder: 
    def __init__(self, input_dim, n_nodes_hl = (32, 16, 1), epochs = 400, batch_size = 128, learning_rate = 0.02, n_examples = 10): 

    # Hyperparameters 
    self.input_dim = input_dim 
    self.epochs = epochs 
    self.batch_size = batch_size 
    self.learning_rate = learning_rate 
    self.n_examples = n_examples 

    # Input and target placeholders 
    X = tf.placeholder('float', [None, self.input_dim]) 
    Y = tf.placeholder('float', [None, self.input_dim]) 
    ... 

    self.X = X 
    print("self.X : ", self.X) 
    self.Y = Y 
    print("self.Y : ", self.Y) 
    ... 

def train_neural_network(self, data, targets): 

    with tf.Session() as sess: 
     sess.run(tf.global_variables_initializer()) 
     for epoch in range(self.epochs): 
      epoch_loss = 0 
      i = 0 

      # Let's train it in batch-mode 
      while i < len(data): 
       start = i 
       end = i + self.batch_size 

       batch_x = np.array(data[start:end]) 
       print("type batch_x :", type(batch_x)) 
       print("len batch_x :", len(batch_x)) 
       batch_y = np.array(targets[start:end]) 
       print("type batch_y :", type(batch_y)) 
       print("len batch_y :", len(batch_y)) 

       hidden, _, c = sess.run([self.encoded, self.optimizer, self.cost], feed_dict={self.X: batch_x, self.Y: batch_y}) 
       epoch_loss +=c 
       i += self.batch_size 

     self.saver.save(sess, 'selfautoencoder.ckpt') 
     print('Accuracy', self.accuracy.eval({self.X: data, self.Y: targets})) 

내가 입력 데이터를 작성하고 당신은 내가 당신의 정보에 대한 그들의 주요 기능을 인쇄 출력 할 수 있습니다 것을 알 수있다 이하 (I 열에서 실제로 관심이 있습니다 : 여기

깊은 autoencoder의 추상적이다 3 만) :

DAE = Deep_Autoencoder(input_dim = len(Train_x)) 
DAE.train_neural_network(Train_x.T[3], Train_y.T[3]) 

이 :

features_DeepAE = create_feature_sets(filename) 

Train_x = np.array(features_DeepAE[0]) 
Train_y = np.array(features_DeepAE[1]) 

print("type Train_x : ", type(Train_x)) 
print("type Train_x.T[3] : ", type(Train_x.T[3])) 
print("len Train_x : ", len(Train_x)) 
print("len Train_x.T[3] : ", len(Train_x.T[3])) 
print("shape Train_x : ", Train_x.shape) 
print("type Train_y : ", type(Train_y)) 
print("type Train_y.T[3] : ", type(Train_y.T[3])) 
print("len Train_y : ", len(Train_y)) 
print("len Train_y.T[3] : ", len(Train_y.T[3])) 
print("shape Train_y : ", Train_y.shape) 

그리고 여기가 코드를 실행

type Train_x : <class 'numpy.ndarray'> 
type Train_x.T[3] : <class 'numpy.ndarray'> 
len Train_x : 3433 
len Train_x.T[3] : 3433 
shape Train_x : (3433, 5) 
type Train_y : <class 'numpy.ndarray'> 
type Train_y.T[3] : <class 'numpy.ndarray'> 
len Train_y : 3433 
len Train_y.T[3] : 3433 
shape Train_y : (3433, 5) 
self.X : Tensor("Placeholder_142:0", shape=(?, 3433), dtype=float32) 
self.Y : Tensor("Placeholder_143:0", shape=(?, 3433), dtype=float32) 
type batch_x : <class 'numpy.ndarray'> 
len batch_x : 128 
type batch_y : <class 'numpy.ndarray'> 
len batch_y : 128 

그리고 마지막으로 오류 :

에 ValueError : (128) 형태의 값을 공급 할 수 없습니다 텐서 'Placeholder_142 : 0'에 대한 참고 출력물이다?, 모양 '을 (이, 3433) '

그리고 예 ... 저는 placeholder # 143에 있습니다 ... 그 많은 실패 (배치 및/또는 텐서 재 형성, 하나 및/또는 다른 트랜스 포즈, 인터넷 ..)! 필요한 경우 주저하지 말고 추가 정보를 요청하십시오.

+0

배치 중 하나를 인쇄하여 모양을 볼 수 있습니까? –

+0

어딘가에 코드를 업로드 할 수 있습니까? 네가 그렇게한다면 나는 그것을 실행하려고 노력할 것이다. – finbarr

+0

아마도'batch_x.shape'를 인쇄하십시오 –

답변

0

는 Avishkar Bhoopchand에 감사 amirbar를 해결 :

1에 input_dim을 설정하고 그들을 모양의 틀에 맞게 만들기 위해 batch_x과 batch_y에 "더미"차원을 추가 [?, 1]과 같은이 : batch_x = np.array (데이터 [시작 : 종료]) [:, 없음] 및 batch_y = np.array (대상 [시작 : 종료]) [:, 없음]. 없음은 Numpy 배열에 빈 차원을 추가합니다.

관련 문제