Skip to content

Instantly share code, notes, and snippets.

@crockpotveggies
Last active December 14, 2018 07:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save crockpotveggies/9519c6f34ae312dd32d413272e2cebb2 to your computer and use it in GitHub Desktop.
Save crockpotveggies/9519c6f34ae312dd32d413272e2cebb2 to your computer and use it in GitHub Desktop.
NodeJS script to sort CIFAR-10 dataset of PNGs into label directories
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