hayden-donnelly commited on
Commit
a81bb0b
1 Parent(s): 7600190

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +63 -0
README.md ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ task_categories:
3
+ - image-classification
4
+ - unconditional-image-generation
5
+ size_categories:
6
+ - 10K<n<100K
7
+ ---
8
+ # MNIST WebDataset PNG
9
+ The MNIST dataset with samples stored as PNG images and compiled into the WebDataset format.
10
+
11
+ ## DALI/JAX Example
12
+ The following code shows how this dataset can be loaded into JAX arrays by DALI.
13
+ ```python
14
+ from nvidia.dali import pipeline_def
15
+ import nvidia.dali.fn as fn
16
+ import nvidia.dali.types as types
17
+ from nvidia.dali.plugin.jax import DALIGenericIterator
18
+ from nvidia.dali.plugin.base_iterator import LastBatchPolicy
19
+
20
+ def get_data_iterator(batch_size, dataset_path):
21
+ @pipeline_def(batch_size=batch_size, num_threads=4, device_id=0)
22
+ def wds_pipeline():
23
+ raw_image, ascii_label = fn.readers.webdataset(
24
+ paths=dataset_path,
25
+ ext=['png', 'cls'],
26
+ missing_component_behavior='error',
27
+ )
28
+ image = fn.decoders.image(raw_image)
29
+ ascii_shift = types.Constant(48).uint8()
30
+ label = ascii_label - ascii_shift
31
+ return image, label
32
+
33
+ data_pipeline = wds_pipeline()
34
+ data_iterator = DALIGenericIterator(
35
+ pipelines=[data_pipeline],
36
+ output_map=['x', 'y'],
37
+ last_batch_policy=LastBatchPolicy.DROP
38
+ )
39
+ return data_iterator
40
+
41
+ data_iterator = get_data_iterator(
42
+ batch_size=32,
43
+ dataset_path='data/mnist_webdataset_numpy_flat_9/data.tar'
44
+ )
45
+ batch = next(data_iterator)
46
+ x = batch['x']
47
+ y = batch['y']
48
+ print('x shape:', x.shape)
49
+ print('y shape:', y.shape)
50
+ print('y:', y[:, 0])
51
+ ```
52
+
53
+ Output:
54
+ ```
55
+ x shape: (32, 28, 28, 3)
56
+ y shape: (32, 1)
57
+ y: [5 0 4 1 9 2 1 3 1 4 3 5 3 6 1 7 2 8 6 9 4 0 9 1 1 2 4 3 2 7 3 8]
58
+ ```
59
+
60
+ ## Acknowledgements
61
+ - Yann LeCun, Courant Institute, NYU
62
+ - Corinna Cortes, Google Labs, New York
63
+ - Christopher J.C. Burges, Microsoft Research, Redmond