gvecchio commited on
Commit
bedaaa3
1 Parent(s): dda88c9

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +29 -6
README.md CHANGED
@@ -185,31 +185,54 @@ MatSynth is accessible through the datasets python library.
185
  Following a usage example:
186
 
187
  ```python
 
188
  from datasets import load_dataset
189
  from torch.utils.data import DataLoader
190
 
 
 
 
 
 
 
 
 
 
 
 
191
  # load the dataset in streaming mode
192
  ds = load_dataset(
193
  "gvecchio/MatSynth",
194
  streaming = True,
195
  )
196
 
197
- # remove unnecessary columns to reduce downloaded data
198
  ds = ds.remove_columns(["diffuse", "specular", "displacement", "opacity", "blend_mask"])
199
- # keep only specified columns
200
- ds = ds.select_columns(["metadata", "basecolor", "normal", "roughness", "metallic"])
 
 
 
201
 
202
  # filter data matching a specific criteria, e.g.: only CC0 materials
203
  ds = ds.filter(lambda x: x["metadata"]["license"] == "CC0")
 
 
204
 
205
- # shuffle data
206
- ds = ds.shuffle(buffer_size=100)
207
 
208
  # set format for usage in torch
209
  ds = ds.with_format("torch")
210
- dl = DataLoader(ds["test"], batch_size=8)
 
 
 
 
211
  ```
212
 
 
 
213
  ## 📜 Citation
214
 
215
  ```
 
185
  Following a usage example:
186
 
187
  ```python
188
+ import torchvision.transforms.functional as TF
189
  from datasets import load_dataset
190
  from torch.utils.data import DataLoader
191
 
192
+ # image processing function
193
+ def process_img(x):
194
+ x = TF.resize(x, (1024, 1024))
195
+ x = TF.to_tensor(x)
196
+ return x
197
+
198
+ # item processing function
199
+ def process_batch(examples):
200
+ examples["basecolor"] = [process_img(x) for x in examples["basecolor"]]
201
+ return examples
202
+
203
  # load the dataset in streaming mode
204
  ds = load_dataset(
205
  "gvecchio/MatSynth",
206
  streaming = True,
207
  )
208
 
209
+ # remove unwanted columns
210
  ds = ds.remove_columns(["diffuse", "specular", "displacement", "opacity", "blend_mask"])
211
+ # or keep only specified columns
212
+ ds = ds.select_columns(["metadata", "basecolor"])
213
+
214
+ # shuffle data
215
+ ds = ds.shuffle(buffer_size=100)
216
 
217
  # filter data matching a specific criteria, e.g.: only CC0 materials
218
  ds = ds.filter(lambda x: x["metadata"]["license"] == "CC0")
219
+ # filter out data from Deschaintre et al. 2018
220
+ ds = ds.filter(lambda x: x["metadata"]["source"] != "deschaintre_2020")
221
 
222
+ # Set up processing
223
+ ds = ds.map(process_batch, batched=True, batch_size=8)
224
 
225
  # set format for usage in torch
226
  ds = ds.with_format("torch")
227
+
228
+ # iterate over the dataset
229
+ for x in ds:
230
+ print(x)
231
+
232
  ```
233
 
234
+ ⚠️ **Note**: Streaming can be slow. We strongly suggest to cache data locally.
235
+
236
  ## 📜 Citation
237
 
238
  ```