|
| 1 | +"""pneumoniamnist dataset.""" |
| 2 | + |
| 3 | +import tensorflow_datasets.public_api as tfds |
| 4 | + |
| 5 | + |
| 6 | +class Builder(tfds.core.GeneratorBasedBuilder): |
| 7 | + """DatasetBuilder for pneumoniamnist dataset.""" |
| 8 | + |
| 9 | + VERSION = tfds.core.Version('1.0.0') |
| 10 | + RELEASE_NOTES = { |
| 11 | + '1.0.0': 'Initial release.', |
| 12 | + } |
| 13 | + |
| 14 | + def _info(self) -> tfds.core.DatasetInfo: |
| 15 | + """Returns the dataset metadata.""" |
| 16 | + # TODO(pneumoniamnist): Specifies the tfds.core.DatasetInfo object |
| 17 | + return self.dataset_info_from_configs( |
| 18 | + features=tfds.features.FeaturesDict({ |
| 19 | + # These are the features of your dataset like images, labels ... |
| 20 | + 'image': tfds.features.Image(shape=(None, None, 3)), |
| 21 | + 'label': tfds.features.ClassLabel(names=['no', 'yes']), |
| 22 | + }), |
| 23 | + # If there's a common (input, target) tuple from the |
| 24 | + # features, specify them here. They'll be used if |
| 25 | + # `as_supervised=True` in `builder.as_dataset`. |
| 26 | + supervised_keys=('image', 'label'), # Set to `None` to disable |
| 27 | + homepage='https://dataset-homepage/', |
| 28 | + ) |
| 29 | + |
| 30 | + def _split_generators(self, dl_manager: tfds.download.DownloadManager): |
| 31 | + """Returns SplitGenerators.""" |
| 32 | + # TODO(pneumoniamnist): Downloads the data and defines the splits |
| 33 | + path = dl_manager.download_and_extract('https://todo-data-url') |
| 34 | + |
| 35 | + # TODO(pneumoniamnist): Returns the Dict[split names, Iterator[Key, Example]] |
| 36 | + return { |
| 37 | + 'train': self._generate_examples(path / 'train_imgs'), |
| 38 | + } |
| 39 | + |
| 40 | + def _generate_examples(self, path): |
| 41 | + """Yields examples.""" |
| 42 | + # TODO(pneumoniamnist): Yields (key, example) tuples from the dataset |
| 43 | + for f in path.glob('*.jpeg'): |
| 44 | + yield 'key', { |
| 45 | + 'image': f, |
| 46 | + 'label': 'yes', |
| 47 | + } |
0 commit comments