Tensorflow basic_rnn_seq2seq TypeError: Expected int32, got -0.1 of type 'float' instead

11,101

This is an issue of confusing error message. The actual cause is, when you call tf.get_variable() but do not set the default initializer, the error message will be confusing. You can use a tf.zero_initializer() or something like that to suppress this error.

Share:
11,101
user3480922
Author by

user3480922

Updated on November 30, 2022

Comments

  • user3480922
    user3480922 over 1 year

    I am trying to run the encoder-decoder model on the dataset. Below is the sample code:

    self._input_data = tf.placeholder(tf.int32, [batch_size, num_steps])
    self._targets = tf.placeholder(tf.int32, [batch_size, num_steps])
    enc_inputs.append(self._input_data) #one batch at once
    dec_inputs.append(self._targets)
    model = seq2seq.basic_rnn_seq2seq(enc_inputs, dec_inputs, tf.nn.rnn_cell.BasicLSTMCell(size, state_is_tuple=True))
    

    I get an error of type mismatch (mentioned below). Does anyone know to solve the issue?

    tensor_util.py, line 290, in _AssertCompatible
        (dtype.name, repr(mismatch), type(mismatch).__name__))
        TypeError: Expected int32, got -0.1 of type 'float' instead.
    
    • user3480922
      user3480922 over 7 years
      Seems, changing tf.int32 to tf.float32 solves the issue. I don't know why but the program runs error-free now.
    • Paul Tucker
      Paul Tucker over 7 years
      The type error arises when you try to insert a float value into a tensor that has been typed as int32. tensor_util.py is used to construct tensors within python, prior to sending data or graph to the backend client for execution. It's not clear from your question exactly how to reproduce your error. How is _input_data being initialized? With values that include a float?
    • user3480922
      user3480922 over 7 years
      encode_input and decode_input are simple the word ids (integers). Next all processes are handled inside the basic_rnn_seq2seq API.