MCPcopy
hub / github.com/nitrain/nitrain / record_generator

Function record_generator

nitrain/loaders/loader.py:168–189  ·  view source on GitHub ↗

This function takes a batch and returns individual records from it. It is necessary for tf.keras generators

(loader)

Source from the content-addressed store, hash-verified

166 return x
167
168def record_generator(loader):
169 """
170 This function takes a batch and returns individual records from it.
171
172 It is necessary for tf.keras generators
173 """
174 my_iter = iter(loader)
175 for x_batch, y_batch in my_iter:
176 if isinstance(x_batch, list) and isinstance(x_batch[0], np.ndarray):
177 if isinstance(y_batch, list) and isinstance(y_batch[0], np.ndarray):
178 for i in range(len(x_batch[0])):
179 yield tuple([xb[i] for xb in x_batch]), tuple([yb[i] for yb in y_batch])
180 else:
181 for i in range(len(x_batch[0])):
182 yield tuple([xb[i] for xb in x_batch]), y_batch[i]
183 else:
184 if isinstance(y_batch, list) and isinstance(y_batch[0], np.ndarray):
185 for i in range(len(x_batch)):
186 yield x_batch[i], tuple([yb[i] for yb in y_batch])
187 else:
188 for i in range(len(x_batch)):
189 yield x_batch[i], y_batch[i]

Callers 8

test_to_kerasMethod · 0.90
test_keras_multiMethod · 0.90
test_3d_no_expandMethod · 0.90
test_image_to_imageMethod · 0.90
to_kerasMethod · 0.85

Calls

no outgoing calls

Tested by 7

test_to_kerasMethod · 0.72
test_keras_multiMethod · 0.72
test_3d_no_expandMethod · 0.72
test_image_to_imageMethod · 0.72