-
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
Add offline module #200
base: main
Are you sure you want to change the base?
Add offline module #200
Conversation
This is exciting to see thank you @ziyuan-linn for working on this! One consideration is that running a stand-along node.js script for downloading the models may involves concepts/steps unfamiliar to beginners especially those used to working only in the p5.js web editor. I think it's ok for this to be the primary way to get the models since this is an "edge" use case, however, we should probably include some detailed documentation for total beginners. I could also record a video tutorial on this topic. Alternatively we could consider providing links to some model downloads directly but this might be hard to maintain. |
@shiffman Thank you for the review! The node.js script for downloading models is meant to be only called by the ml5.js maintainers. I could also set it up as a postinstall script that automatically runs after As far as the users are concerned, they only need to change |
The PR implements an offline version of the ml5.js library.
Webpack will now build
ml5-offline.js
andml5-offline.min.js
in addition toml5.js
andml5.min.js
. The fileml5-offline.js
andml5-offline.min.js
is self-contained and will not make additional network requests. Once a user downloadsml5-offline.min.js
, the ml5 library can run entirely without internet.The entry point for the offline model is
src/offline/index.js
. It imports the ml5 object, injects aloadOfflineModel
function into each ml5 model's prototype, and exports the ml5 object with the modified models. The approach keeps the offline implementation mostly separate from the main source code.Changes:
model.json
is written to a JS file.Uint8Array
and then written to JS files.loadOfflineModel
function.File
objects and creates object URLs for them.landmarkModelURL
) of the ml5 model.ml5-offline.js
build, add theloadOfflineModel
functions into object prototypes of each ml5 model.loadOfflineModel
function from each ml5 model during initialization if the function is defined.To test this implementation, find an example sketch and change
ml5.js
toml5-offline.js
inindex.html
.Note: This is WIP,
ml5-offline.js
only works forHandPose
withmodelType: "lite"
.