Skip to content

Commit db7e67c

Browse files
committed
batch iterator wasnt indexing properly
1 parent 08e409d commit db7e67c

1 file changed

Lines changed: 12 additions & 16 deletions

File tree

python/libs/dataset_utils.py

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -51,24 +51,20 @@ def __init__(self, images, labels):
5151
def next_batch(self, batch_size=100):
5252
# Shuffle each epoch
5353
current_permutation = np.random.permutation(range(len(self.images)))
54-
epoch_images = np.array([self.images[idx]
55-
for idx in current_permutation])
54+
epoch_images = self.images[current_permutation, ...]
5655
epoch_labels = dense_to_one_hot(
57-
np.array([self.labels[idx] for idx in current_permutation]),
58-
self.n_labels)
56+
self.labels[current_permutation, ...], self.n_labels)
5957

6058
# Then iterate over the epoch
6159
self.current_batch_idx = 0
62-
self.current_obs_idx = 0
63-
while self.current_obs_idx < len(self.images):
60+
while self.current_batch_idx < len(self.images):
6461
end_idx = min(
6562
self.current_batch_idx + batch_size, len(self.images))
6663
this_batch = {
6764
'images': epoch_images[self.current_batch_idx:end_idx],
6865
'labels': epoch_labels[self.current_batch_idx:end_idx]
6966
}
70-
self.current_batch_idx += 1
71-
self.current_obs_idx += batch_size
67+
self.current_batch_idx += batch_size
7268
yield this_batch['images'], this_batch['labels']
7369

7470

@@ -90,8 +86,8 @@ def __init__(self, Xs, ys, split=[0.8, 0.1, 0.1]):
9086
n_idxs = len(self.all_inputs)
9187
idxs = range(n_idxs)
9288
rand_idxs = np.random.permutation(idxs)
93-
self.all_inputs = self.all_inputs[rand_idxs]
94-
self.all_labels = self.all_labels[rand_idxs]
89+
self.all_inputs = self.all_inputs[rand_idxs, ...]
90+
self.all_labels = self.all_labels[rand_idxs, ...]
9591

9692
# Get splits
9793
self.train_idxs = idxs[:round(split[0] * n_idxs)]
@@ -102,20 +98,20 @@ def __init__(self, Xs, ys, split=[0.8, 0.1, 0.1]):
10298

10399
@property
104100
def train(self):
105-
inputs = self.all_inputs[self.train_idxs]
106-
labels = self.all_labels[self.train_idxs]
101+
inputs = self.all_inputs[self.train_idxs, ...]
102+
labels = self.all_labels[self.train_idxs, ...]
107103
return DatasetSplit(inputs, labels)
108104

109105
@property
110106
def valid(self):
111-
inputs = self.all_inputs[self.valid_idxs]
112-
labels = self.all_labels[self.valid_idxs]
107+
inputs = self.all_inputs[self.valid_idxs, ...]
108+
labels = self.all_labels[self.valid_idxs, ...]
113109
return DatasetSplit(inputs, labels)
114110

115111
@property
116112
def test(self):
117-
inputs = self.all_inputs[self.test_idxs]
118-
labels = self.all_labels[self.test_idxs]
113+
inputs = self.all_inputs[self.test_idxs, ...]
114+
labels = self.all_labels[self.test_idxs, ...]
119115
return DatasetSplit(inputs, labels)
120116

121117
def mean(self):

0 commit comments

Comments
 (0)