title: Keras using Lambda layers error with K.ctc_decode
body: <p>It appears that Keras has done alot of the heavy lifting for you when it comes to the CTC function. However I am finding it tricky to build a decode function which I don't want to run as part of my neural network. I have a custom function that is executed on epoch end which I then iterate through all my test data and evaluate the metrics, I am currently doing this by hand but want to make use of the k.ctc_decode function (both greedy and beam) however I am finding it hard to access and incorporate into my custom function.</p>
  
  <p>I have a model:</p>
  
  <pre><code> # Define CTC loss
      def ctc_lambda_func(args):
          y_pred, labels, input_length, label_length = args
          return K.ctc_batch_cost(labels, y_pred, input_length, label_length)
  
  def ctc_decode(args):
       y_pred, input_length =args
       seq_len = tf.squeeze(input_length,axis=1)
  
       return K.ctc_decode(y_pred=y_pred, input_length=seq_len, greedy=True, beam_width=100, top_paths=1)
  
  input_data = Input(name='the_input', shape=(None,mfcc_features))  
  x = TimeDistributed(Dense(fc_size, name='fc1', activation='relu'))(input_data) 
  y_pred = TimeDistributed(Dense(num_classes, name="y_pred", activation="softmax"))(x)
  
  labels = Input(name='the_labels', shape=[None,], dtype='int32')
  input_length = Input(name='input_length', shape=[1], dtype='int32')
  label_length = Input(name='label_length', shape=[1], dtype='int32')
  
  loss_out = Lambda(ctc_lambda_func, output_shape=(1,), name='ctc')([y_pred,labels,input_length,label_length])
  
  dec = Lambda(ctc_decode, output_shape=[None,], name='decoder')([y_pred,input_length])
  
  model = Model(inputs=[input_data, labels, input_length, label_length], outputs=[loss_out])
  
  
  
  iterate = K.function([input_data, K.learning_phase()], [y_pred])
  decode = K.function([y_pred, input_length], [dec])
  </code></pre>
  
  <p>Current error is:</p>
  
  <blockquote>
    <p>dec = Lambda(ctc_decode, name='decoder')([y_pred,input_length])   File
    "/home/rob/py27/local/lib/python2.7/site-packages/keras/engine/topology.py",
    line 604, in <strong>call</strong>
        output_shape = self.compute_output_shape(input_shape)   File "/home/rob/py27/local/lib/python2.7/site-packages/keras/layers/core.py",
    line 631, in compute_output_shape
        return K.int_shape(x)   File "/home/rob/py27/local/lib/python2.7/site-packages/keras/backend/tensorflow_backend.py",
    line 451, in int_shape
        shape = x.get_shape() AttributeError: 'tuple' object has no attribute 'get_shape'</p>
  </blockquote>
  
  <p>Any ideas how I can do this?</p>