2017-10-19 60 views
0

我修改了&深层教程的代码,使用tf.contrib.learn.read_batch_examples从文件中读取大量输入。为了加快训练过程,我设置了read_batch_size并且出现错误ValueError:所有形状必须完全定义:[TensorShape([]),TensorShape([Dimension(None)])] 我的代码段:在tf.contrib.learn.read_batch_examples中设置read_batch_size时出现错误。默认是好的

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

对不起,我更新了我的代码。 –

+0

通过阅读代码,错误并不明显。你能发布你最小的完整(可运行)代码吗? – Mingxing

相关问题