Skip to content
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

Can we run two models using different predictor and object detector instances ? #77

Open
mnawazshah opened this issue Dec 6, 2024 · 8 comments

Comments

@mnawazshah
Copy link

No description provided.

@mnawazshah
Copy link
Author

Here is my code for review
var objectDetector = await controller.initObjectDetectorWithLocalModel(); await objectDetector.loadModel(useGpu: true); var objectDetectorCoco = await controller.initObjectDetectorWithLocalModelCoco(); await objectDetectorCoco.loadModel(useGpu: true);

and this code is for running detection on models:
var data = await objectDetector.detect(imagePath:resizedImageFile.path); var dataCoco = await objectDetectorCoco.detect(imagePath:resizedImageFile.path);
But this code is always returning same output of just 1 model in both data and dataCoco lists

@pderrenger
Copy link
Member

It looks like both objectDetector and objectDetectorCoco might be referring to the same model instance or configuration during initialization. Ensure that the models are correctly loaded with distinct configurations or distinct pretrained weights when calling loadModel. Verify that the .initObjectDetectorWithLocalModel() and .initObjectDetectorWithLocalModelCoco() methods truly create independent instances with separate model files.

If the issue persists, please provide specific details about your library or API usage for further assistance.

@mnawazshah
Copy link
Author

Yes it was my mistake I was returning same LocalYoloModel instance in both init methods.
But this issue is again happening when I am trying to run as follows:
var objectDetector = await controller .initObjectDetectorWithLocalModel(); await objectDetector.loadModel(useGpu: true); //// coco initialization var objectDetectorCoco = await controller.initObjectDetectorWithLocalModelCoco(); await objectDetectorCoco.loadModel(useGpu: true);

for some strange reason when code is run in this above way then it mixes up one model with other
var data = await objectDetector.detect(imagePath: resizedImageFile.path); var dataCoco =await objectDetectorCoco.detect(imagePath: resizedImageFile.path);

due to this bug dataCoco and data values are same which logically impossible because both models are completely different.

And if after initializing one model and then I perform some other tasks in between and then initialize other model then this issue is not occurring

@pderrenger
Copy link
Member

It seems like the models are conflicting due to shared resources or improper separation during initialization. Ensure the initObjectDetectorWithLocalModel and initObjectDetectorWithLocalModelCoco methods create entirely independent instances, and verify that both models are loaded into separate memory spaces. If the issue persists, try adding a slight delay or explicitly clearing resources between initializing the two models. Additionally, confirm that you're using the latest version of the library, as updates often address such bugs. Let me know if further clarification is needed!

@mnawazshah
Copy link
Author

what do you mean by "explicitly clearing resources between initializing the two models"

@pderrenger
Copy link
Member

@mnawazshah by "explicitly clearing resources," I mean releasing any shared memory or GPU resources occupied by the first model before initializing the second model. This can be done by ensuring that the first model's instance is properly deleted (using del objectDetector in Python) and calling garbage collection (import gc; gc.collect()), especially if both models use the same hardware resources like GPU. This ensures no conflicts occur during initialization. Let me know if you need further clarification!

@mnawazshah
Copy link
Author

but I asked for flutter not python

@pderrenger
Copy link
Member

Thank you for clarifying. While the Ultralytics repositories and documentation focus primarily on Python, for Flutter-specific issues, ensure that the model instances are completely isolated and independently initialized, avoiding shared resources. If you're still encountering issues, I recommend reaching out to the Flutter community or forums for guidance on integrating YOLO models within Flutter. Let me know if you have further questions related to YOLO itself!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants