ArrayFlow. Convert array samples to tensors and store them in a queue. Arguments: X: `array`. The features data array. Y: `array`. The targets data array. multi_inputs: `bool`. Set to True if X has multiple input sources (i.e. X is a list of arrays).
| 288 | |
| 289 | |
| 290 | class ArrayFlow(object): |
| 291 | """ ArrayFlow. |
| 292 | |
| 293 | Convert array samples to tensors and store them in a queue. |
| 294 | |
| 295 | Arguments: |
| 296 | X: `array`. The features data array. |
| 297 | Y: `array`. The targets data array. |
| 298 | multi_inputs: `bool`. Set to True if X has multiple input sources (i.e. |
| 299 | X is a list of arrays). |
| 300 | batch_size: `int`. The batch size. |
| 301 | shuffle: `bool`. If True, data will be shuffled. |
| 302 | |
| 303 | Returns: |
| 304 | The `X` and `Y` data tensors or a list(`X`) and `Y` data tensors if |
| 305 | multi_inputs is True. |
| 306 | |
| 307 | """ |
| 308 | def __init__(self, X, Y, multi_inputs=False, batch_size=32, shuffle=True, |
| 309 | capacity=None): |
| 310 | # Handle multiple inputs |
| 311 | if not multi_inputs: |
| 312 | X = [X] |
| 313 | if not capacity: |
| 314 | capacity =batch_size * 8 |
| 315 | X = [np.array(x) for x in X] |
| 316 | self.X = X |
| 317 | self.Xlen = len(X[0]) |
| 318 | Y = np.array(Y) |
| 319 | self.Y = Y |
| 320 | # Create X placeholders |
| 321 | self.tensorX = [tf.placeholder( |
| 322 | dtype=tf.float32, |
| 323 | shape=[None] + list(utils.get_incoming_shape(x)[1:])) |
| 324 | for x in X] |
| 325 | # Create Y placeholders |
| 326 | self.tensorY = tf.placeholder( |
| 327 | dtype=tf.float32, |
| 328 | shape=[None] + list(utils.get_incoming_shape(Y)[1:])) |
| 329 | # FIFO Queue for feeding data |
| 330 | self.queue = tf.FIFOQueue( |
| 331 | dtypes=[x.dtype for x in self.tensorX] + [self.tensorY.dtype], |
| 332 | capacity=capacity) |
| 333 | self.enqueue_op = self.queue.enqueue(self.tensorX + [self.tensorY]) |
| 334 | self.batch_size = batch_size |
| 335 | self.multi_inputs = multi_inputs |
| 336 | self.shuffle = shuffle |
| 337 | |
| 338 | def iterate(self, X, Y, batch_size): |
| 339 | while True: |
| 340 | # Shuffle array if specified |
| 341 | if self.shuffle: |
| 342 | idxs = np.arange(0, len(X[0])) |
| 343 | np.random.shuffle(idxs) |
| 344 | X = [x[idxs] for x in X] |
| 345 | Y = Y[idxs] |
| 346 | # Split array by batch |
| 347 | for batch_idx in range(0, self.Xlen, batch_size): |
no outgoing calls
no test coverage detected