0

Je construis un LSTM avec tensorflow et je pense que je suis mal en train de définir mes sorties parce que je reçois l'erreur suivante:erreur en forme de logits dans tensorflow

InvalidArgumentError (see above for traceback): logits and labels must have the same first dimension, got logits shape [160,14313] and labels shape [10] 
    [[Node: SparseSoftmaxCrossEntropyWithLogits/SparseSoftmaxCrossEntropyWithLogits = SparseSoftmaxCrossEntropyWithLogits[T=DT_FLOAT, Tlabels=DT_INT32, _device="/job:localhost/replica:0/task:0/cpu:0"](add, Reshape_1)]] 

clé ici étant: "obtenu logits forme [160,14313] et forme des étiquettes [10] ". Est-ce que le num_steps est toujours pris en compte pour la forme de la sortie?

L'entrée est num_steps (16) de largeur et la sortie est de taille juste 1, à la fois avec batch_size 10.

j'ai défini le réseau comme ceci:

x = tf.placeholder(tf.int32, [None, num_steps], name='input_placeholder') 
y = tf.placeholder(tf.int32, [None, 1], name='labels_placeholder') 


x_one_hot = tf.one_hot(x, num_classes) 
rnn_inputs = [tf.squeeze(i, squeeze_dims=[1]) for i in 
       tf.split(x_one_hot, num_steps, 1)] # still a list of tensors (batch_size, num_classes) 

tmp = tf.stack(rnn_inputs) 
print(tmp.get_shape()) 
tmp2 = tf.transpose(tmp, perm=[1, 0, 2]) 
print(tmp2.get_shape()) 

rnn_inputs = tmp2 


cell = tf.contrib.rnn.LSTMCell(state_size, state_is_tuple=True) 
cell = tf.contrib.rnn.MultiRNNCell([cell] * num_layers, state_is_tuple=True) 

init_state = cell.zero_state(batch_size, tf.float32) 
print(init_state) 
rnn_outputs, final_state = tf.nn.dynamic_rnn(cell, rnn_inputs, initial_state=init_state) 

with tf.variable_scope('softmax'): 
    W = tf.get_variable('W', [state_size, num_classes]) 
    b = tf.get_variable('b', [num_classes], initializer=tf.constant_initializer(0.0)) 

#reshape rnn_outputs and y 
rnn_outputs = tf.reshape(rnn_outputs, [-1, state_size]) 
y_reshaped = tf.reshape(y, [-1]) 

logits = tf.matmul(rnn_outputs, W) + b 

Répondre

1

fixe en ajoutant cette ligne:

rnn_outputs = rnn_outputs[:, num_steps-1, :]