-
Notifications
You must be signed in to change notification settings - Fork 545
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
[Non-breaking] Bundling models into the package itself. #811
Conversation
This bundles all 3 models into the package itself. This also adds support for both `ESM` and `CJS` allowing bundlers like `Webpack` to `tree-shake` the unused models. Added the ability to the `load()` to specify which model to use between the 3 available options, `"MobileNetV2"` | `"MobileNetMid"` | `"InceptionV3"`.
Use browserify to convert model files to .js files. + refactor: reorder package.json scripts. + refactor: rename tsconfig files. + refactor: rename `MobileNetMid` to `MobileNetV2Mid`.
+ refactor: rename example folder to examples. + Update manual_testing example with bundled models.
+ test: add pretest and posttest scripts. + refactor: reorder package.json.
+ Update usage with bundled models. + Refactors.
Netlify build seems to be failing due to the folder rename from |
BTW, I love where this is going! We're reviewing this soon. |
+ Remove node-fetch polyfill from devDependencies as it is no longer being used. + Add to contributions.
I've updated this PR to align with the latest changes in the main branch and refactored a few things as well. I have also added a few changes to the tests to reflect the changes. Everything should be stable. Please take your time and review the changes. The only check that is failing is the renaming of the Cheers. |
@haZya thanks for making the updates. regarding the failing deploy check to Netlify, we'll be making the fix this morning along with merging my PR #820 which should also reduce the number of files you have. I haven't had the opportunity to get to fully review your PR but I have two comments:
also, not sure if you're on the IR Slack Community group, but please, feel free to join and DM me there and we can chat around this further if you'd like! |
@haZya - thanks for chilling with us while we do some much-needed maintenance to this repo! I think we're nearing the end of our merge conflicts, and then we'll dive in and evaluate your PR extensively! |
Hey @GantMan Thanks for the heads up! |
Thanks for the update @mazenchami.
Correct me if I'm wrong, but I believe this is the same behaviour as the latest version of NSFWJS. Still, I agree we could do better here for the I believe this is the best way to load the model on the front end without blocking the main thread. Typically it would be ideal to load the model on a server and access it via API instead of loading it on each client browser. But if the user wants to load the model on the client side, I think using a web worker would be the best approach. Furthermore, I have expanded the Caching section in the docs to explain how caching the model on the browser using I'd be willing to do a PR for this as well on this weekend or the next if you are interested. Please let me know. PS: I've also joined the IR Slack Community. Feel free to do any follow-ups on there if needed. Thanks. |
+ Resolved merge conflicts in package.json.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work on this PR! This will get merged and deployed soon! 🎉 🚀
Hey @haZya - thank you so much for your contribution! We owe you a drink if we can ever meet you in person! |
Hey @GantMan @mazenchami Thank you very much for your time and support in reviewing this PR. I'll probably follow up with another PR later for the Cheers. |
@haZya absolutely, any time! and thank YOU for the contribution! feel free to tag me as a reviewer when you get it up and i'll be happy to take a look |
Pull Request
Related issue
Fixes #779, #807, #808
What does this PR do?
This bundles all 3 models into the package itself. This also adds support for both
ESM
andCJS
, allowing bundlers likeWebpack
totree-shake
unused modules.This gets rid of the reliance on the currently hosted model on
cloudfront.net
ands3 bucket
.load()
to specify which model to use between the 3 available options,"MobileNetV2"
|"MobileNetV2Mid"
|"InceptionV3"
. Defaults to:"MobileNetV2"
.editorconfig
to improve consistency.Caveats
This converts the model weights from
binary
tobase64
since.bin
files cannot be directly imported into JS. As a result, the bundle size increases for each model by approximately 1.33 times (33%). i.e. The"MobileNetV2"
model bundled into the package is 3.5MB instead of 2.6MB for hosted binary files. This means it will have slightly higher loading times than using the binary files directly. If this is a concern, users can host the models on their own servers and use the URL as usual in theload()
, as described in the documentation's Host your own model section. This will only make a difference if the model is loaded every time (without caching) on the client-side browser since on the server-side, you'd only be loading the model once at the start of the server.Network analysis
Bundle analysis