我修改了广泛的代码。使用tf.contrib.learn.read_batch_examples从文件中读取大量输入的深入教程。为了加快训练过程,我设置了read_batch_size并出现错误 ValueError:所有形状必须完全定义:[TensorShape([]),TensorShape([Dimension(None)])] 我的代码:
def input_fn_pre(batch_size, filename):
examples_op = tf.contrib.learn.read_batch_examples(
filename,
batch_size=5000,
reader=tf.TextLineReader,
num_epochs=5,
num_threads=5,
read_batch_size=2500,
parse_fn=lambda x: tf.decode_csv(x, [tf.constant(['0'], dtype=tf.string)] * len(COLUMNS) * 2500, use_quote_delim=False))
examples_dict = {}
for i, col in enumerate(COLUMNS):
examples_dict[col] = examples_op[:, i]
feature_cols = {k: tf.string_to_number(examples_dict[k], out_type=tf.float32) for k in CONTINUOUS_COLUMNS}
feature_cols.update({k: dense_to_sparse(examples_dict[k]) for k in CATEGORICAL_COLUMNS})
label = tf.string_to_number(examples_dict[LABEL_COLUMN], out_type=tf.int32)
return feature_cols, label
使用默认参数设置时是正确的:
def input_fn_pre(batch_size, filename):
examples_op = tf.contrib.learn.read_batch_examples(
filename,
batch_size=5000,
reader=tf.TextLineReader,
num_epochs=5,
num_threads=5,
parse_fn=lambda x: tf.decode_csv(x, [tf.constant(['0'], dtype=tf.string)] * len(COLUMNS), use_quote_delim=False))
examples_dict = {}
for i, col in enumerate(COLUMNS):
examples_dict[col] = examples_op[:, i]
feature_cols = {k: tf.string_to_number(examples_dict[k], out_type=tf.float32) for k in CONTINUOUS_COLUMNS}
feature_cols.update({k: dense_to_sparse(examples_dict[k]) for k in CATEGORICAL_COLUMNS})
label = tf.string_to_number(examples_dict[LABEL_COLUMN], out_type=tf.int32)
return feature_cols, label
tensorflow doc中没有足够的解释。
答案 0 :(得分:0)
我发现您的两个代码段之间没有任何区别。你能更新你的代码吗?