title: Tensorflow 2.0 Warnings - dense_features is casting an input tensor from dtype float64 to the layer's dtype of float32
body: <p>I am reading over the Tensorflow 2.0 google website <a href="https://www.tensorflow.org/tutorials/structured_data/feature_columns#numeric_columns" rel="nofollow noreferrer">tutorial</a>, where they discuss the Feature Columns API. In the second in which they discuss numeric columns, the sample code generates the warning below. The warning seems to be about casting some data, but the message does not exactly explain how to fix the problem--that is, where should the user explicitly cast the data so that this warning is avoided.:</p>
  
  <pre><code>WARNING:tensorflow:Layer dense_features is casting an input tensor from dtype 
  float64 to the layer's dtype of float32, which is new behavior in TensorFlow 
  2.  The layer has dtype float32 because it's dtype defaults to floatx.
  
  If you intended to run this layer in float32, you can safely ignore this 
  warning. If in doubt, this warning is likely only an issue if you are porting 
  a TensorFlow 1.X model to TensorFlow 2.
  
  To change all layers to have dtype float64 by default, call 
  `tf.keras.backend.set_floatx('float64')`. To change just this layer, pass 
  dtype='float64' to the layer constructor. If you are the author of this layer, 
  you can disable autocasting by passing autocast=False to the base Layer 
  constructor.
  </code></pre>
  
  <p>I am trying to figure out how to fix this warning, because it is showing up on some of my own code too. The code to generate this warning is:</p>
  
  <pre><code>from __future__ import absolute_import, division, print_function, unicode_literals
  
  import numpy as np
  import pandas as pd
  
  import tensorflow as tf
  
  from tensorflow import feature_column
  from tensorflow.keras import layers
  from sklearn.model_selection import train_test_split
  
  URL = 'https://storage.googleapis.com/applied-dl/heart.csv'
  dataframe = pd.read_csv(URL)
  train, test = train_test_split(dataframe, test_size=0.2)
  train, val = train_test_split(train, test_size=0.2)
  print(len(train), 'train examples')
  print(len(val), 'validation examples')
  print(len(test), 'test examples')
  
  def df_to_dataset(dataframe, shuffle=True, batch_size=32):
    dataframe = dataframe.copy()
    labels = dataframe.pop('target')
    ds = tf.data.Dataset.from_tensor_slices((dict(dataframe), labels))
    if shuffle:
      ds = ds.shuffle(buffer_size=len(dataframe))
    ds = ds.batch(batch_size)
    return ds
  
  batch_size = 5 # A small batch sized is used for demonstration purposes
  train_ds = df_to_dataset(train, batch_size=batch_size)
  val_ds = df_to_dataset(val, shuffle=False, batch_size=batch_size)
  test_ds = df_to_dataset(test, shuffle=False, batch_size=batch_size)
  
  # We will use this batch to demonstrate several types of feature columns
  example_batch = next(iter(train_ds))[0]
  
  # A utility method to create a feature column
  # and to transform a batch of data
  def demo(feature_column):
    feature_layer = layers.DenseFeatures(feature_column)
    print(feature_layer(example_batch).numpy())
  
  age = feature_column.numeric_column("age")
  demo(age) # &lt;-- SHOULD TRIGGER OR DISPLAY THE WARNING
  </code></pre>
  
  <p>Any suggestions about how to fix this?</p>