0

有没有办法让输入图像值与预期值匹配?我知道的输入图像的宽度是 800 像素,高度是 500 像素,并且是彩色的(意思是 3 个通道),所以形状应该是 [800,500,3]。但是,我收到以下错误:

错误:Error: Based on the provided shape, [800,500,3], the tensor should have 1200000 values but has 400000

有没有办法给图像赋值 1200000,或者将形状调整为 400000 但仍保留 3 个通道的 800x500 尺寸?

编码:

var tf = require('@tensorflow/tfjs-node');
const fs = require(`fs`)
const Jimp = require(`jimp`)

const image = `./1-1.png`

const imageWidth = 800;
const imageHeight = 500;
const imageChannels = 3;

const getData = async function (path) {
  const data = [];
  const image = await Jimp.read(path);
  await image
      .scan(0, 0, imageWidth, imageHeight, (x, y, idx) => {
        let v = image.bitmap.data[idx + 0];
        data.push(v / 255);
      });
  return data;
};

const createImage = async (data) => {
  const imTen = tf.tensor(data, [imageWidth, imageHeight, 3]);
  const inTen = imTen.expandDims();
  return inTen;
}

const main = async () => {
  const model = await tf.loadLayersModel('file:///retake/savedmodels/model.json');
  model.summary();

  const a = await getData(image)
  const b = await createImage(a)

  const tfImage = b
  console.log(im)

  const prediction = model.predict(tfImage);
  prediction.print();
}
main()
4

1 回答 1

0

我知道的输入图像宽度为 800 像素,高度为 500 像素,并且是彩色的(意思是 3 个通道)

检查您的方法的返回值,getData因为它似乎返回灰度图像 - 这将匹配 400,000 而不是预期的 1,200,000 值

于 2022-01-20T03:35:19.210 回答