首页 文章

Tensorflow - 使用批处理形成验证集

提问于
浏览
0

我'm attempting to use tensorflow'的批处理系统,详见此处https://www.tensorflow.org/versions/master/how_tos/reading_data/index.html,使用我之前训练过的模型进行预测 . 目前我已将我在tf.train.batch中使用的批量大小设置为等于我想要预测的数据集的大小 .

但是,我想创建一个验证集来测试我的预测并避免过度拟合 .

Is there a way to separate a validation set from the training data using the batching system or is the only way to use placeholders?

以下是我负责培训的代码示例 . 它:

  • 从CSV文件读取数据,将数据转换为张量

  • 将张量传递给tf.train.shuffle_batch进行训练

def input_pipeline(filename_list,batch_size,capacity):filename_queue = tf.train.string_input_producer(filename_list,num_epochs = None)reader = tf.TextLineReader()key,value = reader.read(filename_queue)

# Defaults force key value and label to int, all others to float.
record_defaults = [[1]]+[[46]]+[[1.0] for i in range(436)]
# Reads in a single row from the CSV and outputs a list of scalars.
csv_list = tf.decode_csv(value, record_defaults=record_defaults)
# Packs the different columns into separate feature tensors.
location = tf.pack(csv_list[2:4])
bbox = tf.pack(csv_list[5:8])
pix_feats = tf.pack(csv_list[9:])
onehot = tf.one_hot(csv_list[1], depth=98)
keep_prob = 0.5


# Creates batches of images and labels.
image_batch, label_batch = tf.train.shuffle_batch(
    [pix_feats, onehot], 
    batch_size=batch_size, num_threads=4, capacity=capacity, min_after_dequeue=30000)

return image_batch, label_batch

1 回答

  • 0

    我不确定你的record_defaults .

    所以有几种方法可以做到这一点 . 你可以有两个不同的“shuffle_batch”,它将接收训练数据,另一个将接收验证数据 . 然后你打电话来运行其中一个 .

    train_loss = train(train_set)
    val_loss = val(val_set)
    
    sess.run([train_loss]) # or sess.run([val_loss])
    

    占位符是另一种选择 .

相关问题