ml5-library icon indicating copy to clipboard operation
ml5-library copied to clipboard

Can't addImage to Feature Extractor

Open nabsiddiqui opened this issue 3 years ago • 1 comments

Hello,

I am working on a simple example to classify Covid lungs based on a Kaggle dataset. I am only using the first 120 images for testing. I have looked through all the bugs, but I still can't seem to figure out how to add a p5 Image to a feature extractor. Currently, I receive the following error:

Screen Shot 2021-12-02 at 2 24 45 PM

The following is my code:

let train_covid_images=new Array();
let train_healthy_images=new Array();
let featureExtractor;
let classifier;

// When the model is loaded
function modelLoaded() {
  console.log('Model Loaded!');
}

function preload(){
  // Initialize a MobileNet as  
  featureExtractor = ml5.featureExtractor('mobileNet',modelLoaded);
  train_covid_images=getImages('images/covid', 'covid', 120);
  train_healthy_images=getImages('images/healthy', 'healthy', 120);
}

function setup(){
  // Output the current version of ml5 to the console
  console.log('ml5 version:', ml5.version);
  featureExtractor.addImage(train_covid_images[0], "covid");
  featureExtractor.addImage(train_healthy_images[0], "healthy");
}

function getImages(folder, filename, amount){
  let images=new Array();
  for (let i=0; i < amount; i++){
    images[i]=loadImage(`${folder}/${filename}${i}.png`);
    console.log(`Loaded ${folder}/${filename}${i}.png`);
  }
  return images;
}

nabsiddiqui avatar Dec 02 '21 19:12 nabsiddiqui