From 08bba843a6c21568ada3bbefb6893774baff85c5 Mon Sep 17 00:00:00 2001 From: Moe Date: Sun, 3 May 2020 22:21:24 -0700 Subject: [PATCH] clean up tensorflow install process --- plugins/tensorflow/.gitignore | 3 +- plugins/tensorflow/INSTALL.sh | 13 ++--- plugins/tensorflow/ObjectDetectors.js | 5 +- plugins/tensorflow/package.json | 40 ++++++++++++++ plugins/tensorflow/shinobi-tensorflow.js | 68 ------------------------ 5 files changed, 49 insertions(+), 80 deletions(-) create mode 100644 plugins/tensorflow/package.json diff --git a/plugins/tensorflow/.gitignore b/plugins/tensorflow/.gitignore index 58816542..2726a9cc 100644 --- a/plugins/tensorflow/.gitignore +++ b/plugins/tensorflow/.gitignore @@ -1,2 +1,3 @@ conf.json -cascades \ No newline at end of file +dist +models diff --git a/plugins/tensorflow/INSTALL.sh b/plugins/tensorflow/INSTALL.sh index 5f17bcfd..42fe61e0 100644 --- a/plugins/tensorflow/INSTALL.sh +++ b/plugins/tensorflow/INSTALL.sh @@ -5,22 +5,17 @@ echo "You can run this installer again to change it." echo "(y)es or (N)o" read nodejsinstall echo "Getting Tensorflow Node.js module..." -npm install dotenv@8.2.0 --unsafe-perm npm uninstall @tensorflow/tfjs-node-gpu --unsafe-perm npm uninstall @tensorflow/tfjs-node --unsafe-perm -npm install @tensorflow/tfjs-core@1.7.3 --unsafe-perm --force -npm install @tensorflow/tfjs-converter@1.7.3 --unsafe-perm --force -npm install @tensorflow/tfjs-layers@1.7.3 --unsafe-perm --force npm install yarn -g --unsafe-perm --force -npm install @tensorflow/tfjs-node@1.7.3 --unsafe-perm GPU_INSTALL="0" if [ "$nodejsinstall" = "y" ] || [ "$nodejsinstall" = "Y" ]; then GPU_INSTALL="1" - npm install @tensorflow/tfjs-node-gpu@1.7.0 --unsafe-perm + npm install @tensorflow/tfjs-node-gpu@1.7.3 --unsafe-perm +else + npm install @tensorflow/tfjs-node@1.7.3 --unsafe-perm fi -echo "Getting Coco SSD Model..." -npm install @tensorflow-models/coco-ssd --unsafe-perm - +npm install --unsafe-perm if [ ! -e "./conf.json" ]; then echo "Creating conf.json" sudo cp conf.sample.json conf.json diff --git a/plugins/tensorflow/ObjectDetectors.js b/plugins/tensorflow/ObjectDetectors.js index ddd0f05e..36137971 100644 --- a/plugins/tensorflow/ObjectDetectors.js +++ b/plugins/tensorflow/ObjectDetectors.js @@ -3,20 +3,21 @@ module.exports = function(config){ switch(config.tfjsBuild){ case'gpu': tfjsSuffix = '-gpu' + var tf = require('@tensorflow/tfjs-node-gpu') break; case'cpu': + var tf = require('@tensorflow/tfjs-node') break; default: try{ - require(`@tensorflow/tfjs-node-gpu`) tfjsSuffix = '-gpu' + var tf = require('@tensorflow/tfjs-node-gpu') }catch(err){ console.log(err) } break; } - var tf = require(`@tensorflow/tfjs-node${tfjsSuffix}`) const cocossd = require('@tensorflow-models/coco-ssd'); // const mobilenet = require('@tensorflow-models/mobilenet'); diff --git a/plugins/tensorflow/package.json b/plugins/tensorflow/package.json new file mode 100644 index 00000000..3260a7eb --- /dev/null +++ b/plugins/tensorflow/package.json @@ -0,0 +1,40 @@ +{ + "name": "shinobi-tensorflow", + "author": "Shinob Systems, Moinul Alam", + "version": "1.0.0", + "description": "Object Detection plugin based on @tensorflow/tfjs-node", + "main": "shinobi-tensorflow.js", + "dependencies": { + "@tensorflow-models/coco-ssd": "^2.0.3", + "@tensorflow/tfjs-converter": "^1.7.3", + "@tensorflow/tfjs-core": "^1.7.3", + "@tensorflow/tfjs-layers": "^1.7.3", + "@tensorflow/tfjs-node": "^1.7.3", + "@tensorflow/tfjs-node-gpu": "^1.7.3", + "dotenv": "^8.2.0", + "express": "^4.16.2", + "moment": "^2.19.2", + "socket.io": "^2.0.4", + "socket.io-client": "^1.7.4" + }, + "devDependencies": {}, + "bin": "shinobi-tensorflow.js", + "scripts": { + "package": "pkg package.json -t linux,macos,win --out-path dist", + "package-x64": "pkg package.json -t linux-x64,macos-x64,win-x64 --out-path dist/x64", + "package-x86": "pkg package.json -t linux-x86,macos-x86,win-x86 --out-path dist/x86", + "package-armv6": "pkg package.json -t linux-armv6,macos-armv6,win-armv6 --out-path dist/armv6", + "package-armv7": "pkg package.json -t linux-armv7,macos-armv7,win-armv7 --out-path dist/armv7", + "package-all": "npm run package && npm run package-x64 && npm run package-x86 && npm run package-armv6 && npm run package-armv7" + }, + "pkg": { + "targets": [ + "node12" + ], + "scripts": [ + "../pluginBase.js" + ], + "assets": [ + ] + } +} diff --git a/plugins/tensorflow/shinobi-tensorflow.js b/plugins/tensorflow/shinobi-tensorflow.js index f40a39e0..c9e133ab 100644 --- a/plugins/tensorflow/shinobi-tensorflow.js +++ b/plugins/tensorflow/shinobi-tensorflow.js @@ -33,11 +33,6 @@ s.detectObject=function(buffer,d,tx,frameLocation){ if(results[0]){ var mats = [] results.forEach(function(v){ - // [xmin ymin xmax ymax] - // [x y width height] - // [xmin, ymin, xmax-xmin+1, ymax-ymin+1] - // var width = v.bbox[2] - v.bbox[0] - // var height = v.bbox[3] - v.bbox[1] mats.push({ x: v.bbox[0], y: v.bbox[1], @@ -66,67 +61,4 @@ s.detectObject=function(buffer,d,tx,frameLocation){ }) } }) - // var detectStuff = function(frame,callback){ - // detector.detect(frame) - // .then(detections => { - // matrices = [] - // detections.forEach(function(v){ - // matrices.push({ - // x:v.box.x, - // y:v.box.y, - // width:v.box.w, - // height:v.box.h, - // tag:v.className, - // confidence:v.probability, - // }) - // }) - // if(matrices.length > 0){ - // tx({ - // f:'trigger', - // id:d.id, - // ke:d.ke, - // details:{ - // plug:config.plug, - // name:'yolo', - // reason:'object', - // matrices:matrices, - // imgHeight:parseFloat(d.mon.detector_scale_y), - // imgWidth:parseFloat(d.mon.detector_scale_x) - // } - // }) - // } - // fs.unlink(frame,function(){ - // - // }) - // }) - // .catch(error => { - // console.log(error) - // - // // here you can handle the errors. Ex: Out of memory - // }) - // } - // if(frameLocation){ - // detectStuff(frameLocation) - // }else{ - // d.tmpFile=s.gid(5)+'.jpg' - // if(!fs.existsSync(s.dir.streams)){ - // fs.mkdirSync(s.dir.streams); - // } - // d.dir=s.dir.streams+d.ke+'/' - // if(!fs.existsSync(d.dir)){ - // fs.mkdirSync(d.dir); - // } - // d.dir=s.dir.streams+d.ke+'/'+d.id+'/' - // if(!fs.existsSync(d.dir)){ - // fs.mkdirSync(d.dir); - // } - // fs.writeFile(d.dir+d.tmpFile,buffer,function(err){ - // if(err) return s.systemLog(err); - // try{ - // detectStuff(d.dir+d.tmpFile) - // }catch(error){ - // console.error('Catch: ' + error); - // } - // }) - // } }