ml5js / ml5-library

Friendly machine learning for the web! 🤖
https://ml5js.org
Other
6.48k stars 902 forks source link

Can't addImage to Feature Extractor #1253

Open nabsiddiqui opened 2 years ago

nabsiddiqui commented 2 years ago

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;
}
devihall03 commented 7 months ago

Not really why this issue was closed. there is a comment that says nabsiddiqui mentioned this issue on Jul 15, 2022 https://github.com/programminghistorian/ph-submissions/issues/414

However there is nothing in issue #414 ("Lesson proposal...") related to the .addImage issue with Feature Extractor mentioned here.

I have similar issues and it has been very difficult to find the appropriate information with regards to whether addImage method can accept an array of images or an object with images and labels. Desperately need some clarification on this. I have found many comments and posts on various forums with folks having similar issues with this exact same .addImage method. Particularly in the use case where we are uploading image files instead of the video example. In addition to posting here I will open a new issue. Thanks!