Args: augmentors (list[imgaug.Augmentor]): Defaults to `fbresnet_augmentor(isTrain)` Returns: A DataFlow which produces BGR images and labels. See explanations in the tutorial: http://tensorpack.readthedocs.io/tutorial/efficient-dataflow.html
(
datadir, name, batch_size,
augmentors=None, parallel=None)
| 65 | |
| 66 | |
| 67 | def get_imagenet_dataflow( |
| 68 | datadir, name, batch_size, |
| 69 | augmentors=None, parallel=None): |
| 70 | """ |
| 71 | Args: |
| 72 | augmentors (list[imgaug.Augmentor]): Defaults to `fbresnet_augmentor(isTrain)` |
| 73 | |
| 74 | Returns: A DataFlow which produces BGR images and labels. |
| 75 | |
| 76 | See explanations in the tutorial: |
| 77 | http://tensorpack.readthedocs.io/tutorial/efficient-dataflow.html |
| 78 | """ |
| 79 | assert name in ['train', 'val', 'test'] |
| 80 | isTrain = name == 'train' |
| 81 | assert datadir is not None |
| 82 | if augmentors is None: |
| 83 | augmentors = fbresnet_augmentor(isTrain) |
| 84 | assert isinstance(augmentors, list) |
| 85 | if parallel is None: |
| 86 | parallel = min(40, multiprocessing.cpu_count() // 2) # assuming hyperthreading |
| 87 | |
| 88 | if isTrain: |
| 89 | ds = dataset.ILSVRC12(datadir, name, shuffle=True) |
| 90 | ds = AugmentImageComponent(ds, augmentors, copy=False) |
| 91 | if parallel < 16: |
| 92 | logger.warn("DataFlow may become the bottleneck when too few processes are used.") |
| 93 | ds = MultiProcessRunnerZMQ(ds, parallel) |
| 94 | ds = BatchData(ds, batch_size, remainder=False) |
| 95 | else: |
| 96 | ds = dataset.ILSVRC12Files(datadir, name, shuffle=False) |
| 97 | aug = imgaug.AugmentorList(augmentors) |
| 98 | |
| 99 | def mapf(dp): |
| 100 | fname, cls = dp |
| 101 | im = cv2.imread(fname, cv2.IMREAD_COLOR) |
| 102 | im = aug.augment(im) |
| 103 | return im, cls |
| 104 | ds = MultiThreadMapData(ds, parallel, mapf, buffer_size=2000, strict=True) |
| 105 | ds = BatchData(ds, batch_size, remainder=True) |
| 106 | ds = MultiProcessRunnerZMQ(ds, 1) |
| 107 | return ds |
| 108 | |
| 109 | |
| 110 | """ |
no test coverage detected
searching dependent graphs…