| | |
| | import os |
| | import torch |
| | from datasets import DatasetInfo, GeneratorBasedBuilder, BuilderConfig, Split, SplitGenerator |
| |
|
| | class LPBFConfig(BuilderConfig): |
| | def __init__(self, **kwargs): |
| | super().__init__(**kwargs) |
| |
|
| | class LPBFDataset(GeneratorBasedBuilder): |
| | VERSION = "1.0.0" |
| | BUILDER_CONFIGS = [ |
| | LPBFConfig(name="default", version=VERSION, description="Laser powder bed fusion additive manufacturing dataset") |
| | ] |
| |
|
| | |
| | def _info(self): |
| | return DatasetInfo( |
| | description="Laser powder bed fusion additive manufacturing dataset", |
| | features=None, |
| | ) |
| |
|
| | def _split_generators(self, dl_manager): |
| | """ |
| | After extraction, the dataset structure should look like: |
| | LPBF/train/*.pt |
| | LPBF/test/*.pt |
| | """ |
| | data_dir = dl_manager.download_and_extract( |
| | "https://huggingface.co/datasets/vedantpuri/LPBF_FLARE/resolve/main/LPBF.tar.gz" |
| | ) |
| |
|
| | |
| | |
| | split_train = os.path.join(data_dir, "LPBF", "train") |
| | split_test = os.path.join(data_dir, "LPBF", "test") |
| |
|
| | return [ |
| | SplitGenerator(name=Split.TRAIN, gen_kwargs={"data_dir": split_train}), |
| | SplitGenerator(name=Split.TEST, gen_kwargs={"data_dir": split_test}), |
| | ] |
| |
|
| |
|
| | def _generate_examples(self, data_dir): |
| | files = sorted([f for f in os.listdir(data_dir) if f.endswith(".pt")]) |
| | for idx, fname in enumerate(files): |
| | path = os.path.join(data_dir, fname) |
| | obj = torch.load(path, map_location="cpu") |
| | |
| | yield idx, {"graph": obj} |
| |
|