将示例放在矩阵的行或列上的小批量中?
Placing examples in a mini-batch on the rows or columns of a matrix?
我正在使用 tensorflow 2.0 训练模型。我正在决定是否应该沿着矩阵的行或列批量放置多个示例。显然,这也会影响我设计模型的方式。有什么实用的建议比较好吗?
引用@山青菜
Putting examples in a batch along the rows of a matrix (i.e., the first axis of the input tensor) is the prevailing way of training deep learning models. Virtually any tensorflow2 / keras example you can find follows that pattern. Putting them along any non-first axis is much rarer.
如前所述,行维度是存储样本的首选方式。我可以想到两个原因,
TF 做了很多涉及批量数据的矩阵乘法。因此,通过将批量维度作为第一维度,您可以使用矩阵乘法连续生成张量,矩阵乘法也将批量维度作为第一维度。 (例如 [batch size, 10] . [10, 2]
产生 [batch size, 2]
)
另一个原因是行维度是变化最慢的维度。因此,您可以通过获取单个连续的内存块来访问单个样本,这在磁盘读取/内存读取方面始终是首选。
我正在使用 tensorflow 2.0 训练模型。我正在决定是否应该沿着矩阵的行或列批量放置多个示例。显然,这也会影响我设计模型的方式。有什么实用的建议比较好吗?
引用@山青菜
Putting examples in a batch along the rows of a matrix (i.e., the first axis of the input tensor) is the prevailing way of training deep learning models. Virtually any tensorflow2 / keras example you can find follows that pattern. Putting them along any non-first axis is much rarer.
如前所述,行维度是存储样本的首选方式。我可以想到两个原因,
TF 做了很多涉及批量数据的矩阵乘法。因此,通过将批量维度作为第一维度,您可以使用矩阵乘法连续生成张量,矩阵乘法也将批量维度作为第一维度。 (例如
[batch size, 10] . [10, 2]
产生[batch size, 2]
)另一个原因是行维度是变化最慢的维度。因此,您可以通过获取单个连续的内存块来访问单个样本,这在磁盘读取/内存读取方面始终是首选。