2017-11-15 1 views
0

예측을 수행하기 위해 LSTM 신경망을 사용하는 것. 데이터 세트에는 모든 Y 값에 대해 16 개의 X 값이 있습니다. 내가 알 수있는 한 열 X & Y 배열 또는 테스트 X & Y 배열 또는 둘 모두의 모양에 문제가 있다는 것을 알 수 있습니다. 나는 고쳐 썼다. 내 조정이 정확하지 않은 것 같다. 아래는 Jupyter Notebook의 with 출력에 따른 코드입니다. 귀하의 통찰력에 미리 감사드립니다.다음 오류 코드를 수정하려면 어떻게해야합니까? ValueError : Tensor 'InputData/X : 0'에 '(?, 16, 1)'모양의 도형 값 (64, 15)을 입력 할 수 없음

from __future__ import division, print_function, absolute_import 

#import pandas as pd 
import tflearn 
import numpy as np 
import math 
import matplotlib 
matplotlib.use('Agg') 
import matplotlib.pyplot as plt 
import tensorflow as tf 

def myRNN(): 
    tf.reset_default_graph() 
    # Network building 
    net = tflearn.input_data(shape=[None, 16, 1]) 
    net = tflearn.lstm(net, 32, dropout=0.8,bias=True) 
    net = tflearn.fully_connected(net, 1, activation='relu') 
    net = tflearn.regression(net, optimizer='adam', loss='mean_square', learning_rate=0.003) 

    #Gather the Training Data 
    csvData = np.genfromtxt('LabelCall5Data.csv', delimiter=',') 
    trainX = csvData[0:3360,0:15] 
    trainY = csvData[0:3360,16] 

    #Transpose the input Data 
    trainX = np.reshape(trainX, (-1, 16, 1)) 
    trainY = np.reshape(trainY, (-1, 1)) 
    print('trainX Shape: ', trainX.shape) 
    print('trainY Shape: ', trainY.shape) 

    #Gather the Testing Data 
    testX = csvData[3361:,0:15] 
    testY = csvData[3361:,16] 
    print('testY Shape: ', testX.shape) 
    print('testY Shape: ', testY.shape) 

    # Training 
    model = tflearn.DNN(net) 
    model.fit(trainX, trainY, n_epoch=100, validation_set=(testX, testY), show_metric=True) 

    # Predict the future values 
    predictY = model.predict(testX) 

    print("---------TEST ERROR-----------") 
    expected = np.array(testY).flatten() 
    predicted = np.array(predictY).flatten() 
    error = sum(((expected - predicted) **2)/len(expected)) 
    print(error)`enter code here` 

출력은 다음과 같습니다.

Training Step: 49 | total loss: 24915.56836 | time: 0.557s 
| Adam | epoch: 001 | loss: 24915.56836 - binary_acc: 0.0000 -- iter: 3136/3150 

--------------------------------------------------------------------------- 
ValueError        Traceback (most recent call last) 
<ipython-input-130-e193b95cc714> in <module>() 
----> 1 myRNN() 

<ipython-input-129-b039a187b4c6> in myRNN() 
    37  # Training 
    38  model = tflearn.DNN(net) 
---> 39  model.fit(trainX, trainY, n_epoch=100, validation_set=(testX, testY), show_metric=True) 
    40 
    41  # Predict the future values 

~/anaconda3/lib/python3.6/site-packages/tflearn/models/dnn.py in fit(self, X_inputs, Y_targets, n_epoch, validation_set, show_metric, batch_size, shuffle, snapshot_epoch, snapshot_step, excl_trainops, validation_batch_size, run_id, callbacks) 
    214       excl_trainops=excl_trainops, 
    215       run_id=run_id, 
--> 216       callbacks=callbacks) 
    217 
    218  def fit_batch(self, X_inputs, Y_targets): 

~/anaconda3/lib/python3.6/site-packages/tflearn/helpers/trainer.py in fit(self, feed_dicts, n_epoch, val_feed_dicts, show_metric, snapshot_step, snapshot_epoch, shuffle_all, dprep_dict, daug_dict, excl_trainops, run_id, callbacks) 
    337              (bool(self.best_checkpoint_path) | snapshot_epoch), 
    338              snapshot_step, 
--> 339              show_metric) 
    340 
    341        # Update training state 

~/anaconda3/lib/python3.6/site-packages/tflearn/helpers/trainer.py in _train(self, training_step, snapshot_epoch, snapshot_step, show_metric) 
    845    if show_metric and self.metric is not None: 
    846     eval_ops.append(self.metric) 
--> 847    e = evaluate_flow(self.session, eval_ops, self.test_dflow) 
    848    self.val_loss = e[0] 
    849    if show_metric and self.metric is not None: 

~/anaconda3/lib/python3.6/site-packages/tflearn/helpers/trainer.py in evaluate_flow(session, ops_to_evaluate, dataflow) 
    996 
    997   while feed_batch: 
--> 998    r = session.run(ops_to_evaluate, feed_batch) 
    999    current_batch_size = get_current_batch_size(feed_batch, dataflow) 
    1000    for i in range(len(r)): 

~/anaconda3/lib/python3.6/site-packages/tensorflow/python/client/session.py in run(self, fetches, feed_dict, options, run_metadata) 
    887  try: 
    888  result = self._run(None, fetches, feed_dict, options_ptr, 
--> 889       run_metadata_ptr) 
    890  if run_metadata: 
    891   proto_data = tf_session.TF_GetBuffer(run_metadata_ptr) 

~/anaconda3/lib/python3.6/site-packages/tensorflow/python/client/session.py in _run(self, handle, fetches, feed_dict, options, run_metadata) 
    1094     'Cannot feed value of shape %r for Tensor %r, ' 
    1095     'which has shape %r' 
-> 1096     % (np_val.shape, subfeed_t.name, str(subfeed_t.get_shape()))) 
    1097   if not self.graph.is_feedable(subfeed_t): 
    1098    raise ValueError('Tensor %s may not be fed.' % subfeed_t) 

ValueError: Cannot feed value of shape (64, 15) for Tensor 'InputData/X:0', which has shape '(?, 16, 1)' 

답변

0

문제는 당신이 trainX를 만들 때, 당신은 15의 값을 가지고 16

trainX = csvData[0:3360,0:15] 작성하지 것은 단지 당신에게 두 번째 차원에서 처음으로 15 개 채널을 제공한다는 것입니다. trainX = csvData[0:3360,0:16]으로 교체하십시오.

테스트 데이터에는 네트워크에 먹이를주기 전에 reshape d가 아닌 보너스가 동일한 문제가 있습니다. 그 결과 적절한 수의 측정 기준이 제공되지 않습니다.

+0

제안에 따라 코드가 업데이트되었으므로 이제는 다른 오류가 발생합니다. –

+0

trainX 형태 : (100, 16) trainY 모양 (100) 고쳐 trainX : (100, 16, 1) 고쳐 trainY (100, 1) 고쳐 testX : (100, 16, 1) 고쳐 testY : (100, 1) ----------------------------------------- ---------------------------------- IndexError 추적 (가장 최근의 마지막 호출) IndexError : 목록 색인 출력 범위의 –

+0

제안에 따라 코드를 조정 한 후에해야 할 일은 모두 Jupyter Notework로 커널을 다시 시작한 것입니다. 그 후 모든 일, 감사합니다 Sunreef !! 초보자가되기가 힘듭니다. :) –

관련 문제