Last active
October 15, 2024 12:41
-
-
Save nonodev96/b8f25dfc12536d76c1d27bb0d23c9def to your computer and use it in GitHub Desktop.
Read npy and npz in browser with js
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
| import npyjs from 'npyjs' | |
| import JSZip from 'jszip' | |
| import JSZipUtils from 'jszip-utils' | |
| const handleClick_debug_npz = async () => { | |
| const file = process.env.REACT_APP_PATH + '/datasets/03-image-classification/kmnist/kmnist-train-imgs.npz' | |
| await JSZipUtils.getBinaryContent(file, async (err, data) => { | |
| if (err) { | |
| throw err // or handle the error | |
| } | |
| const jsZip = new JSZip() | |
| const npzFiles = await jsZip.loadAsync(data) | |
| for (const [npy_filename, npy_data] of Object.entries(npzFiles.files)) { | |
| if (!npy_filename.endsWith('.npy')) { | |
| console.error('error .npy') | |
| return | |
| } | |
| const npy_array_buffer = await npzFiles.files[npy_filename].async("arraybuffer") | |
| console.log({ npy_filename, npy_data, npy_array_buffer: npy_array_buffer }) | |
| const _npyjs_ = new npyjs() | |
| console.log(await _npyjs_.parse(npy_array_buffer)) | |
| } | |
| }) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment