title: Numpy array in Keras Layer
body: <p>I want to adjust the image brightness of an input image that is feed into a keras model. The data is supplied from a simulator and feed into the model in real time so i need a way to adjust the image data in the model itself. I am currently using my own layer with openCV to perform the task but i am getting the following error.</p>
  
  <blockquote>
    <p>File "/usr/lib/python3/dist-packages/numpy/core/_methods.py", line 70, in _mean
        ret = ret.dtype.type(ret / rcount)
    AttributeError: 'DType' object has no attribute 'type'</p>
  </blockquote>
  
  <p>The issue appears to be with 'gamma = np.median(img) / 25' and the code trying to do numpy maths on a class 'tensorflow.python.framework.ops.Tensor'. </p>
  
  <p>My class code is </p>
  
  <pre><code>class ImageLayer(Layer):
  
  def __init__(self, **kwargs):
      super(ImageLayer, self).__init__(**kwargs)
  
  def call(self, img, mask=None):
  
      print(type(img))
      # adjust the image brightness to help normalise dark and light images
      gamma = np.median(img) / 25
      if gamma &gt; 5.:
          gamma = 5
      elif gamma &lt; 0.5:
          gamma = 0.5
      # build a lookup table mapping the pixel values [0, 255] to
      # their adjusted gamma values
      # http://www.pyimagesearch.com/2015/10/05/opencv-gamma-correction/
      invGamma = 1.0 / gamma
      table = np.array([((i / 255.0) ** invGamma) * 255
                        for i in np.arange(0, 256)]).astype("uint8")
  
      # apply gamma correction using the lookup table
      return cv2.LUT(img, table)
  </code></pre>
  
  <p>The model calls the class from the model</p>
  
  <pre><code>inputs = Input(shape=(160, 320, 3), dtype='int8')
  x = Cropping2D(cropping=((50,0), (0,0)), input_shape=(160, 320, 3), dim_ordering='tf')(inputs)
  x = ImageLayer()(x)
  x = BatchNormalization(epsilon=0.001, mode=0, axis=2, momentum=0.99)(x)
  </code></pre>
  
  <p>Is it possible to do what i want to do?</p>
  
  <p>Is it possible to perform numpy arithmetic in Keras? I know that you can in Tensorflow with .eval().</p>