-
Notifications
You must be signed in to change notification settings - Fork 5.2k
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
@mediapipe/selfie_segmentation
npm package can be bundled by Rollup, but raises an error in runtime.
#2883
Comments
Just adding that I am experiencing the same issue with the @mediapipe/hands package. Using the package installed via npm works fine but if I compile it with Rollup then I am given You can see the same issue with the CDN version of the package using this standalone script:
|
@englishtom Does @sile's workaround of adding I'm not familiar with Rollup myself, so I don't really have any insights to offer here. |
@tyrmullen It does not, however, using the Hands library directly without TensorFlow works well for me so that is the approach I have moved forwards with. |
This might help to understand the issue:
|
By @bluwy :
Does someone have a workaround for this issue? |
Just FYI, I implemented a custom rollup plugin that appends the line |
Awesome, thanks so much. This works for me! I use this plugin now in my |
Thanks for sharing. In my case the error was related to MediaPipe Facemesh, so I adjusted the plugin as follows: function mediapipe_workaround() {
return {
name: "mediapipe_workaround",
load(id) {
if (path.basename(id) === "face_mesh.js") {
let code = fs.readFileSync(id, "utf-8")
code += "exports.FaceMesh = FaceMesh;"
return { code }
} else {
return null
}
},
}
} |
Hello @sile, You can continue to use those legacy solutions in your applications if you choose. Though, we would request you to check new MediaPipe solutions which can help you more easily build and customize ML solutions for your applications. These new solutions will provide a superset of capabilities available in the legacy solutions. |
@kuaashish Thank you for letting me know about the new solutions. I tried using the Image Segmenter (with label=person) for selfie segmentation purposes. It was able to build without the error shared by this issue. |
@sile, |
@kuaashish I see. It's okay to close this issue 👍 |
Maybe you can use vite-plugin-mediapipe:https://github.com/Spencer17x/arca/tree/main/packages/vite-plugin/vite-plugin-mediapipe |
Hey @mattrossman , I'm encountering the exact same issue, trying to bundle mediapipe/facemesh into a vite built application ( also The link you quoted doesn't go anywhere anymore, do you happen to still have a full vite plugin that the method you wrote goes into? |
@Bersaelor That For posterity, here's a permalink to the original by @sile that I based it on (it looks like they just renamed the file extension which broke that other link). And here's where it's used in the config. |
First of all, thank you for publishing this great library.
I'm new to this library and TypeScript, so not sure that this is actually a bug.
Please let me know if you have any misunderstandings 🙏
System information (Please provide as much relevant information as possible)
Describe the current behavior:
Failed to instantiate the
SelfieSegmentation
class from a JavaScript file bundled by Rollup.The screenshot below shows the error message (please refer to the following
Standalone code to reproduce the issue
section about what is the context ofindex.html
):Describe the expected behavior:
Be able to instantiate
SelfieSegmentatoin
class without errors (theHello World!
message below is emitted after the instantiation).Standalone code to reproduce the issue:
I created a small example package, that provides a class only instantiating
SelfieSegmentation
, to reproduce this issue.index.html
:index.ts
:package.json
:rollup.config.js
:Other info / Complete Logs :
I don't exactly know why it works but if the line
exports.SelfieSegmentation = SelfieSegmentation;
is appended toselfie_segmentation.js
, the problem is disappeared:The text was updated successfully, but these errors were encountered: