user3639557 user3639557 - 1 month ago 20x
Python Question

reading data in tensorflow - TypeError("%s that don't all match." % prefix)

I am trying to load the following data file (with 225805 rows) in tensor flow. The data file looks like this:


the code that reads the data is

import tensorflow as tf

# read in data
filename_queue = tf.train.string_input_producer(["~/"])
reader = tf.TextLineReader()
key, value =

record_defaults = [tf.constant([], dtype=tf.int32), # Column 1
tf.constant([], dtype=tf.int32), # Column 2
tf.constant([], dtype=tf.float32), # Column 3
tf.constant([], dtype=tf.float32)] # Column 4

col1, col2, col3, col4 = tf.decode_csv(value, record_defaults=record_defaults)
features = tf.pack([col1, col2, col3])

with tf.Session() as sess:
coord = tf.train.Coordinator()
threads = tf.train.start_queue_runners(coord=coord)

for i in range(225805):
example, label =[features, col4])


and this is the error I am getting

Traceback (most recent call last):
File "", line 16, in <module>
features = tf.pack([col1, col2, col3])
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/", line 487, in pack
return gen_array_ops._pack(values, axis=axis, name=name)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/", line 1462, in _pack
result = _op_def_lib.apply_op("Pack", values=values, axis=axis, name=name)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/", line 437, in apply_op
raise TypeError("%s that don't all match." % prefix)
TypeError: Tensors in list passed to 'values' of 'Pack' Op have types [int32, int32, float32] that don't all match.


The tf.pack() operator requires that all of the tensors passed to it have the same element type. In your program, the first two tensors have type tf.int32, while the third tensor has type tf.float32. The simplest solution is to cast the first two tensors to have type tf.float32, using the tf.to_float() operator:

features = tf.pack([tf.to_float(col1), tf.to_float(col2), col3])