-
Notifications
You must be signed in to change notification settings - Fork 32
/
list-image-pairs
executable file
·38 lines (30 loc) · 1.16 KB
/
list-image-pairs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/usr/bin/env node
var fs = require('fs')
var path = require('path')
var readSample = require('./lib/read-sample')
var through = require('through2')
var argv = require('minimist')(process.argv.slice(2))
if (!argv.labels) {
console.error('Usage: cat sample.txt | ./slice --labels path/to/labels [--images path/to/images] [--label-ratio RATIO]')
process.exit()
}
var basedir = path.resolve(argv.basedir)
var fullImagesPath = argv.images ? path.resolve(basedir, argv.images) : false
var fullLabelsPath = argv.labels ? path.resolve(basedir, argv.labels) : false
readSample(argv)
.pipe(through.obj(function (tile, _, next) {
var filename = tile.join('-')
if (fullImagesPath && !fs.existsSync(path.join(fullImagesPath, filename + '.jpg'))) {
console.error('Cannot find image ' + filename)
return next()
}
if (fullLabelsPath && !fs.existsSync(path.join(fullLabelsPath, filename + '.png'))) {
console.error('Cannot find label ' + filename)
return next()
}
var image = path.join('/data', argv.images, filename + '.jpg')
var label = path.join('/data', argv.labels, filename + '.png')
this.push(image + ' ' + label + '\n')
next()
}))
.pipe(process.stdout)