【问题标题】:Tensorflow js server side classification with mobilenet and blazeface带有mobilenet和blazeface的Tensorflow js服务器端分类
【发布时间】:2021-02-13 20:25:43
【问题描述】:

我正在尝试将 tensorflowjs 与已构建的模型一起使用,一开始我遇到了 blazeface 的问题,因为它在照片上找不到人脸(仅显示人脸),所以我正在尝试使用 mobilenet 和相同问题的结果是无意义的。太漂亮了,它来自我发送的图像格式。

这是我的代码:

module.exports = {
    blazeface: require('@tensorflow-models/blazeface'),
    mobilenet: require('@tensorflow-models/mobilenet'),
    tf: require("@tensorflow/tfjs-node"),
    fs: require("fs"),
    sizeOf: require("image-size"),

    async structureData(imageLink) {
        let data = this.fs.readFileSync(imageLink);//return a buffer
        const dimension = await this.sizeOf(imageLink);
        const tensorflowImage = {
            data: data,
            width: dimension.width,
            height: dimension.height
        };
        console.log(tensorflowImage)
        return tensorflowImage;
    },

    async detectFace(imageLink) {
        let image = await this.structureData(imageLink);
        const model = await this./*blazeface*/mobilenet.load();
        const returnTensors = false;
        const predictions = await model.classify(image);
        console.log(predictions);
    }
}

所以这段代码不是错误的结果,但结果是这个=>

[
  {
    className: 'theater curtain, theatre curtain',
    probability: 0.03815646469593048
  },
  {
    className: 'web site, website, internet site, site',
    probability: 0.0255243219435215
  },
  { className: 'matchstick', probability: 0.02520526386797428 }
]

以及任何照片(这里是白色背景中的香蕉)。 所以我很确定我需要重建 structureData 函数,但我不知道如何...... 我也用 uint32array 试过这个

    async structureData(imageLink) {
        let data = this.fs.readFileSync(imageLink);
        data = new Uint32Array(data);
        const dimension = await this.sizeOf(imageLink);
        const tensorflowImage = {
            data: data,
            width: dimension.width,
            height: dimension.height
        };
        console.log(tensorflowImage)
        return tensorflowImage;
    },

但是我收到了这个错误。

Error: pixels passed to tf.browser.fromPixels() must be either an HTMLVideoElement, HTMLImageElement, HTMLCanvasElement, ImageData in browser, or OffscreenCanvas, ImageData in webworker or {data: Uint32Array, width: number, height: number}, but was Object

记住我正在使用节点,所以我不能(或认为我不能)我们 HTMLimageelement

非常感谢:)

【问题讨论】:

    标签: node.js tensorflow artificial-intelligence tensorflow.js


    【解决方案1】:

    通过使用张量、视频或图像元素作为模型的参数,它将能够进行分类。

    let data = this.fs.readFileSync(imageLink);
    tensor = tf.node.decodeImage(data, 3)
    
    await model.classify(tensor)
    

    【讨论】:

    • 非常感谢!!你能解释一下 3 吗?
    • 3 表示通道数
    猜你喜欢
    • 1970-01-01
    • 2021-04-12
    • 2013-11-23
    • 2017-01-12
    • 2017-03-14
    • 1970-01-01
    • 2013-06-28
    • 2018-11-10
    • 1970-01-01
    相关资源
    最近更新 更多