处理更大的tensorflow数据集

时间:2020-05-01 19:16:43

标签: python tensorflow iterator dataset

我是Tensorflow的新手,并且根据我在ts网站上找到的教程进行了一些模型训练。我已经能够满足我的初步要求的功能。

我正在本地读取一个csv文件,该文件提供了指向与写在同一csv行上的标签关联的图像的一些链接。我的代码大致如下:

$step_ids_array = $step_ids->toArray(); // Easier to work with if both are array (or collection)
for ($i = 0; $i < count($step_ids_array); ++$i) {
    $step_id = $step_ids_array[$i];
    $step_text = $steps_filt[$i];
    DB::table('steps')->where('id', $step_id)->update(['step' => $step_text]);
}                 

NB_IMG是我拥有的图像总数。此处的EPOCHS任意固定为给定值(通常为20或40),并且拆分是应用于NB_IMG的比率。

我所有的图像都在本地计算机上,使用该代码,我的GPU当前可以大致管理多达50000张图像。训练失败,显示更多图像(GPU耗尽)。我能理解这是由于我要一次读取所有数据,但是我有点受阻,无法在此处进行下一步以能够管理更大的数据集。

下面这部分是我认为需要改进的部分:

$combined = $step_ids->combine($steps_filt);

// $combined will now be a collection where the keys are the IDs and the values are the texts

foreach ($combined as $step_id => $step_text) {
    DB::table('steps')->where('id', $step_id)->update(['step' => $step_text]);
}

这里有人可以帮助我继续前进,并引导我走向一些示例或摘要,以便在更大的数据集上训练模型吗?我在这里迷失了下一步,并且不确定在ts文档中应该关注的地方。我没有在网上真正找到适合我需求的清晰示例。我应该如何循环处理不同的批次?迭代器如何编码?

谢谢!

2 个答案:

答案 0 :(得分:0)

那么,您能否提供有关两个功能process_imgread的更多信息吗?

在实验期间,我注意到shuffle函数在数据量很大且缓冲区很大的情况下会变慢。尝试注释该行,并检查其运行速度是否更快。如果是这样,您可以使用pandas加载CSV文件,然后将其随机播放并使用tf.data.Dataset.from_tensor_slices

Tensorflow现在具有用于描述模型和数据集管道(https://www.tensorflow.org/tensorboard/tensorboard_profiling_keras)的强大工具。

答案 1 :(得分:0)

readdef process_img(filename): img = tf.io.read_file(filename) return tf.image.decode_jpeg(img, channels=3) 是非常简单的功能:

def read(row):
  return row[1]
X, y = next(iter(dataset))

我的代码改组部分速度很慢,但似乎不是导致失败的原因,我可以删除它并直接从csv改组数据。如果数据集太大,似乎在body { font-family: Arial, Helvetica; font-size: 15px; line-height: 1.5; padding: 0; margin: 0; background-color: #F4F4F4; } .container { width: 70%; margin: auto; } #topbanner { background-color: #565656; color: #FFFFFF; } #hod { float: left; } div#hod ul { list-style-type: none; color: red; margin: 0px padding: 0px; } div#hod ul li { display: inline; }行会失败

感谢您提出的配置代码建议,我将尝试一下。还有其他方法可以在数据集中进行拆分和迭代吗?

相关问题