|
| 1 | +The scripts contained in this folder, such as `infimnist_py`, have been crafted |
| 2 | +to stably work with python3 and above. |
| 3 | + |
| 4 | +The Python binding for the infinite MNIST dataset generator of L. Bottou |
| 5 | +(see http://leon.bottou.org/projects/infimnist), is written in Cython. |
| 6 | + |
| 7 | +**DEV NOTE:** We will be adding a real-time tensorflow generator to work with Keras |
| 8 | +and Tensorflow 2 (TF2). |
| 9 | + |
| 10 | +# Installation and Integration into ngc-learn |
| 11 | + |
| 12 | +In order for ngc-learn to properly recognize the data generating process |
| 13 | +under `ngclearn.generator.experimental.infimnist.infimnist`, you MUST |
| 14 | +do the following: |
| 15 | + |
| 16 | +1) You need to copy (or symlink) the `data/` directory from the original infimnist |
| 17 | +project folder (available [here](http://leon.bottou.org/projects/infimnist)) |
| 18 | +into the root folder of this repo. |
| 19 | + |
| 20 | +The files you specifically need inside of `data/` (that you can extract from the |
| 21 | +source website's zip-file contents) are: |
| 22 | +``` |
| 23 | +fields_float_1522x28x28.bin |
| 24 | +t10k-labels-idx1-ubyte |
| 25 | +train-images-idx3-ubyte |
| 26 | +t10k-images-idx3-ubyte |
| 27 | +tangVec_float_60000x28x28.bin |
| 28 | +train-labels-idx1-ubyte |
| 29 | +``` |
| 30 | + |
| 31 | +2) Next, build the cython extension with: |
| 32 | + |
| 33 | +``` |
| 34 | +$ python setup.py build_ext -if |
| 35 | +``` |
| 36 | + |
| 37 | +3) Finally, go up/back to the main ngc-learn directory `/ngc-learn/` and re-run |
| 38 | +the primary library building script: |
| 39 | + |
| 40 | +``` |
| 41 | +$ python setup.py install |
| 42 | +``` |
| 43 | + |
| 44 | +and the InfiMNIST package should be successfully integrated into the ngc-learn |
| 45 | +primary library package. If you do not complete the above directions, ngc-learn |
| 46 | +will throw an error as it will not properly recognize the InfiMNIST sampler |
| 47 | +in the `generator.experimental` module sub-directory. |
| 48 | + |
| 49 | +# Example Usage |
| 50 | +The following code gives the first test example (0), the first training example |
| 51 | +(10000) and its first transformation (70000). The indexing logic follows that |
| 52 | +of the original infimnist binary described [here](http://leon.bottou.org/projects/infimnist). |
| 53 | +ngc-learn has built internally a wrapper "generator" to convert the original |
| 54 | +infinite mnist into an on-the-fly (mini-batch) sampler/stochastic data generating |
| 55 | +process. |
| 56 | + |
| 57 | +```python |
| 58 | +from ngclearn.generator.experimental.infimnist.infimnist import InfiMNIST |
| 59 | +import matplotlib.pyplot as plt |
| 60 | + |
| 61 | +n_iter = 10 # bound your computation by a maximum number of iterations to simulate |
| 62 | + |
| 63 | +sampler = InfiMNIST(batch_size=8) |
| 64 | + |
| 65 | +for t in range(n_iter): |
| 66 | + x, y = sampler.sample() |
| 67 | + |
| 68 | + # Update NGC agent given x, y |
| 69 | + # WRITEME: agent code goes here... |
| 70 | + |
| 71 | + # You can also plot images using matplotlib and save to disk if you like |
| 72 | + import matplotlib.pyplot as plt |
| 73 | + plt.imshow(x[0].reshape(28,28)) |
| 74 | + plt.title('label: {}'.format(y[0])) |
| 75 | + plt.savefig("sample{}.jpg".format(t)) |
| 76 | +``` |
| 77 | + |
| 78 | +**DEV NOTE:** Future versions of InfiMNIST will offer support for tf.records. |
0 commit comments