()
| 497 | |
| 498 | |
| 499 | def test_as_array(): |
| 500 | batch_size = 64 |
| 501 | |
| 502 | class HybridPipe(Pipeline): |
| 503 | def __init__(self, batch_size, num_threads, device_id): |
| 504 | super(HybridPipe, self).__init__(batch_size, num_threads, device_id, seed=12) |
| 505 | self.input = ops.readers.Caffe(path=caffe_db_folder, random_shuffle=True) |
| 506 | self.decode = ops.decoders.Image(device="mixed", output_type=types.RGB) |
| 507 | self.cmnp = ops.CropMirrorNormalize( |
| 508 | device="gpu", |
| 509 | dtype=types.FLOAT, |
| 510 | crop=(224, 224), |
| 511 | mean=[128.0, 128.0, 128.0], |
| 512 | std=[1.0, 1.0, 1.0], |
| 513 | ) |
| 514 | self.coin = ops.random.CoinFlip() |
| 515 | self.uniform = ops.random.Uniform(range=(0.0, 1.0)) |
| 516 | self.iter = 0 |
| 517 | |
| 518 | def define_graph(self): |
| 519 | self.jpegs, self.labels = self.input() |
| 520 | images = self.decode(self.jpegs) |
| 521 | mirror = self.coin() |
| 522 | output = self.cmnp( |
| 523 | images, mirror=mirror, crop_pos_x=self.uniform(), crop_pos_y=self.uniform() |
| 524 | ) |
| 525 | return (output, self.labels) |
| 526 | |
| 527 | for i in range(10): |
| 528 | pipe = HybridPipe(batch_size=batch_size, num_threads=2, device_id=0) |
| 529 | pipe_out = pipe.run() |
| 530 | pipe_out_cpu = pipe_out[0].as_cpu() |
| 531 | img_chw_test = pipe_out_cpu.as_array() |
| 532 | if i == 0: |
| 533 | img_chw = img_chw_test |
| 534 | assert img_chw_test.shape == (batch_size, 3, 224, 224) |
| 535 | assert np.sum(np.abs(img_chw - img_chw_test)) == 0 |
| 536 | |
| 537 | |
| 538 | def test_seed_serialize(): |
nothing calls this directly
no test coverage detected