ml5js / ml5-next-gen

Repo for next generation of ml5.js: friendly machine learning for the web! 🤖
https://ml5js.org/
Other
57 stars 19 forks source link

`bodyPose` and `bodySegmentation` failing to preload in p5 instance mode #175

Open jackbdu opened 1 month ago

jackbdu commented 1 month ago

Creating a new issue to track the progress of this:

@lindapaiste Thank you for adding support for instance mode. I was able to preload most models (ml5.faceMesh, ml5.handPose, ml5.imageClassifier, ml5.neuralNetwork, and ml5.sentiment) but I'm getting an error for ml5.bodyPose. See this minimal sketch demonstrating the issue. I also included my temporary fix in the comments, which creates blank window._incrementPreload() and window._decrementPreload() to avoid this error.

I'm also getting an error for preloading ml5.bodySegmentation in instance mode, and that could be fixed by declaring a global variable let video;.

Originally posted by @jackbdu in https://github.com/ml5js/ml5-next-gen/issues/81#issuecomment-2067780151

lindapaiste commented 1 month ago

We need to remove this call: https://github.com/ml5js/ml5-next-gen/blob/542e5a5171a428e807451ca901cc130b54d6f8e9/src/BodyPose/index.js#L56 (and any others like it)

There will be no window._incrementPreload when using instance mode because _incrementPreload will be a property of the p5 instance, rather than a property of the window.

lindapaiste commented 1 month ago

I'm also getting an error for preloading ml5.bodySegmentation in instance mode, and that could be fixed by declaring a global variable let video;.

Likely we have some code that is using an improperly scoped video variable. We definitely should not have a global/window scoped video variable anywhere. I suspect it's an issue where we are using this.video in a context where this is actually the window. That sort of thing can be fixed by binding the function to the correct this context. I would need to dig into the code to find where the bad variable is.

lindapaiste commented 1 month ago

We're using a variable video that doesn't exist on like 34 of BodySegmentation.

https://github.com/ml5js/ml5-next-gen/blob/84419b3d2808aac1a6214c24f1f6b00d918127f2/src/BodySegmentation/index.js#L34