Tensorflow.js model for text error: the Array of Tensors that you are passing to your model is not the size the the model expected. Expected to see 1
Tensorflow.js model for text error: the Array of Tensors that you are passing to your model is not the size the the model expected. Expected to see 1
错误:Uncaught (in promise) Error: Error when checking model : the Array of Tensors that you are passing to your model is not the size the the model expected. Expected to see 1 Tensor(s), but instead got 150 Tensors(s).
async function load_model() {
let m = await tf.loadLayersModel(chrome.runtime.getURL(MODEL_URL));
return m;
}
let model = load_model();
let text = "sample text";
model.then(function (res) {
const vocabulary = "abcdefghijklmnopqrstuvwxyz0123456789".split("");
const trimmed = text.toLowerCase().replace(/(\.|\,|\!)/g, '').split('');
const sequence = trimmed.map(c => {
const wordIndex = vocabulary.indexOf(c)+1.0;
if (wordIndex < 0) {
return 38; //oov_index
}
return wordIndex;
});
sequence.length =150;
let padded_input = Array.from(sequence, v => {
if (v == null)
return 0.0;
return v;
});
console.log(padded_input);
const prediction = res.predict(padded_input);
console.log(prediction);
}, function (err) {
console.log(err);
});
如果我想使用fit
函数,我应该如何处理我得到的张量?
const prediction = res.fit(tf.stack(padded_input), text);
这有一个错误:
Error: You must compile a model before training/testing. Use LayersModel.compile(modelCompileArgs).
通过重塑张量解决。
res.predict(tf.tensor(padded_input).reshape([1,-1]));
错误:Uncaught (in promise) Error: Error when checking model : the Array of Tensors that you are passing to your model is not the size the the model expected. Expected to see 1 Tensor(s), but instead got 150 Tensors(s).
async function load_model() {
let m = await tf.loadLayersModel(chrome.runtime.getURL(MODEL_URL));
return m;
}
let model = load_model();
let text = "sample text";
model.then(function (res) {
const vocabulary = "abcdefghijklmnopqrstuvwxyz0123456789".split("");
const trimmed = text.toLowerCase().replace(/(\.|\,|\!)/g, '').split('');
const sequence = trimmed.map(c => {
const wordIndex = vocabulary.indexOf(c)+1.0;
if (wordIndex < 0) {
return 38; //oov_index
}
return wordIndex;
});
sequence.length =150;
let padded_input = Array.from(sequence, v => {
if (v == null)
return 0.0;
return v;
});
console.log(padded_input);
const prediction = res.predict(padded_input);
console.log(prediction);
}, function (err) {
console.log(err);
});
如果我想使用fit
函数,我应该如何处理我得到的张量?
const prediction = res.fit(tf.stack(padded_input), text);
这有一个错误:
Error: You must compile a model before training/testing. Use LayersModel.compile(modelCompileArgs).
通过重塑张量解决。
res.predict(tf.tensor(padded_input).reshape([1,-1]));