简体   繁体   English

javascript - Uncaught (in promise) TypeError: e.iterator is not a function。 如何修复此类错误?

[英]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 .错误来自convertedTestingDataconvertedTrainingData 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。

  • Convert js array to tf.tensor将 js 数组转换为 tf.tensor

the method fit will be used instead of fitDataset将使用fit方法代替fitDataset

model.fit(tf.tensor(features), tf.tensor(labels))
  • Use tf.data.Dataset使用 tf.data.Dataset

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.

相关问题 我收到一个错误:未捕获(承诺)类型错误:cartItems.map 不是 function。 上述错误发生在<cartscreen>零件:</cartscreen> - i got an error: Uncaught (in promise) TypeError: cartItems.map is not a function. The above error occurred in the <CartScreen> component: Javascript Uncaught TypeError:不是函数。 动态加载的内容 - Javascript Uncaught TypeError: is not a function. Dynamically loaded content 未捕获的TypeError:X不是函数。 使用javascript闭包时 - Uncaught TypeError: X is not a function. While using javascript closure JavaScript forEach function:未捕获(承诺)类型错误 - JavaScript forEach function: Uncaught (in promise) TypeError 如何在JavaScript中修复Uncaught TypeError? - How to fix Uncaught TypeError in JavaScript? 未捕获的TypeError:data.push不是函数。 我怎样才能解决这个推送错误? - Uncaught TypeError: data.push is not a function. How can I get around this push error? “未捕获(承诺)TypeError:_this.setState 不是函数”错误 - "Uncaught (in promise) TypeError: _this.setState is not a function" error 错误:未捕获(承诺):TypeError:r不是函数 - Error: Uncaught (in promise): TypeError: r is not a function Uncaught Promise错误:TypeError:member不是函数 - Uncaught Promise Error: TypeError: member is not a function 如何在JavaScript中修复“未捕获的TypeError:action.addEventListener不是函数” - How to fix “Uncaught TypeError: action.addEventListener is not a function” in JavaScript
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM