-
Notifications
You must be signed in to change notification settings - Fork 24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Supporting p5.js preload #29
Comments
Hi @limzykenneth! I am currently working on a new API for some of the ml5 models and would like to get some insight from you about the p5 preload function. We are trying to make the model initialization functions compatible with p5's let handpose, img;
function preload() {
handpose = ml5.handpose(); //ml5 handpose model initialization function
img = loadImage("file.jpg");
}
function setup() {
handpose.detect(img, gotHands);
}
gotHands() {
...
} I am not very familiar with how p5's Would calling |
This part of the API is not really very well documented so I'm mostly going by looking at the source and what I've tested. For the most part it seems It should be fine to use |
Thank you so much for the information! A wrapper that contains all the p5-related code definitely sounds like a good idea. Also looking forward to the future implementations of p5.js! |
Thank you so much @limzykenneth for the advice and support! |
@limzykenneth I've tried working on this part of the ml5 code before and I found that it's actually impossible to implement properly without some changes on the p5 side. The p5 code only works properly with methods that are bound to the p5 prototype. See processing/p5.js#5677 and processing/p5.js#815. The result is a long-standing bug which prevents using ml5 functions with Promise.then() syntax when using p5. We are calling |
Yes, I have recently gone through the documentation to try things out and as you identified, I would like |
Part of the reason that the current code is complicated and buggy is that we are trying to support two different usage patterns at once.
In the p5 use-case that you are describing, calling We get into trouble when we also want to support this sort of setup, for use in a vanilla JS environment. (This example is terrible because we load the model in
Or this
In both of these examples, we are expecting that calling The current behavior, shown below, is that we return the instance directly when the arguments of
It seems like the next-gen version of the library has decided to drop this switching behavior, which means that you can no longer do
Actually it is used! We are passing the models that we want to preload in the
Due to the long-standing problems on the p5 side, I think that directly calling Is there any desire to keep the current behavior of supporting both |
Just to chime in for p5.js side, I have reviewed the library authoring side of things relatively recently and calling Moving forward, as part of investigation into potentiall p5.js 2.0, it is proposed that loading will use async/await in an async The timeline towards p5.js 2.0 is not fixed though and we are looking a relatively slow progress because of team capacity. That being said, feel free to create addional proposals if anyone here wants to see some potentially larger or breaking changes that can be introduced in p5.js 2.0, both in terms of library author and user perspectives. |
@lindapaiste Perhaps a new preload helper could use
Perhaps #69 is also worth considering at this point: @ziyuan-linn found that we run into an issue when trying to load two mediapipe models simultaneously. Some synchronization mechanisms might be needed for the best composability. |
Chiming in here to speak to this question, feedback and thoughts welcome!
The new version of ml5.js is prioritizing p5.js users and scaling down to have a simpler API with fewer models, focused on beginners to creative coding and machine learning. So our examples and documentation will follow p5.js development and focus on callbacks along with preload support. It would be "nice to have" if behind the scenes promises were also supported (I'd use them in some contexts!), but it would also be ok to wait until promises are supported more natively in p5.js 2.0 if that is not an easy thing to support. I expect (and hope!) there will be continued use of ml5.js outside of p5.js, but in our research (shoutout to @MOQN and @QuinnHe!) we discovered that the native JS examples and documentation caused a lot of confusion for beginners to library. And given how much extra work it is to maintain and the different flavors and styles of use, I think we can focus on p5.js callbacks + preload! |
@limzykenneth I've been looking into this and I'm not sure if it's even possible for use to get the right I've been playing around with this a lot, and I am able to get preloading to work if I put the method on
Putting a wrapped version of the library method on the
I cannot figure out a way to support calling I'm feeling like I've exhausted this approach and the next thing for me to play with are the edit: OH MY GOD I AM FINALLY GETTING SOMEWHERE!!!! You have no idea how many things I tried. An explicit
|
@lindapaiste The investigations you've done are all super helpful. I will look into this from what you have found and seeing as p5.js 2.0 is likely awhile away, I will incorporate fixes around this system if necessary to get preload working with libraries that does not attach to the p5 prototype directly. |
@shiffman Hi everyone, I am starting this discussion because I just realized that initialization functions like
ml5.handpose()
need to be hooked into p5'spreload()
function.@gohai's mentioned here that the old
p5PreloadHelper
does not seem to be working and instead called_incrementPreload()
and_decrementPreload()
. I am not really familiar with p5's implementation, so I am not sure howpreload()
works under the hood. Would it make sense for us to update thep5PreloadHelper
so we could easily hook into thepreload
function?The text was updated successfully, but these errors were encountered: