Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TensorFlow 0.12 tutorials produce warning: "Rank of input Tensor should be the same as output_rank for column

I have some experience with writing machine learning programs in python, but I'm new to TensorFlow and am checking it out. My dev environment is a lubuntu 14.04 64-bit virtual machine. I've created a python 3.5 conda environment from miniconda and installed TensorFlow 0.12 and its dependencies. I began trying to run some example code from TensorFlow's tutorials and encountered this warning when calling fit() in the boston.py example for input functions: source.

WARNING:tensorflow:Rank of input Tensor (1) should be the same as output_rank (2) for column. Will attempt to expand dims. It is highly recommended that you resize your input, as this behavior may change.

After some searching in Google, I found other people encountered this same warning:

  • https://github.com/tensorflow/tensorflow/issues/6184
  • https://github.com/tensorflow/tensorflow/issues/5098
  • Tensorflow - Boston Housing Data Tutorial Errors

However, they also experienced errors which prevent code execution from completing. In my case, the code executes with the above warning. Unfortunately, I couldn't find a single answer in those links regarding what caused the warning and how to fix the warning. They all focused on the error. How does one remove the warning? Or is the warning safe to ignore?

Cheers!

Extra info, I also see the following warnings when running the aforementioned boston.py example.

WARNING:tensorflow:******************************************************* WARNING:tensorflow:TensorFlow's V1 checkpoint format has been deprecated. WARNING:tensorflow:Consider switching to the more efficient V2 format: WARNING:tensorflow:
'tf.train.Saver(write_version=tf.train.SaverDef.V2)' WARNING:tensorflow:now on by default. WARNING:tensorflow:*******************************************************

and

WARNING:tensorflow:From /home/kade/miniconda3/envs/tensorflow/lib/python3.5/site-packages/tensorflow/contrib/learn/python/learn/estimators/dnn_linear_combined.py:1053 in predict.: calling BaseEstimator.predict (from tensorflow.contrib.learn.python.learn.estimators.estimator) with x is deprecated and will be removed after 2016-12-01. Instructions for updating: Estimator is decoupled from Scikit Learn interface by moving into separate class SKCompat. Arguments x, y and batch_size are only available in the SKCompat class, Estimator will only accept input_fn. Example conversion: est = Estimator(...) -> est = SKCompat(Estimator(...))

UPDATE (2016-12-22): I've tracked the warning to this file: https://github.com/tensorflow/tensorflow/blob/master/tensorflow/contrib/layers/python/layers/feature_column_ops.py

and this code block:

except NotImplementedError:
    with variable_scope.variable_scope(
        None,
        default_name=column.name,
        values=columns_to_tensors.values()):
      tensor = column._to_dense_tensor(transformed_tensor)
      tensor = fc._reshape_real_valued_tensor(tensor, 2, column.name)
      variable = [
          contrib_variables.model_variable(
              name='weight',
              shape=[tensor.get_shape()[1], num_outputs],
              initializer=init_ops.zeros_initializer(),
              trainable=trainable,
              collections=weight_collections)
      ]
      predictions = math_ops.matmul(tensor, variable[0], name='matmul')

Note the line: tensor = fc._reshape_real_valued_tensor(tensor, 2, column.name)

The method signature is: _reshape_real_valued_tensor(input_tensor, output_rank, column_name=None)

The value 2 is hardcoded as the value of output_rank, but the boston.py example is passing in an input_tensor of rank 1. I will continue to investigate.

like image 444
The Traveling Coder Avatar asked Dec 21 '16 22:12

The Traveling Coder


1 Answers

If you specify the shape of your tensor explicitly:

tf.constant(df[k].values, shape=[df[k].size, 1]) 

the warning should go away.

like image 177
Montmorency Avatar answered Nov 11 '22 15:11

Montmorency