varora commited on
Commit
3133cab
1 Parent(s): 3045785

Upload hit.py

Browse files
Files changed (1) hide show
  1. hit.py +151 -0
hit.py ADDED
@@ -0,0 +1,151 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright 2020 The HuggingFace Datasets Authors and the current dataset script contributor.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+ # TODO: Address all TODOs and remove all explanatory comments
15
+ """TODO: Add a description here."""
16
+
17
+
18
+ import csv
19
+ import json
20
+ import os
21
+ from glob import glob
22
+ import datasets
23
+ import pickle
24
+
25
+
26
+ # TODO: Add BibTeX citation
27
+ # Find for instance the citation on arxiv or on the dataset repo/website
28
+ _CITATION = """\
29
+ @inproceedings{Keller:CVPR:2024,
30
+ title = {{HIT}: Estimating Internal Human Implicit Tissues from the Body Surface},
31
+ author = {Keller, Marilyn and Arora, Vaibhav and Dakri, Abdelmouttaleb and Chandhok, Shivam and
32
+ Machann, Jürgen and Fritsche, Andreas and Black, Michael J. and Pujades, Sergi},
33
+ booktitle = {Proceedings IEEE/CVF Conf.~on Computer Vision and Pattern Recognition (CVPR)},
34
+ month = jun,
35
+ year = {2024},
36
+ month_numeric = {6}}
37
+ """
38
+
39
+ # TODO: Add description of the dataset here
40
+ # You can copy an official description
41
+ _DESCRIPTION = """\
42
+ The HIT dataset is a structured dataset of paired observations of body's inner tissues and the body surface. More concretely, it is a dataset of paired full-body volumetric segmented (bones, lean, and adipose tissue) MRI scans and SMPL meshes capturing the body surface shape for male (N=157) and female (N=241) subjects respectively. This is relevant for medicine, sports science, biomechanics, and computer graphics as it can ease the creation of personalized anatomic digital twins that model our bones, lean, and adipose tissue."""
43
+
44
+ # TODO: Add a link to an official homepage for the dataset here
45
+ _HOMEPAGE = "https://hit.is.tue.mpg.de/"
46
+
47
+ # TODO: Add the licence for the dataset here if you can find it
48
+ _LICENSE = "see https://huggingface.co/datasets/varora/HIT/blob/main/README.md"
49
+
50
+ # TODO: Add link to the official dataset URLs here
51
+ # The HuggingFace Datasets library doesn't host the datasets but only points to the original files.
52
+ # This can be an arbitrary nested dict/list of URLs (see below in `_split_generators` method)
53
+ _PATHS = {
54
+ "male": "/male",
55
+ "female": "/female",
56
+ }
57
+
58
+ # TODO: Name of the dataset usually matches the script name with CamelCase instead of snake_case
59
+ class NewDataset(datasets.GeneratorBasedBuilder):
60
+ """TODO: Short description of my dataset."""
61
+
62
+ VERSION = datasets.Version("1.1.0")
63
+
64
+ # This is an example of a dataset with multiple configurations.
65
+ # If you don't want/need to define several sub-sets in your dataset,
66
+ # just remove the BUILDER_CONFIG_CLASS and the BUILDER_CONFIGS attributes.
67
+
68
+ # If you need to make complex sub-parts in the datasets with configurable options
69
+ # You can create your own builder configuration class to store attribute, inheriting from datasets.BuilderConfig
70
+ # BUILDER_CONFIG_CLASS = MyBuilderConfig
71
+
72
+ # You will be able to load one or the other configurations in the following list with
73
+ # data = datasets.load_dataset('my_dataset', 'first_domain')
74
+ # data = datasets.load_dataset('my_dataset', 'second_domain')
75
+
76
+ def _info(self):
77
+ features = datasets.Features(
78
+ {
79
+ "gender": datasets.Value("string"),
80
+ "mri_seg": datasets.Value("int64"),
81
+ "mri_labels": dict,
82
+ "mri_seg_dict": dict,
83
+ "resolution": datasets.Value("double"),
84
+ "center": datasets.Value("double"),
85
+ "smpl_dict": dict,
86
+ "dataset_name": datasets.Value("string"),
87
+ "subject_ID": datasets.Value("string")
88
+ # These are the features of your dataset like images, labels ...
89
+ }
90
+ )
91
+ return datasets.DatasetInfo(
92
+ # This is the description that will appear on the datasets page.
93
+ description=_DESCRIPTION,
94
+ # This defines the different columns of the dataset and their types
95
+ features=features, # Here we define them above because they are different between the two configurations
96
+ # If there's a common (input, target) tuple from the features, uncomment supervised_keys line below and
97
+ # specify them. They'll be used if as_supervised=True in builder.as_dataset.
98
+ # supervised_keys=("sentence", "label"),
99
+ # Homepage of the dataset for documentation
100
+ homepage=_HOMEPAGE,
101
+ # License for the dataset if available
102
+ license=_LICENSE,
103
+ # Citation for the dataset
104
+ citation=_CITATION,
105
+ )
106
+
107
+ def _split_generators(self, dl_manager):
108
+ # TODO: This method is tasked with downloading/extracting the data and defining the splits depending on the configuration
109
+ # If several configurations are possible (listed in BUILDER_CONFIGS), the configuration selected by the user is in self.config.name
110
+ # dl_manager is a datasets.download.DownloadManager that can be used to download and extract URLS
111
+ # It can accept any type or nested list/dict and will give back the same structure with the url replaced with path to local files.
112
+ # By default the archives will be extracted and a path to a cached folder where they are extracted is returned instead of the archive
113
+ rel_path = _PATHS[self.config.name]
114
+ return [
115
+ datasets.SplitGenerator(
116
+ name=datasets.Split.TRAIN,
117
+ # These kwargs will be passed to _generate_examples
118
+ gen_kwargs={
119
+ "filepath": os.path.join(rel_path, "train", "*.gz"),
120
+ "split": "train",
121
+ },
122
+ ),
123
+ datasets.SplitGenerator(
124
+ name=datasets.Split.VALIDATION,
125
+ # These kwargs will be passed to _generate_examples
126
+ gen_kwargs={
127
+ "filepath": os.path.join(rel_path, "val", "*.gz"),
128
+ "split": "dev",
129
+ },
130
+ ),
131
+ datasets.SplitGenerator(
132
+ name=datasets.Split.TEST,
133
+ # These kwargs will be passed to _generate_examples
134
+ gen_kwargs={
135
+ "filepath": os.path.join(rel_path, "test", "*.gz"),
136
+ "split": "test"
137
+ },
138
+ ),
139
+ ]
140
+
141
+ # method parameters are unpacked from `gen_kwargs` as given in `_split_generators`
142
+ def _generate_examples(self, filepath, split):
143
+ # TODO: This method handles input defined in _split_generators to yield (key, example) tuples from the dataset.
144
+ # The `key` is for legacy reasons (tfds) and is not important in itself, but must be unique for each example.
145
+ # List all files in the path .gz
146
+ files = glob(filepath)
147
+ for subject_path in files:
148
+ with gzip.open(subject_path, 'rb') as f:
149
+ data = pickle.load(f)
150
+ key = data['subject_ID']
151
+ yield key, data