title: Concatenate input with constant vector in keras
body: <p>I am trying to concatenate my input with a constant tensor in the keras-2 function API. In my real problem, the constants depend on some parameters in setup, but I think the example below shows the error I get.</p>
  
  <pre><code>from keras.layers import*
  from keras.models import *
  from keras import backend as K
  import numpy as np
  
  a = Input(shape=(10, 5))
  a1 = Input(tensor=K.variable(np.ones((10, 5))))
  x = [a, a1]  # x = [a, a] works fine
  b = concatenate(x, 1)
  x += [b]  # This changes b._keras_history[0].input
  b = concatenate(x, 1)
  model = Model(a, b)
  </code></pre>
  
  <p>The error I get is:</p>
  
  <pre><code>ValueError                                Traceback (most recent call last)
  ~/miniconda3/envs/ds_tools/lib/python3.6/site-packages/keras/engine/topology.py in assert_input_compatibility(self, inputs)
      418             try:
  --&gt; 419                 K.is_keras_tensor(x)
      420             except ValueError:
  
  ~/miniconda3/envs/ds_tools/lib/python3.6/site-packages/keras/backend/theano_backend.py in is_keras_tensor(x)
      198                           T.sharedvar.TensorSharedVariable)):
  --&gt; 199         raise ValueError('Unexpectedly found an instance of type `' + str(type(x)) + '`. '
      200                          'Expected a symbolic tensor instance.')
  
  ValueError: Unexpectedly found an instance of type `&lt;class 'theano.gpuarray.type.GpuArraySharedVariable'&gt;`. Expected a symbolic tensor instance.
  
  During handling of the above exception, another exception occurred:
  
  ValueError                                Traceback (most recent call last)
  &lt;ipython-input-2-53314338ab8e&gt; in &lt;module&gt;()
        5 a1 = Input(tensor=K.variable(np.ones((10, 5))))
        6 x = [a, a1]
  ----&gt; 7 b = concatenate(x, 1)
        8 x += [b]  # This changes b._keras_history[0].input
        9 b = concatenate(x, 1)
  
  ~/miniconda3/envs/ds_tools/lib/python3.6/site-packages/keras/layers/merge.py in concatenate(inputs, axis, **kwargs)
      506         A tensor, the concatenation of the inputs alongside axis `axis`.
      507     """
  --&gt; 508     return Concatenate(axis=axis, **kwargs)(inputs)
      509 
      510 
  
  ~/miniconda3/envs/ds_tools/lib/python3.6/site-packages/keras/engine/topology.py in __call__(self, inputs, **kwargs)
      550                 # Raise exceptions in case the input is not compatible
      551                 # with the input_spec specified in the layer constructor.
  --&gt; 552                 self.assert_input_compatibility(inputs)
      553 
      554                 # Collect input shapes to build layer.
  
  ~/miniconda3/envs/ds_tools/lib/python3.6/site-packages/keras/engine/topology.py in assert_input_compatibility(self, inputs)
      423                                  'Received type: ' +
      424                                  str(type(x)) + '. Full input: ' +
  --&gt; 425                                  str(inputs) + '. All inputs to the layer '
      426                                  'should be tensors.')
      427 
  
  ValueError: Layer concatenate_2 was called with an input that isn't a symbolic tensor. Received type: &lt;class 'theano.gpuarray.type.GpuArraySharedVariable'&gt;. Full input: [concatenate_1/input_3, concatenate_1/variable]. All inputs to the layer should be tensors.
  </code></pre>
  
  <p>I am running keras version <code>2.0.5</code> with the theano backend, with theano version <code>0.10.0dev1</code>. Any ideas on what is going wrong or a more correct way to accomplish the concatenation? </p>