mrt*_*mrt 5 shuffle lstm keras rnn
当我使用.fit()图层训练模型时,参数shuffle预设为True.
假设我的数据集有100个样本,批量大小为10.当我设置shuffle = True然后keras首先随机随机选择样本(现在100个样本有不同的顺序),并且在新订单上它将开始创建批次:批处理1:1-10,批次2:11-20等
如果我设置shuffle = 'batch'它应该如何在后台工作?直观地使用前面的100个样本数据集的例子,批量大小= 10,我的猜测是keras首先将样本分配给批次(即批次1:数据集原始订单后的样本1-10,批次2:11-20以下数据集原始顺序,批次3 ......等等)然后洗牌批次的顺序.因此,模型现在将按随机订购的批次进行培训,例如:3(包含样品21 - 30),4(包含样品31 - 40),7(包含样品61 - 70),1(包含样品1 - 10) ),...(我编制了批次的顺序).
我的想法是正确还是我错过了什么?
谢谢!
看看这个链接的实现(training.py 的第 349 行),答案似乎是肯定的。
尝试使用此代码进行检查:
import numpy as np
def batch_shuffle(index_array, batch_size):
"""Shuffles an array in a batch-wise fashion.
Useful for shuffling HDF5 arrays
(where one cannot access arbitrary indices).
# Arguments
index_array: array of indices to be shuffled.
batch_size: integer.
# Returns
The `index_array` array, shuffled in a batch-wise fashion.
"""
batch_count = int(len(index_array) / batch_size)
# to reshape we need to be cleanly divisible by batch size
# we stash extra items and reappend them after shuffling
last_batch = index_array[batch_count * batch_size:]
index_array = index_array[:batch_count * batch_size]
index_array = index_array.reshape((batch_count, batch_size))
np.random.shuffle(index_array)
index_array = index_array.flatten()
return np.append(index_array, last_batch)
x = np.array(range(100))
x_s = batch_shuffle(x,10)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1076 次 |
| 最近记录: |