Set worker use as configuration setting
Signed-off-by: Justin Georgi <justin.georgi@gmail.com>
This commit is contained in:
@@ -209,8 +209,6 @@
|
||||
let miniJ = `../models/${this.detectorName}-mini/model.json`
|
||||
this.modelLocation = new URL(modelJ,import.meta.url).href
|
||||
this.miniLocation = new URL(miniJ,import.meta.url).href
|
||||
console.log(this.modelLocation)
|
||||
console.log(this.miniLocation)
|
||||
let classesJ = `../models/${this.detectorName}/classes.json`
|
||||
fetch(new URL(classesJ,import.meta.url).href)
|
||||
.then((mod) => { return mod.json() })
|
||||
@@ -222,30 +220,12 @@
|
||||
if (loadServerSettings) this.serverSettings = JSON.parse(loadServerSettings)
|
||||
},
|
||||
mounted () {
|
||||
this.detectWorker = new detectionWorker()
|
||||
this.detectWorker.onmessage = (eMount) => {
|
||||
self = this
|
||||
if (eMount.data.error) {
|
||||
console.log(eMount.data.message)
|
||||
f7.dialog.alert(`ALVINN AI model error: ${eMount.data.message}`)
|
||||
}
|
||||
self.modelLoading = false
|
||||
}
|
||||
this.vidWorker = new detectionWorker()
|
||||
this.vidWorker.onmessage = (eMount) => {
|
||||
self = this
|
||||
if (eMount.data.error) {
|
||||
console.log(eMount.data.message)
|
||||
f7.dialog.alert(`ALVINN AI nano model error: ${eMount.data.message}`)
|
||||
}
|
||||
}
|
||||
|
||||
if (this.serverSettings && this.serverSettings.use) {
|
||||
this.getRemoteLabels()
|
||||
this.modelLoading = false
|
||||
} else {
|
||||
this.modelLoading = true
|
||||
if (this.isSafari) {
|
||||
if (!this.useWorkers) {
|
||||
this.loadModel(this.modelLocation, true).then(() => {
|
||||
this.modelLoading = false
|
||||
}).catch((e) => {
|
||||
@@ -254,6 +234,23 @@
|
||||
this.modelLoading = false
|
||||
})
|
||||
} else {
|
||||
this.detectWorker = new detectionWorker()
|
||||
this.detectWorker.onmessage = (eMount) => {
|
||||
self = this
|
||||
if (eMount.data.error) {
|
||||
console.log(eMount.data.message)
|
||||
f7.dialog.alert(`ALVINN AI model error: ${eMount.data.message}`)
|
||||
}
|
||||
self.modelLoading = false
|
||||
}
|
||||
this.vidWorker = new detectionWorker()
|
||||
this.vidWorker.onmessage = (eMount) => {
|
||||
self = this
|
||||
if (eMount.data.error) {
|
||||
console.log(eMount.data.message)
|
||||
f7.dialog.alert(`ALVINN AI nano model error: ${eMount.data.message}`)
|
||||
}
|
||||
}
|
||||
this.detectWorker.postMessage({call: 'loadModel', weights: this.modelLocation, preload: true})
|
||||
this.vidWorker.postMessage({call: 'loadModel', weights: this.miniLocation, preload: true})
|
||||
}
|
||||
@@ -318,30 +315,32 @@
|
||||
return `--chip-media-gradient: conic-gradient(from ${270 - (confFactor * 360 / 2)}deg, hsl(${confFactor * 120}deg, 100%, 50%) ${confFactor}turn, hsl(${confFactor * 120}deg, 50%, 66%) ${confFactor}turn)`
|
||||
},
|
||||
async setData () {
|
||||
this.detectWorker.onmessage = (eDetect) => {
|
||||
self = this
|
||||
if (eDetect.data.error) {
|
||||
self.detecting = false
|
||||
self.resultData = {}
|
||||
loadFailure()
|
||||
f7.dialog.alert(`ALVINN structure finding error: ${eDetect.data.message}`)
|
||||
} else if (eDetect.data.success == 'detection') {
|
||||
self.detecting = false
|
||||
self.resultData = eDetect.data.detections
|
||||
if (self.resultData) {
|
||||
self.resultData.detections.map(d => {d.label = self.detectorLabels[d.label].name})
|
||||
if (this.detectWorker) {
|
||||
this.detectWorker.onmessage = (eDetect) => {
|
||||
self = this
|
||||
if (eDetect.data.error) {
|
||||
self.detecting = false
|
||||
self.resultData = {}
|
||||
loadFailure()
|
||||
f7.dialog.alert(`ALVINN structure finding error: ${eDetect.data.message}`)
|
||||
} else if (eDetect.data.success == 'detection') {
|
||||
self.detecting = false
|
||||
self.resultData = eDetect.data.detections
|
||||
if (self.resultData) {
|
||||
self.resultData.detections.map(d => {d.label = self.detectorLabels[d.label].name})
|
||||
}
|
||||
self.uploadDirty = true
|
||||
} else if (eDetect.data.success == 'model') {
|
||||
self.reloadModel = false
|
||||
loadSuccess()
|
||||
}
|
||||
self.uploadDirty = true
|
||||
} else if (eDetect.data.success == 'model') {
|
||||
self.reloadModel = false
|
||||
loadSuccess()
|
||||
}
|
||||
}
|
||||
|
||||
let loadSuccess = null
|
||||
let loadFailure = null
|
||||
let modelReloading = null
|
||||
if (this.isSafari && this.reloadModel) {
|
||||
if (!this.useWorkers && this.reloadModel) {
|
||||
await this.loadModel(this.modelLocation)
|
||||
this.reloadModel = false
|
||||
} else {
|
||||
@@ -358,7 +357,7 @@
|
||||
|
||||
if (this.serverSettings && this.serverSettings.use) {
|
||||
this.remoteDetect()
|
||||
} else if (!this.isSafari) {
|
||||
} else if (this.useWorkers) {
|
||||
Promise.all([modelReloading,createImageBitmap(this.imageView)]).then(res => {
|
||||
this.detectWorker.postMessage({call: 'localDetect', image: res[1]}, [res[1]])
|
||||
})
|
||||
@@ -400,7 +399,7 @@
|
||||
var vidElement = this.$refs.vid_viewer
|
||||
vidElement.width = trackDetails.width
|
||||
vidElement.height = trackDetails.height
|
||||
if (this.isSafari) {
|
||||
if (!this.useWorkers) {
|
||||
this.videoFrameDetect(vidElement)
|
||||
} else {
|
||||
this.videoFrameDetectWorker(vidElement)
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
<f7-block-title medium>Details</f7-block-title>
|
||||
<f7-list>
|
||||
<f7-list-item title="Version" :after="alvinnVersion"></f7-list-item>
|
||||
<f7-list-item v-if="isSafari" title="Safari" after="Workers disabled"></f7-list-item>
|
||||
<f7-list-item title="Workers" :after="useWorkers ? 'Enabled' : 'Disabled'"></f7-list-item>
|
||||
</f7-list>
|
||||
<f7-block-title medium>Models</f7-block-title>
|
||||
<f7-list style="width: 100%;">
|
||||
@@ -54,6 +54,7 @@
|
||||
alvinnVersion: store().getVersion,
|
||||
isCordova: !!window.cordova,
|
||||
isSafari: store().isSafari,
|
||||
useWorkers: store().useWorkers,
|
||||
otherSettings: {}
|
||||
}
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user