Last active
November 15, 2020 14:39
-
-
Save aniketbiprojit/5f5dbaff0c18eab948a2b745f3eab32b to your computer and use it in GitHub Desktop.
Load MNIST data and convert to tfjs tensors
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const load_data = require('./data_loader') | |
| const data = load_data() | |
| const X = data.map((elem) => { | |
| const key = Object.keys(elem)[0] | |
| return elem[key].map((val) => val / 255) | |
| }) | |
| console.log(X[0]) | |
| const arr = Array.apply(null, Array(10)).map(() => 0) | |
| const y = data.map((elem) => { | |
| const key = parseInt(Object.keys(elem)[0]) | |
| const copy_arr = Object.assign([], arr) | |
| for (let index = 0; index < copy_arr.length; index++) { | |
| if (index === key) { | |
| copy_arr[index] = 1 | |
| } | |
| } | |
| return copy_arr | |
| }) | |
| console.log(y[0],y[1]) | |
| console.log('X:', X.length) | |
| console.log('y:', y.length) | |
| let X_tensor = tf.tensor2d(X, [5000, 784]) | |
| let y_tensor = tf.tensor2d(y, [5000, 10]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment