-
Notifications
You must be signed in to change notification settings - Fork 7
/
postinstall.js
57 lines (54 loc) · 3.34 KB
/
postinstall.js
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
var path = require('path');
var fs = require('fs');
var child_process = require('child_process');
var rp = require('request-promise');
var models = [{
name: 'mobilenet',
urls: ['https://storage.googleapis.com/tfhub-tfjs-modules/google/imagenet/mobilenet_v1_100_224/classification/1/model.json',
'https://storage.googleapis.com/tfhub-tfjs-modules/google/imagenet/mobilenet_v1_100_224/classification/1/group1-shard1of5',
'https://storage.googleapis.com/tfhub-tfjs-modules/google/imagenet/mobilenet_v1_100_224/classification/1/group1-shard2of5',
'https://storage.googleapis.com/tfhub-tfjs-modules/google/imagenet/mobilenet_v1_100_224/classification/1/group1-shard3of5',
'https://storage.googleapis.com/tfhub-tfjs-modules/google/imagenet/mobilenet_v1_100_224/classification/1/group1-shard4of5',
'https://storage.googleapis.com/tfhub-tfjs-modules/google/imagenet/mobilenet_v1_100_224/classification/1/group1-shard5of5']
}, {
name: 'coco-ssd',
urls: ['https://storage.googleapis.com/tfjs-models/savedmodel/ssdlite_mobilenet_v2/model.json',
'https://storage.googleapis.com/tfjs-models/savedmodel/ssdlite_mobilenet_v2/group1-shard1of5',
'https://storage.googleapis.com/tfjs-models/savedmodel/ssdlite_mobilenet_v2/group1-shard2of5',
'https://storage.googleapis.com/tfjs-models/savedmodel/ssdlite_mobilenet_v2/group1-shard3of5',
'https://storage.googleapis.com/tfjs-models/savedmodel/ssdlite_mobilenet_v2/group1-shard4of5',
'https://storage.googleapis.com/tfjs-models/savedmodel/ssdlite_mobilenet_v2/group1-shard5of5']
}, {
name: 'posenet',
urls: ['https://storage.googleapis.com/tfjs-models/savedmodel/posenet/mobilenet/float/075/model-stride16.json',
'https://storage.googleapis.com/tfjs-models/savedmodel/posenet/mobilenet/float/075/group1-shard1of2.bin',
'https://storage.googleapis.com/tfjs-models/savedmodel/posenet/mobilenet/float/075/group1-shard2of2.bin']
}];
(async () => {
try { fs.mkdirSync(__dirname + '/models'); } catch (e) {}
for (var i = 0; i < models.length; i++) {
var model = models[i];
try { fs.mkdirSync(__dirname + '/models/' + model.name); } catch (e) {}
for (var j = 0; j < model.urls.length; j++) {
var flag = true;
for (var k = 0; flag && k < 8; k++) {
try {
console.log('Downloading: ' + model.name + ', ' + model.urls[j]);
var response = await rp.get({ url: model.urls[j], encoding: null });
var file = model.urls[j].split('/').slice(-1)[0];
fs.writeFileSync(__dirname + '/models/' + model.name + '/' + file, Buffer.from(response));
console.log('Downloaded: ' + model.name + ', ' + model.urls[j]);
flag = false;
} catch (err) {
console.log(err);
}
}
}
}
})();
var modelfile = '/proc/device-tree/model';
if (fs.existsSync(modelfile) && fs.readFileSync(modelfile).toString().startsWith('Raspberry Pi')) {
var cmd = 'npm rebuild @tensorflow/tfjs-node --build-from-source';
var spawn = child_process.spawnSync(cmd, { cwd: path.resolve(__dirname, '..', '..'), shell: true });
console.log(spawn.stderr.toString() + '\n----\n' + spawn.stdout.toString());
}