AttributeError:“ int”对象没有属性“ value”

时间:2019-10-10 15:09:58

标签: tensorflow keras tf.keras

我无法解决我要到达这里的这个问题。我在Tensorflow 2上运行,我真的不明白为什么会出现此错误。有什么我想念的吗?

这是代码中出现错误的相关部分:

from tensorflow.lite.experimental.examples.lstm.rnn import bidirectional_dynamic_rnn
from tensorflow.lite.experimental.examples.lstm.rnn_cell import TFLiteLSTMCell

...

lstm_cells = []
lstm_0 = TFLiteLSTMCell(num_units=256, forget_bias=0, name='rnn_0')
lstm_1 = TFLiteLSTMCell(num_units=256, forget_bias=0, name='rnn_1')
lstm_2 = TFLiteLSTMCell(num_units=128, forget_bias=0, name='rnn_2')
lstm_3 = TFLiteLSTMCell(num_units=128, forget_bias=0, name='rnn_3')

lstm_cells.append(lstm_0)
lstm_cells.append(lstm_1)
lstm_cells.append(lstm_2)
lstm_cells.append(lstm_3)

bi_LSTM_2 = layers.Lambda(buildLstmLayer, arguments={'layers' : lstm_cells})(fc_1)

...

这是相应的Lambda层。我正在创建双向RNN,但我认为错误更多是与TFLiteLSTMCell本身有关,但我认为我正确使用了它。

def buildLstmLayer(inputs, layers):


  inputs = tf.transpose(inputs, [1,0,2])
  # inputs = tf.unstack(inputs, axis=1)

  inter_output, _ = bidirectional_dynamic_rnn (
      layers[0],
      layers[1],
      inputs,
      dtype='float32',
      time_major=True)

  inter_output = tf.concat(inter_output, 2)

  output, _ = bidirectional_dynamic_rnn (
      layers[2],
      layers[3],
      inter_output,
      dtype='float32',
      time_major=True)

  output = tf.concat(output, 2)
  # output = tf.stack(output, axis=1)

  output = tf.transpose(output, [1,0,2])

  return output

这是我得到的回溯:

Traceback (most recent call last):
  File "crnn_architecture.py", line 279, in <module>
    model, base_model = CRNN_model(is_training=True)
  File "crnn_architecture.py", line 108, in CRNN_model
    bi_LSTM_2 = layers.Lambda(buildLstmLayer, arguments={'layers' : lstm_cells})(fc_1)
  File "/usr/local/lib/python3.6/dist-packages/tensorflow_core/python/keras/engine/base_layer.py", line 847, in __call__
    outputs = call_fn(cast_inputs, *args, **kwargs)
  File "/usr/local/lib/python3.6/dist-packages/tensorflow_core/python/keras/layers/core.py", line 795, in call
    return self.function(inputs, **arguments)
  File "crnn_architecture.py", line 146, in buildLstmLayer
    time_major=True)
  File "/usr/local/lib/python3.6/dist-packages/tensorflow_core/lite/experimental/examples/lstm/rnn.py", line 379, in bidirectional_dynamic_rnn
    scope=fw_scope)
  File "/usr/local/lib/python3.6/dist-packages/tensorflow_core/lite/experimental/examples/lstm/rnn.py", line 266, in dynamic_rnn
    dtype=dtype)
  File "/usr/local/lib/python3.6/dist-packages/tensorflow_core/python/ops/rnn.py", line 916, in _dynamic_rnn_loop
    swap_memory=swap_memory)
  File "/usr/local/lib/python3.6/dist-packages/tensorflow_core/python/ops/control_flow_ops.py", line 2675, in while_loop
    back_prop=back_prop)
  File "/usr/local/lib/python3.6/dist-packages/tensorflow_core/python/ops/while_v2.py", line 198, in while_loop
    add_control_dependencies=add_control_dependencies)
  File "/usr/local/lib/python3.6/dist-packages/tensorflow_core/python/framework/func_graph.py", line 915, in func_graph_from_py_func
    func_outputs = python_func(*func_args, **func_kwargs)
  File "/usr/local/lib/python3.6/dist-packages/tensorflow_core/python/ops/while_v2.py", line 176, in wrapped_body
    outputs = body(*_pack_sequence_as(orig_loop_vars, args))
  File "/usr/local/lib/python3.6/dist-packages/tensorflow_core/python/ops/rnn.py", line 884, in _time_step
    (output, new_state) = call_cell()
  File "/usr/local/lib/python3.6/dist-packages/tensorflow_core/python/ops/rnn.py", line 870, in <lambda>
    call_cell = lambda: cell(input_t, state)
  File "/usr/local/lib/python3.6/dist-packages/tensorflow_core/python/keras/engine/base_layer.py", line 847, in __call__
    outputs = call_fn(cast_inputs, *args, **kwargs)
  File "/usr/local/lib/python3.6/dist-packages/tensorflow_core/python/keras/layers/recurrent.py", line 137, in call
    inputs, states = cell.call(inputs, states, **kwargs)
  File "/usr/local/lib/python3.6/dist-packages/tensorflow_core/lite/experimental/examples/lstm/rnn_cell.py", line 440, in call
    if input_size.value is None:
AttributeError: 'int' object has no attribute 'value'

0 个答案:

没有答案