【发布时间】:2017-01-15 03:22:16
【问题描述】:
我正在尝试使用 tensorflow 的批处理系统(详见此处https://www.tensorflow.org/versions/master/how_tos/reading_data/index.html),使用我之前训练过的模型进行预测。目前我已将我在 tf.train.batch 中使用的批量大小设置为等于我想要进行预测的数据集的大小。
但是,我想创建一个验证集来测试我的预测并避免过度拟合。
有没有办法使用批处理系统将验证集与训练数据分开,或者是使用占位符的唯一方法?
以下是我负责训练的代码示例。它:
- 从 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) 阅读器 = tf.TextLineReader() 键、值 = 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
【问题讨论】:
标签: machine-learning tensorflow