title: How to convert keras float predictions to int?
body: <p>I'm getting the error </p>
  
  <blockquote>
    <p>File "/anaconda/envs/tf3/lib/python3.6/site-packages/keras/engine/training.py", line 830, in compile
        sample_weight, mask)<br>
      File "/anaconda/envs/tf3/lib/python3.6/site-packages/keras/engine/training.py", line 445, in weighted
        score_array *= weights<br>
      File "/anaconda/envs/tf3/lib/python3.6/site-packages/tensorflow/python/ops/math_ops.py", line 898, in binary_op_wrapper
        y = ops.convert_to_tensor(y, dtype=x.dtype.base_dtype, name="y")<br>
      File "/anaconda/envs/tf3/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 932, in convert_to_tensor
        as_ref=False)<br>
      File "/anaconda/envs/tf3/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 1022, in internal_convert_to_tensor
        ret = conversion_func(value, dtype=dtype, name=name, as_ref=as_ref)<br>
      File "/anaconda/envs/tf3/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 866, in _TensorTensorConversionFunction
        (dtype.name, t.dtype.name, str(t)))
    ValueError: Tensor conversion requested dtype int32 for Tensor with dtype float32: 'Tensor("global_average_pooling2d_1_sample_weights:0", shape=(?,), dtype=float32)' </p>
  </blockquote>
  
  <p>during the training phase.</p>
  
  <p>Running the latest <code>Keras (2.1.3)</code> and <code>TensorFlow (1.5)</code> through <code>Conda</code>.</p>
  
  <p>Here is a minimum code that reproduces the error:</p>
  
  <pre><code>from keras.layers import Input, Conv2D, GlobalAveragePooling2D
  from keras.models import Model
  
  import keras.backend as K
  import numpy as np
  
  def test_loss(y_input, x_input):
  
      x1 = K.cast(x_input, dtype='int32')
      y1 = K.cast(y_input, dtype='int32')
  
      loss = K.square(x1 - y1)
  
  
      reduced_loss = K.cumsum(loss)
  
      return reduced_loss
  
  train_data = 10*np.random.rand(1600, 18,18,512)
  validation_data = 10*np.random.rand(200, 18,18,512)
  
  Y_train = np.random.rand(1600, 803)
  Y_test = np.random.rand(200, 803)
  
  #model
  inputs = Input(shape=train_data.shape[1:])
  x = Conv2D(803, (1,1), activation='sigmoid')(inputs)
  predictions = GlobalAveragePooling2D(input_shape=train_data.shape[1:])(x)
  model = Model(inputs=inputs, outputs=predictions)
  
  model.summary()
  
  model.compile(optimizer='adam', loss=test_loss,  metrics=['accuracy'])
  
  model.fit(train_data, Y_train,
                epochs=200,
                batch_size=1,
                validation_data=(validation_data, Y_test))
  </code></pre>