Tensorflow.js: 提要的数据类型 (int32) 与键 'input_1' (float32) 的数据类型不兼容

Tensorflow.js: dtype of the feed (int32) is incompatible with that of the key 'input_1' (float32)

我进行了从 Mobilenet 到我的模型的迁移学习,并尝试进行预测:

const img = document.querySelector("img");
const image = tf.reshape(tf.fromPixels(img), [1, 224, 224, 3]);
const pretrainedModelPrediction = pretrainedModel.predict(image);
const modelPrediction = model.predict(pretrainedModelPrediction);
const prediction = modelPrediction.as1D().argMax().dataSync()[0];
console.log({ prediction });

这行代码失败了:

const pretrainedModelPrediction = pretrainedModel.predict(image);

出现此错误:

tfjs.js:67 Uncaught (in promise) Error: The dtype of the feed (int32) is incompatible with that of the key 'input_1' (float32).
    at new t (tfjs.js:67)
    at assertFeedCompatibility (tfjs.js:67)
    at e.add (tfjs.js:67)
    at new e (tfjs.js:67)
    at tfjs.js:67
    at tfjs.js:49
    at e.scopedRun (tfjs.js:49)
    at e.tidy (tfjs.js:49)
    at e.tidy (tfjs.js:49)
    at s (tfjs.js:67)

知道为什么会发生此错误以及如何解决它吗?

作为附加信息:

imageint32 类型。您可以将其转换为 float32.

 pretrainedModel.predict(image.cast('float32'));