2

I am in the process of carrying out a small project to learn the alphabet in sign language (and learn p5.js and ml5.js). I got an already trained model that I want to import into my project. The model was in .h5 and I converted it with this command:

$ tensorflowjs_converter --input_format keras model/model.h5 modelJS/

  When i load the model with load() i get this error: Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'load')

let classifier;

function loadModel(){ classifier.load('modelJS/model.json', predict); }

function predict(){ //classifier.classify({image:video},gotResults); }

function setup() {
  createCanvas(640, 480); video = createCapture(VIDEO); video.hide();
  background(0);
  // Load Model
  loadModel()
};

function draw(){ image(video, 0, 0, 640, 480); }
Dév05
  • 23
  • 3
  • Well, as per this code posted, classifier is undefined. It is declared and not assigned to anything... so it has not a method called load, nor any other thing. – v.k. Oct 19 '22 at 14:18

1 Answers1

1

As you have it, classifier is null ("undefined"). Therefore it doesn't have the property: load().

In the ml5js Documentaion classifier is set to ml5.imageClassifier('MobileNet') To use a image classification model:

function loadModel(){
    classifier = ml5.imageClassifier('modelJS/model.json');
}
Henhen1227
  • 392
  • 1
  • 3
  • 12
  • 1
    Hello, in documentation there's no _ml5.load_ function. I get this error when I add your answer anyway: `Uncaught (in promise) TypeError: ml5.load is not a function` – Dév05 Oct 19 '22 at 06:11
  • Sorry! I think it is supposed to be `classifier = ml5.imageClassifier('modelJS/model.json');` I'll edit my answer. – Henhen1227 Oct 19 '22 at 12:53