Vue js application with TFJS

139 views
Skip to first unread message

Andrew Sigurdson

unread,
Jul 27, 2018, 5:05:12 PM7/27/18
to TensorFlow.js Discussion
Hello,

I am started to make a front end application with vue js but have hit a roadblock. I didnt' change any of the tensor flow java script functions that worked before but now I'm getting a weird error. It must be something with Vue js so not sure if you guys have seen this error.  Also included the tfjs functions here.  It doesn't like the input to predict() i guess. But these worked fine before using vue js which is weird.
tf.loadModel(pathToModels + 'tfjs_model/model.json').then(modelLoad => {
model = modelLoad
try {
model.predict(tf.zeros([1, 224, 224, 3]))
} catch (loadModelError) {
console.log(loadModelError)
}
modelLoaded = true
}) 
 function runMod(imageData) {
var t0 = performance.now()
var image = tf.fromPixels(imageData)
var reshaped = image.expandDims(0).toFloat()
try {
var output
output = model.predict(reshaped.div(tf.scalar(127)).sub(tf.scalar(1)))
var t2 = performance.now()
var index = getMaxIndex(output.dataSync())
document.getElementById('prediction').innerHTML = '<br>' + labels[index]
document.getElementById('confidence').innerHTML =
'<br>Co: ' + output.dataSync()[index]
document.getElementById('timeToRun').innerHTML =
'<br>running model: ' + (t2 - t0) + ' ms'
} catch (runModelError) {
console.log(runModelError)
}
}
Error: Argument 'b' passed to 'div' must be a Tensor or TensorLike, but got e
    at convertToTensor (tf...@0.12.0:2)
    at e.div (tf...@0.12.0:2)
    at tf...@0.12.0:2
    at e.tidy (tf...@0.12.0:2)
    at Function.e.tidy (tf...@0.12.0:2)
    at Object.r.value [as div] (tf...@0.12.0:2)
    at e.div (tf...@0.12.0:2)
    at runMod (home.vue?3be5:117)
    at eval (home.vue?3be5:108)
    at e.tidy (tf...@0.12.0:2)

If anyone has any ideas let me know!

Nikhil Thorat

unread,
Jul 27, 2018, 5:12:57 PM7/27/18
to Andrew Sigurdson, TensorFlow.js Discussion
Can you update your tfjs version to 0.12.8? That should fix it.

The underlying issue is you have multiple copies of tfjs being included on the oage(which we recently allowed), you may want to investigate that (if just for bundle size).

--
You received this message because you are subscribed to the Google Groups "TensorFlow.js Discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tfjs+uns...@tensorflow.org.
Visit this group at https://groups.google.com/a/tensorflow.org/group/tfjs/.
To view this discussion on the web visit https://groups.google.com/a/tensorflow.org/d/msgid/tfjs/42665b00-5569-4988-a268-269d3bb78729%40tensorflow.org.

Andrew Sigurdson

unread,
Jul 27, 2018, 5:26:59 PM7/27/18
to TensorFlow.js Discussion, as...@umich.edu
Thank you!  
Reply all
Reply to author
Forward
0 new messages