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)
知道为什么会发生此错误以及如何解决它吗?
作为附加信息:
- 我正在使用
@tensorflow/tfjs
版本 0.12.0
- 所有失败的代码(带有模型)都在这里:https://github.com/aralroca/skin-cancer-detection-tfjs/tree/d0d288c84919410dd422a1a19de7b207b6f49000
image
是 int32
类型。您可以将其转换为 float32
.
pretrainedModel.predict(image.cast('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)
知道为什么会发生此错误以及如何解决它吗?
作为附加信息:
- 我正在使用
@tensorflow/tfjs
版本0.12.0
- 所有失败的代码(带有模型)都在这里:https://github.com/aralroca/skin-cancer-detection-tfjs/tree/d0d288c84919410dd422a1a19de7b207b6f49000
image
是 int32
类型。您可以将其转换为 float32
.
pretrainedModel.predict(image.cast('float32'));