|
| 1 | +"use strict"; |
| 2 | + |
| 3 | +var caffe = require("../../bagua-caffe/build/Release/caffe.node"); |
| 4 | +var SSD = require("./ssd.js"); |
| 5 | + |
| 6 | +var LABELS = ["---", "aeroplane", "bicycle", "bird", "boat", "bottle", "bus", "car", "cat", "chair", "cow", |
| 7 | + "diningtable", "dog", "horse", "motorbike", "person", "pottedplant", "sheep", "sofa", "train", "tvmonitor"]; |
| 8 | + |
| 9 | +var image = caffe.io.loadImage("dog.jpg"); |
| 10 | + |
| 11 | +caffe.io.namedWindow("Image"); |
| 12 | + |
| 13 | +function show (blob) { |
| 14 | + let detections = SSD.parse(blob, image); |
| 15 | + |
| 16 | + detections.forEach(o => { |
| 17 | + if (o.score > 0.3) { |
| 18 | + console.log(LABELS[o.label], o.score.toFixed(3), "@", o.xmin, o.ymin, o.xmax, o.ymax); |
| 19 | + image.rectangle(o.xmin, o.ymin, o.xmax, o.ymax); |
| 20 | + } |
| 21 | + }); |
| 22 | + caffe.io.show("Image", image); |
| 23 | + caffe.io.waitKey(); |
| 24 | +} |
| 25 | + |
| 26 | + |
| 27 | +var net = new caffe.Net('../../model-zoo/caffe/VOC0712/SSD_300x300/deploy.prototxt', '../../model-zoo/caffe/VOC0712/SSD_300x300/VGG_VOC0712_SSD_300x300_iter_120000.caffemodel'); |
| 28 | + |
| 29 | +var transformer = new caffe.io.Transformer(net.blobs["data"].shape); |
| 30 | +transformer.setMeanValue([104, 117, 123]); |
| 31 | + |
| 32 | +net.blobs["data"].data = transformer.preprocess(image); |
| 33 | + |
| 34 | +// Sync call |
| 35 | +//show (net.forward()[0]); |
| 36 | + |
| 37 | + |
| 38 | +// Async call |
| 39 | +net.forward(output_blobs => { |
| 40 | + show (output_blobs[0]); |
| 41 | +}); |
| 42 | + |
0 commit comments