python - reading data in tensorflow - TypeError("%s that don't all match." % prefix) -
i trying load following data file (with 225805 rows) in tensor flow. data file looks this:
1,1,0.05,-1.05 1,1,0.1,-1.1 1,1,0.15,-1.15 1,1,0.2,-1.2 1,1,0.25,-1.25 1,1,0.3,-1.3 1,1,0.35,-1.35
the code reads data is
import tensorflow tf # read in data filename_queue = tf.train.string_input_producer(["~/input.data"]) reader = tf.textlinereader() key, value = reader.read(filename_queue) 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]) tf.session() sess: coord = tf.train.coordinator() threads = tf.train.start_queue_runners(coord=coord) in range(225805): example, label = sess.run([features, col4]) coord.request_stop() coord.join(threads)
and error getting
traceback (most recent call last): file "dummy.py", line 16, in <module> features = tf.pack([col1, col2, col3]) file "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/array_ops.py", 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/gen_array_ops.py", 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/op_def_library.py", line 437, in apply_op raise typeerror("%s don't match." % prefix) typeerror: tensors in list passed 'values' of 'pack' op have types [int32, int32, float32] don't match.
the tf.pack()
operator requires of tensors passed have same element type. in program, first 2 tensors have type tf.int32
, while third tensor has type tf.float32
. simplest solution cast first 2 tensors have type tf.float32
, using tf.to_float()
operator:
features = tf.pack([tf.to_float(col1), tf.to_float(col2), col3])
Comments
Post a Comment