[英]javascript - Uncaught (in promise) TypeError: e.iterator is not a function. How to fix such error?
I'm new to javascript and I'm implementing a binary classification.我是 javascript 新手,正在实施二进制分类。 After converting the csv files of training and test data to arrays, I found this error: Uncaught (in promise) TypeError: e.iterator is not a function
在将训练和测试数据的 csv 文件转换为数组后,我发现了这个错误: Uncaught (in promise) TypeError: e.iterator is not a function
Here is the model fitting:这是模型拟合:
await model.fitDataset(convertedTrainingData,
{epochs:100,
validationData: convertedTestingData,
callbacks:{
onEpochEnd: async(epoch, logs) =>{
console.log("Epoch: " + epoch + " Loss: " +
logs.loss + " Accuracy: " + logs.acc);
}
}});
The error comes from convertedTestingData
and convertedTrainingData
.错误来自convertedTestingData
和convertedTrainingData
。 fitDataset
takes as parameter a tf.data.Dataset
. fitDataset
取作为参数tf.data.Dataset
。 An instance of tf.data.Dataset
has an asynchronous iterator. tf.data.Dataset
一个实例有一个异步迭代器。
if convertedTestingData
(respectively convertedTrainingData
) is a js array, it needs to be converted either to a tf.tensor or to a tf.data.Dataset.如果convertedTestingData
(分别是convertedTrainingData
)是一个js数组,则需要将其转换为tf.tensor或tf.data.Dataset。
the method fit
will be used instead of fitDataset
将使用fit
方法代替fitDataset
model.fit(tf.tensor(features), tf.tensor(labels))
A tf.data.Dataset is created by using a generator. tf.data.Dataset 是使用生成器创建的。
function createDataGenerator(data) {
return function* dataGenerator() {
let index = 0;
while (index < data.length) {
const feature = getFeatureTensorAtIndex(i) ; // get the feature tensor at the index
const label = getLabelTensorAtIndex(i); // get the label tensor at the index
index++;
yield {xs: feature, ys: label};
}
}
}
const training = tf.data.generator(createDataGenerator(convertedTrainingData));
const testing = tf.data.generator(createDataGenerator(convertedTestingData));
Then the model can be trained with the dataset ds
然后可以使用数据集ds
训练模型
await model.fitDataset(training,
{
epochs: 100,
validationData: testing,
callbacks: {
onEpochEnd: async (epoch, logs) => {
console.log("Epoch: " + epoch + " Loss: " +
logs.loss + " Accuracy: " + logs.acc);
}
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.