2

I want to know how to process images before being fed as an input to a Bidirectional LSTM. I always get this error whenever I run me code:

AttributeError: 'list' object has no attribute 'get_shape'

from this line:

outputs, _, _ = tf.nn.bidirectional_dynamic_rnn(lstm_fw_cell, lstm_bw_cell, x, dtype=tf.float32)

Here's a part of my code relevant to the problem:

def bi_rnn(features, labels, mode):
    x = tf.unstack(features, num_inputs, 1)
    ... # cell initialization
    # Get lstm cell output
    try:
        outputs, _, _ = tf.nn.bidirectional_dynamic_rnn(lstm_fw_cell, lstm_bw_cell, x, dtype=tf.float32)

... 

def serving_input_fn():
    feature_placeholders = {
        'features': tf.placeholder(tf.float32, [None, num_inputs])
    }
    features = {
        key: tf.expand_dims(tensor, -1) for key, tensor in feature_placeholders.items()
    }
    features = tf.squeeze(features, axis=[2])
    return InputFnOps(features, None, feature_placeholders)

def read_dataset(img_paths, labels):
    def _input_fn():
        ... # reading image paths omitted
        image_files = tf.image.decode_png(image_files)
        image_files = tf.image.resize_images(image_files, [1024, 128])
        image_files = evaluate_images(image_files)
        ... # labels part omitted
        return tf.convert_to_tensor(np.array(image_files)), labels2
    return _input_fn
Milind Anantwar
  • 81,290
  • 25
  • 94
  • 125
Rocket Pingu
  • 621
  • 9
  • 26
  • I can't trace the exact error using the provided code and error (having a full stack trace is generally more useful than just an error), but my guess would be that you are passing a python list where the method expects a Tensor. – iga Oct 02 '17 at 21:03
  • Here's the gist containing the code and the stacktrace https://gist.github.com/selcouthlyBlue/ee06c170ea22ee82695a219e871f9c2c – Rocket Pingu Oct 05 '17 at 03:43
  • Not sure if this is the problem, but the doc for bidirectional_dynamic_rnn requires `inputs` (`x` in your case) to be a Tensor or a tuple of Tensors. In the code from the gist, it is a list (as returned by `tf.unstack`). I am not sure why you even need the call to `tf.unstack` there? – iga Oct 05 '17 at 05:08

1 Answers1

0

I pretty much gave up on this one already and made something else work. It doesn't use the TFLearn features unlike this one. The recent one I'm working on has a problem which you can view here.

Rocket Pingu
  • 621
  • 9
  • 26