0

Ceci est le codeerreur de valeur: ne peut pas alimenter la valeur de la forme (5, 15) pour 'one_hot: 0' Tensor, qui a une forme '(5, 15, 2)'

num_epochs = 100 
total_series_length = 50000 
truncated_backprop_length = 15 
state_size = 4 
num_classes = 2 
echo_step = 3 
batch_size = 5 
num_batches = total_series_length//batch_size//truncated_backprop_length 

données genreating { ...}

batchX_placeholder = tf.placeholder(tf.int32, [batch_size, truncated_backprop_length]) 
batchY_placeholder = tf.placeholder(tf.int32, [batch_size, truncated_backprop_length]) 

#and one for the RNN state, 5,4 
init_state = tf.placeholder(tf.float32, [batch_size, state_size]) 

batchX_placeholder = tf.one_hot(batchX_placeholder, num_classes) 
inputs_series = tf.unstack(batchX_placeholder, axis=1) 

cell = tf.contrib.rnn.BasicRNNCell(state_size) 
rnn_outputs, final_state = tf.contrib.rnn.static_rnn(cell, inputs_series, initial_state=init_state) 

un code d'optimisation {....} puis créer le graphique

#Step 3 Training the network 
with tf.Session() as sess: 
    #we stupidly have to do this everytime, it should just know 
    #that we initialized these vars. v2 guys, v2.. 
    sess.run(tf.initialize_all_variables()) 
    #interactive mode 
    plt.ion() 
    #initialize the figure 
    plt.figure() 
    #show the graph 
    plt.show() 
    #to show the loss decrease 
    loss_list = [] 

    for epoch_idx in range(num_epochs): 
     #generate data at eveery epoch, batches run in epochs 
     x,y = generateData() 
     #initialize an empty hidden state 
     _current_state = np.zeros((batch_size, state_size)) 

     print("New data, epoch", epoch_idx) 
     #each batch 
     for batch_idx in range(num_batches): 
      #starting and ending point per batch 
      #since weights reoccuer at every layer through time 
      #These layers will not be unrolled to the beginning of time, 
      #that would be too computationally expensive, and are therefore truncated 
      #at a limited number of time-steps 
      start_idx = batch_idx * truncated_backprop_length 
      end_idx = start_idx + truncated_backprop_length 

      batchX = x[:,start_idx:end_idx] 
      batchY = y[:,start_idx:end_idx] 

      #run the computation graph, give it the values 
      #we calculated earlier 
      _total_loss, _train_step, _final_state, _predictions_series = sess.run(
       [total_loss, train_step, final_state, predictions], 
       feed_dict={ 
        batchX_placeholder:batchX, 
        batchY_placeholder:batchY, 
        init_state:_current_state 
       }) 

      loss_list.append(_total_loss) 

      if batch_idx%100 == 0: 
       print("Step",batch_idx, "Loss", _total_loss) 
       plot(loss_list, _predictions_series, batchX, batchY) 

plt.ioff() 
plt.show() 

et cela l'erreur:

ValueError        Traceback (most recent call last) 
<ipython-input-9-7c3d1289d16b> in <module>() 
    40      batchX_placeholder:batchX, 
    41      batchY_placeholder:batchY, 
---> 42      init_state:_current_state 
    43     }) 
    44 

/home/pranshu_44/anaconda3/lib/python3.5/site-packages/tensorflow/python/client/session.py in run(self, fetches, feed_dict, options, run_metadata) 
    765  try: 
    766  result = self._run(None, fetches, feed_dict, options_ptr, 
--> 767       run_metadata_ptr) 
    768  if run_metadata: 
    769   proto_data = tf_session.TF_GetBuffer(run_metadata_ptr) 

/home/pranshu_44/anaconda3/lib/python3.5/site-packages/tensorflow/python/client/session.py in _run(self, handle, fetches, feed_dict, options, run_metadata) 
    942     'Cannot feed value of shape %r for Tensor %r, ' 
    943     'which has shape %r' 
--> 944     % (np_val.shape, subfeed_t.name, str(subfeed_t.get_shape()))) 
    945   if not self.graph.is_feedable(subfeed_t): 
    946    raise ValueError('Tensor %s may not be fed.' % subfeed_t) 

ValueError: Cannot feed value of shape (5, 15) for Tensor 'one_hot:0', which has shape '(5, 15, 2)' 

j'ai regardé les documents, mais cela ne veut pas utile du tout s'il y a un autre moyen facile qui sera également utile

Répondre

0

Vous transformez votre variable d'espace réservé à une représentation d'un chaud mais pas la conversion les données que vous alimentez réellement sur le réseau pendant la formation. Essayez de convertir batchX en une représentation à chaud avant de l'alimenter. Cet extrait va convertir la matrice à sa représentation chaude:

# Assuming that y contains values from 0 to N-1 where N is number of classes 
batchX = (np.arange(max(batchX.flatten())+1) = batchX[:,:,None]).astype(int) 
+0

merci l'homme .. cela a fonctionné !! c'était tellement studpid de moi .. –