(dali_device="gpu", include_decoder=True, random_pipe=True)
| 39 | |
| 40 | @pipeline_def |
| 41 | def image_pipe(dali_device="gpu", include_decoder=True, random_pipe=True): |
| 42 | if include_decoder: |
| 43 | filepaths = fn.external_source(name="images", no_copy=True) |
| 44 | jpegs = fn.io.file.read(filepaths) |
| 45 | decoder_device = "mixed" if dali_device == "gpu" else "cpu" |
| 46 | |
| 47 | if random_pipe: |
| 48 | images = fn.decoders.image_random_crop( |
| 49 | jpegs, |
| 50 | device=decoder_device, |
| 51 | output_type=types.RGB, |
| 52 | random_aspect_ratio=[0.75, 4.0 / 3.0], |
| 53 | random_area=[0.08, 1.0], |
| 54 | ) |
| 55 | else: |
| 56 | images = fn.decoders.image( |
| 57 | jpegs, |
| 58 | device=decoder_device, |
| 59 | output_type=types.RGB, |
| 60 | ) |
| 61 | else: |
| 62 | images = fn.external_source(name="images", no_copy=True) |
| 63 | if random_pipe: |
| 64 | shapes = images.shape() |
| 65 | crop_anchor, crop_shape = fn.random_crop_generator( |
| 66 | shapes, random_aspect_ratio=[0.75, 4.0 / 3.0], random_area=[0.08, 1.0] |
| 67 | ) |
| 68 | images = fn.slice(images, start=crop_anchor, shape=crop_shape, axes=[0, 1]) |
| 69 | |
| 70 | images = fn.resize( |
| 71 | images, |
| 72 | size=[224, 224], |
| 73 | interp_type=types.INTERP_LINEAR, |
| 74 | antialias=False, |
| 75 | ) |
| 76 | mirror = fn.random.coin_flip(probability=0.5) if random_pipe else False |
| 77 | output = fn.crop_mirror_normalize( |
| 78 | images, |
| 79 | dtype=types.FLOAT, |
| 80 | output_layout="CHW", |
| 81 | crop=(224, 224), |
| 82 | mean=[0.485 * 255, 0.456 * 255, 0.406 * 255], |
| 83 | std=[0.229 * 255, 0.224 * 255, 0.225 * 255], |
| 84 | mirror=mirror, |
| 85 | ) |
| 86 | return output |
| 87 | |
| 88 | |
| 89 | @attr("pytorch") |
no test coverage detected