Add Tensorflow based local detection #95
671
package-lock.json
generated
671
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -23,6 +23,7 @@
|
||||
"last 5 Firefox versions"
|
||||
],
|
||||
"dependencies": {
|
||||
"@tensorflow/tfjs": "^4.17.0",
|
||||
"dom7": "^4.0.6",
|
||||
"framework7": "^8.3.0",
|
||||
"framework7-icons": "^5.0.5",
|
||||
|
||||
BIN
src/models/thorax_tfwm/group1-shard1of7.bin
Normal file
BIN
src/models/thorax_tfwm/group1-shard1of7.bin
Normal file
Binary file not shown.
BIN
src/models/thorax_tfwm/group1-shard2of7.bin
Normal file
BIN
src/models/thorax_tfwm/group1-shard2of7.bin
Normal file
Binary file not shown.
BIN
src/models/thorax_tfwm/group1-shard3of7.bin
Normal file
BIN
src/models/thorax_tfwm/group1-shard3of7.bin
Normal file
Binary file not shown.
BIN
src/models/thorax_tfwm/group1-shard4of7.bin
Normal file
BIN
src/models/thorax_tfwm/group1-shard4of7.bin
Normal file
Binary file not shown.
BIN
src/models/thorax_tfwm/group1-shard5of7.bin
Normal file
BIN
src/models/thorax_tfwm/group1-shard5of7.bin
Normal file
Binary file not shown.
BIN
src/models/thorax_tfwm/group1-shard6of7.bin
Normal file
BIN
src/models/thorax_tfwm/group1-shard6of7.bin
Normal file
Binary file not shown.
BIN
src/models/thorax_tfwm/group1-shard7of7.bin
Normal file
BIN
src/models/thorax_tfwm/group1-shard7of7.bin
Normal file
Binary file not shown.
1
src/models/thorax_tfwm/model.json
Normal file
1
src/models/thorax_tfwm/model.json
Normal file
File diff suppressed because one or more lines are too long
@@ -286,9 +286,10 @@
|
||||
import SvgIcon from '../components/svg-icon.vue'
|
||||
|
||||
import submitMixin from './submit-mixin'
|
||||
import detectMixin from './local-detect'
|
||||
|
||||
export default {
|
||||
mixins: [submitMixin],
|
||||
mixins: [submitMixin, detectMixin],
|
||||
props: {
|
||||
f7route: Object,
|
||||
},
|
||||
@@ -433,6 +434,7 @@
|
||||
} else {
|
||||
//TODO
|
||||
f7.dialog.alert('Using built-in model')
|
||||
this.localDetect(this.activeRegion,this.imageView)
|
||||
}
|
||||
},
|
||||
remoteTimeout () {
|
||||
|
||||
@@ -1,21 +1,48 @@
|
||||
import * as tf from '@tensorflow/tfjs'
|
||||
|
||||
export default {
|
||||
methods: {
|
||||
localDetect(region, imageData) {
|
||||
async localDetect(region, imageData) {
|
||||
switch (region) {
|
||||
case 0:
|
||||
var modelFile = 'some/path/to/thorax'
|
||||
var weights = '../models/thorax_tfwm/model.json'
|
||||
break;
|
||||
case 1:
|
||||
var modelFile = 'some/path/to/abdomen'
|
||||
var weights = '../models/abdomen_tfwm/model.json'
|
||||
break;
|
||||
case 2:
|
||||
var modelFile = 'some/path/to/limbs'
|
||||
var weights = '../models/limbs_tfwm/model.json'
|
||||
break;
|
||||
case 3:
|
||||
var modelFile = 'some/path/to/head'
|
||||
var weights = '../models/head_tfwm/model.json'
|
||||
break;
|
||||
}
|
||||
return finalDetections
|
||||
|
||||
const model = await tf.loadGraphModel(weights).then(model => {
|
||||
return model
|
||||
})
|
||||
let [modelWidth, modelHeight] = model.inputs[0].shape.slice(1, 3);
|
||||
const input = tf.tidy(() => {
|
||||
return tf.image.resizeBilinear(tf.browser.fromPixels(imageData), [modelWidth, modelHeight]).div(255.0).expandDims(0)
|
||||
})
|
||||
var results = await model.executeAsync(input).then(res => {
|
||||
const [boxes, scores, classes, valid_detections] = res;
|
||||
const boxes_data = boxes.dataSync();
|
||||
const scores_data = scores.dataSync();
|
||||
const classes_data = classes.dataSync();
|
||||
const valid_detections_data = valid_detections.dataSync()[0];
|
||||
|
||||
tf.dispose(res)
|
||||
|
||||
console.log(boxes_data)
|
||||
console.log(scores_data)
|
||||
console.log(classes_data)
|
||||
console.log(valid_detections_data)
|
||||
|
||||
return boxes_data
|
||||
})
|
||||
|
||||
return results
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user