Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
GSNikhil opened this issue Sep 16, 2020 · 0 comments
Open

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

GSNikhil opened this issue Sep 16, 2020 · 0 comments

Comments

@GSNikhil
Copy link

GSNikhil commented Sep 16, 2020

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant