Last active
December 14, 2018 07:43
-
-
Save crockpotveggies/9519c6f34ae312dd32d413272e2cebb2 to your computer and use it in GitHub Desktop.
NodeJS script to sort CIFAR-10 dataset of PNGs into label directories
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
var fs = require('fs') | |
var labels = fs.readFileSync('labels.txt', 'utf-8') | |
.split('\n') | |
.filter(Boolean); | |
/*for(i = 0; i < labels.length; i++) { | |
fs.mkdirSync("./train/"+i); | |
fs.mkdirSync("./test/"+i); | |
}*/ | |
var set = './train/' | |
fs.readdirSync(set).forEach(file => { | |
console.log(file); | |
if(file.indexOf('.png') > -1) { | |
var label = file.match(/([a-zA-Z0-9_-])\_(.*)\.png/).pop() | |
var id = labels.indexOf(label) | |
console.log('Label is: '+id) | |
fs.rename(set+file, set+id+'/'+file) | |
console.log('Moved to: '+set+id+'/'+file) | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment