Created
July 13, 2016 01:46
-
-
Save yurkor/1816f025161a65ed54bd1803c7b7766c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def iterate_minibatches(inputs, targets, batchsize, shuffle=False): | |
assert len(inputs) == len(targets) | |
while True: | |
if shuffle: | |
indices = np.arange(len(inputs)) | |
np.random.shuffle(indices) | |
for start_idx in range(0, len(inputs) - batchsize + 1, batchsize): | |
if shuffle: | |
excerpt = indices[start_idx:start_idx + batchsize] | |
else: | |
excerpt = slice(start_idx, start_idx + batchsize) | |
yield inputs[excerpt], targets[excerpt] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment