| |
|
|
| """MNIST Point Cloud Data Set""" |
|
|
|
|
| import struct |
|
|
| import numpy as np |
|
|
| import datasets |
|
|
| _VERSION = "0.0.3" |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
| _DESCRIPTION = """\ |
| The MNIST dataset consists of 70,000 28x28 black-and-white points in 10 classes (one for each digits), with 7,000 |
| points per class. There are 60,000 training points and 10,000 test points. |
| """ |
|
|
| _URL = f"https://huggingface.co/datasets/cgarciae/point-cloud-mnist/resolve/{_VERSION}/data/" |
| _URLS = { |
| "train_points": "X_train.npy", |
| "train_labels": "y_train.npy", |
| "test_points": "X_test.npy", |
| "test_labels": "y_test.npy", |
| } |
|
|
|
|
| class MNIST(datasets.GeneratorBasedBuilder): |
| """MNIST Data Set""" |
|
|
| BUILDER_CONFIGS = [ |
| datasets.BuilderConfig( |
| name="point-cloud-mnist", |
| version=datasets.Version(_VERSION), |
| description=_DESCRIPTION, |
| ) |
| ] |
|
|
| def _info(self): |
| return datasets.DatasetInfo( |
| description=_DESCRIPTION, |
| features=datasets.Features( |
| { |
| "points": datasets.Array2D(shape=(351, 3), dtype="uint8"), |
| "label": datasets.features.ClassLabel( |
| names=["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"] |
| ), |
| } |
| ), |
| supervised_keys=("points", "label"), |
| |
| |
| ) |
|
|
| def _split_generators(self, dl_manager): |
| urls_to_download = {key: _URL + fname for key, fname in _URLS.items()} |
| downloaded_files = dl_manager.download_and_extract(urls_to_download) |
| return [ |
| datasets.SplitGenerator( |
| name=datasets.Split.TRAIN, |
| gen_kwargs={ |
| "filepath": [ |
| downloaded_files["train_points"], |
| downloaded_files["train_labels"], |
| ], |
| "split": "train", |
| }, |
| ), |
| datasets.SplitGenerator( |
| name=datasets.Split.TEST, |
| gen_kwargs={ |
| "filepath": [ |
| downloaded_files["test_points"], |
| downloaded_files["test_labels"], |
| ], |
| "split": "test", |
| }, |
| ), |
| ] |
|
|
| def _generate_examples(self, filepath, split): |
| """This function returns the examples in the raw form.""" |
| |
| with open(filepath[0], "rb") as f: |
| points = np.load(f) |
|
|
| |
| with open(filepath[1], "rb") as f: |
| labels = np.load(f) |
|
|
| for idx in range(len(points)): |
| yield ( |
| idx, |
| { |
| "points": points[idx], |
| "label": str(labels[idx]), |
| }, |
| ) |
|
|