ml5js / ml5-website-archive

ml5 website!
https://archive-docs.ml5js.org
MIT License
46 stars 47 forks source link

inputLabels must be an array (sketch: line 46) #163

Open GSNikhil opened 4 years ago

GSNikhil commented 4 years ago
let nn;
let data, labels;
let img;

const IMAGE_WIDTH = 28;
const IMAGE_HEIGHT = 28;
const IMAGE_CHANNELS = 1;

const options = {
  task: 'imageClassification',
  inputs: [IMAGE_WIDTH, IMAGE_HEIGHT, IMAGE_CHANNELS],
  outputs: ['label'],
  debug: true
}

const trainingOptions = {
  epochs: 32,
  batchSize: 10
}

function setup() {
  data = loadTable('data.csv', 'csv', 'header', dataLoaded);
  nn = ml5.neuralNetwork(options);
}

function dataLoaded() {
  console.log('Data Loaded');
  labels = loadTable('labels.csv', 'csv', 'header', labelsLoaded);
}

function labelsLoaded() {
  console.log('Labels Loaded');
  addDataNN();
}

function addDataNN() {
  let temp = [];

  for (let i = 0; i < data.getRowCount(); i++) 
  {
    temp = data.getRow(i).arr.map( function(v) {
      return parseInt(v, 10);
    });

    nn.addData(temp,
      [parseInt(labels.getRow(i).arr[0], 10)]);
  }

  // nn.normalizeData();
  nn.train(trainingOptions, whileTraining, finishedTraining);
}

function whileTraining(epoch, loss) {
  console.log(`epoch: ${epoch}, loss:${loss}`);
}

function finishedTraining() {
  console.log('Done!');
}

The nn.addData() is not accepting the temp array. Can anyone help me here? It is throwing me this error - inputLabels must be an array (sketch: line 46)