【问题标题】:Loading an image from Dropzone.js into Tensorflow.js将图像从 Dropzone.js 加载到 Tensorflow.js
【发布时间】:2020-03-23 13:12:44
【问题描述】:

目前,我们遇到了一个问题,即我们需要允许用户将图像拖放到初始登录页面中,然后当他们按下 Identify! 按钮时,它会获取当前位于已拖放图像位置的图像并然后把它扔到模型中进行预测。

目前的问题是想办法把刚刚扔到Dropzone中的图片放到我们的模型中进行处理,然后放到我们的模型中进行预测。

let identify = document.querySelector('.identify')
if (identify) {
    identify.addEventListener('click', event => {
        event.preventDefault()
        let user_pic = document.querySelector('.dz-image').children[0].src
        ...
        const prediction = model.predict(user_pic)
        console.log('This is your prediction: ', prediction)
    })
}

正在发生的事情是控制台说: Uncaught TypeError: model.predict is not a function at HTMLDivElement.<anonymous>

这没有意义,因为我们的模板中有 CDN Tensorflow 标签,所以它应该可以正常工作。

【问题讨论】:

  • 你分配给模型什么?
  • 初始变量为const model = tf.loadLayersModel('model_json')
  • 你需要使用“等待”

标签: dropzone.js tensorflow.js


【解决方案1】:

你需要使用await,因为加载模型是一个异步操作

const model = await tf.loadLayersModel('model_json')

【讨论】:

    猜你喜欢
    • 2014-05-05
    • 2017-03-12
    • 1970-01-01
    • 2013-07-29
    • 1970-01-01
    • 2017-07-13
    • 2011-05-03
    • 1970-01-01
    相关资源
    最近更新 更多