Closed matiaslopezd closed 3 weeks ago
Hi @matiaslopezd,
Could you please provide the memory trace to facilitate a thorough review of the issue? To access it, navigate to Chrome Options -> More Tools -> Developer Tools -> Memory Tab, and select the third option Allocation Sampling and record the trace, as shown in the screenshot below.
Thank you!!
@matiaslopezd The error you're encountering with the MediaPipe ImageSegmenter in long-duration sessions could be related to memory management, resource exhaustion, or a potential memory leak in the underlying WebGL context.
Steps to Troubleshoot and Resolve:
Monitor Resource Usage: Use browser developer tools to monitor memory usage over time. Look for signs of memory leaks or excessive memory consumption that could lead to failures after prolonged usage.
Automatic Cleanup: Ensure that you are properly cleaning up resources when they are no longer needed. For example, if you are creating instances of ImageSegmenter, make sure to call the close method when they are no longer needed. Implement a mechanism to periodically clean up and reinitialize the ImageSegmenter.
3.Error Handling: Add error handling to catch and recover from errors. This can include reinitializing the ImageSegmenter instance when an error occurs. Use try-catch blocks around critical sections of code that involve the ImageSegmenter.
sample snippet for Error Handling and Reinitialization::-
let imageSegmenter;
function initializeImageSegmenter() {
if (imageSegmenter) {
imageSegmenter.close();
}
imageSegmenter = new ImageSegmenter({
// Your configuration here
});
imageSegmenter.onResults(onResults);
// Add error handling
imageSegmenter.onError(handleError);
}
function handleError(error) {
console.error("ImageSegmenter error:", error);
// Attempt to reinitialize the ImageSegmenter
initializeImageSegmenter();
}
function onResults(results) {
// Process results
}
// Initialize the ImageSegmenter
initializeImageSegmenter();
// Example: Process an image
function processImage(image) {
try {
imageSegmenter.segment(image);
} catch (error) {
handleError(error);
}
}
// Periodic cleanup and reinitialization (e.g., every hour)
setInterval(() => {
console.log("Reinitializing ImageSegmenter for cleanup");
initializeImageSegmenter();
}, 3600000); // 1 hour in milliseconds
Hope, This helps Thanks
Hi @matiaslopezd,
Could you please review the above https://github.com/google-ai-edge/mediapipe/issues/5539#issuecomment-2249581432 and provide us further information?
Thank you!!
Open
is only called once per graph, when the calculators are initialized. So that means that the error trace initially reported was not encountered by continuous running, per se, but rather was triggered by an initialization or reinitialization.
Since the activation shader is the first one created in the postprocessing (and one of the simplest), one possibility is that somehow you do not have an active WebGL context anymore. Check to make sure that your WebGL context is still active before initializing/reinitializing. In particular, for long-running tabs, the browser can recycle your WebGL context out from under you, which sounds perhaps like what's happening here. So make sure you handle or check for "WebGLContextLost" events.
To that end, the utility call isContextLost() may also be helpful here, and there is also an extension you can use for testing: WebGL_lose_context.
This issue has been marked stale because it has no recent activity since 7 days. It will be closed if no further activity occurs. Thank you.
This issue was closed due to lack of activity after being marked stale for past 7 days.
Have I written custom code (as opposed to using a stock example script provided in MediaPipe)
No
OS Platform and Distribution
Windows 10
Mobile device if the issue happens on mobile device
Thinkpad T14 Gen 1
Browser and version if the issue happens on browser
Google Chrome 126.0.x.x
Programming Language and version
Javascript
MediaPipe version
0.10.12
Bazel version
No response
Solution
ImageSegmenter
Android Studio, NDK, SDK versions (if issue is related to building in Android environment)
No response
Xcode & Tulsi version (if issue is related to building for iOS)
No response
Describe the actual behavior
Works but something for long duration session (>4 hrs) in a single tab throw this kind of error
Describe the expected behaviour
Hopefully have a way to listener errors to instance a new ImageSegmenter
Standalone code/steps you may have used to try to get what you need
Other info / Complete Logs