MCPcopy Index your code
hub / github.com/lazyprogrammer/machine_learning_examples / test_generator

Function test_generator

cnn_class2/siamese.py:196–229  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

194
195# same thing as the train generator except no shuffling and it uses the test set
196def test_generator():
197 n_batches = int(np.ceil(len(test_positives) / batch_size))
198
199 while True:
200 n_samples = batch_size * 2
201 shape = [n_samples] + list(img.shape)
202 x_batch_1 = np.zeros(shape)
203 x_batch_2 = np.zeros(shape)
204 y_batch = np.zeros(n_samples)
205
206 for i in range(n_batches):
207 pos_batch_indices = test_positives[i * batch_size: (i + 1) * batch_size]
208
209 # fill up x_batch and y_batch
210 j = 0
211 for idx1, idx2 in pos_batch_indices:
212 x_batch_1[j] = test_images[idx1]
213 x_batch_2[j] = test_images[idx2]
214 y_batch[j] = 1 # match
215 j += 1
216
217 # get negative samples
218 neg_indices = np.random.choice(len(test_negatives), size=len(pos_batch_indices), replace=False)
219 for neg in neg_indices:
220 idx1, idx2 = test_negatives[neg]
221 x_batch_1[j] = test_images[idx1]
222 x_batch_2[j] = test_images[idx2]
223 y_batch[j] = 0 # non-match
224 j += 1
225
226 x1 = x_batch_1[:j]
227 x2 = x_batch_2[:j]
228 y = y_batch[:j]
229 yield [x1, x2], y
230
231
232

Callers 1

siamese.pyFile · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected