Skip to content

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

@GSNikhil

Description

@GSNikhil
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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions