gpt4 book ai didi

angular - TensorflowJS : Error: The shape of dict ['images' ] provided in model. execute(dict) 必须是 [-1,224,224,3],但是是 [400,600,1]

转载 作者:行者123 更新时间:2023-12-03 23:53:54 31 4
gpt4 key购买 nike

我正在使用来自谷歌的 mobilenet 神经网络对图像进行分类。我正在使用 angular 6 + TensorFlow.js 来构建我的图像分类器应用程序。
我正在尝试按照 tfjs-converter library readme 提供的步骤进行操作,我想出了以下代码:

import * as tf from '@tensorflow/tfjs';
import { FrozenModel } from '@tensorflow/tfjs';

export class NeuralNetwork {
private MODEL_PATH: string = 'http://localhost:4200/assets/model/tensorflowjs_model.pb';
private WEIGHTS_PATH: string = 'http://localhost:4200/assets/model/weights_manifest.json';
constructor(){}
async loadModel() {
const localModel: FrozenModel = (await tf.loadFrozenModel(this.MODEL_PATH, this.WEIGHTS_PATH));
let image: any = document.getElementById('cat');

let pixels = tf.fromPixels(image, 1);
let result = localModel.predict(pixels);

}
async predict(){
let image: any = document.getElementById('cat');
debugger;
this.model.execute({input: tf.fromPixels(image)});
}

}
图像 HTML 元素:
<img id="cat" src="http://localhost:4200/assets/images/cat.jpg"/>
当我尝试执行 localModel.predict(pixels) 函数时,出现以下错误:

Uncaught (in promise): Error: The shape of dict['images'] provided in model.execute(dict) must be [-1,224,224,3], but was [400,600,1]


我是 Tensorflow 和 TensorFlow.js 技术的新手。有谁知道我做错了什么?

最佳答案

遇到同样的问题,然后在Github中找到了解决方法:Input appears to be wrong shape

const img = document.getElementById('myimg');
const tfImg = tf.fromPixels(img);
const smalImg = tf.image.resizeBilinear(tfImg, [368, 432]);
const resized = tf.cast(smalImg, 'float32');
const t4d = tf.tensor4d(Array.from(resized.dataSync()),[1,368,432,3])

关于angular - TensorflowJS : Error: The shape of dict ['images' ] provided in model. execute(dict) 必须是 [-1,224,224,3],但是是 [400,600,1],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52825696/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com