Add Tensorflow based local detection #95

Merged
jgeorgi merged 3 commits from msv-local-detect into main 2024-02-15 02:42:35 +00:00
12 changed files with 679 additions and 46 deletions
Showing only changes of commit c58cc24087 - Show all commits

671
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -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",

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

File diff suppressed because one or more lines are too long

View File

@@ -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 () {

View File

@@ -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
}
}
}