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

Predict wrong class #1

Closed
nicejava opened this issue Nov 30, 2023 · 5 comments
Closed

Predict wrong class #1

nicejava opened this issue Nov 30, 2023 · 5 comments

Comments

@nicejava
Copy link

nicejava commented Nov 30, 2023

Your code very good but predict class wrong
It always result predicts the first class.

Example we class CLASS_NAMES = ['BG', 'A', 'B', 'C', 'D', 'E', 'F']

your code result predict is class A always Whether using images of other classes

@z-mahmud22
Copy link
Owner

Hi @nicejava, could you please elaborate on what you mean by it predicts wrong class by sharing the results you are getting?

@nicejava
Copy link
Author

nicejava commented Nov 30, 2023

Thank for reply

ok i try train 5 class CLASS_NAMES = ['A', 'B', 'C', 'D', 'E']

# Number of classes (including background)
NUM_CLASSES = 1 + 5  # Background + object

And I have image for testing 5 class too like this

01.jpg = class A
02.jpg = class B
03.jpg = class C
04.jpg = class D
05.jpg = class E

So after trained i try testing each image but result display first always is 'A'
No matter where I use it, the results are the same, which is A

such as i try testing 03.jpg which should have received the answer C, but instead received the answer A

r = model.detect([image], verbose=0)
r = r[0]
result r['class_ids'] is 1 every time testing ( [1 1] : [0.97279286 0.9367134 ] )

@z-mahmud22
Copy link
Owner

You would also need to register these class names and assign class_id in your Dataset class when training using the add_class function here. Without this, the model will not learn the specific classes during training and would produce random results during inference.

Please follow this tutorial as it gives you a proper walkthrough on how to train mask-rcnn using your own dataset.

@nicejava
Copy link
Author

nicejava commented Nov 30, 2023

I try added class like this, draw mask correct predict shape very good. But label show first always it's incorrect result label

image

I used mrcnn-prediction.py code for predict

model.detect return 1 always

.. thanks

@z-mahmud22
Copy link
Owner

z-mahmud22 commented Dec 1, 2023

It's NOT incorrect class labels that your model is returning. In fact, your model is always returning 1 as the class label. I think you are directly copying the BalloonDataset class which is particularly designed for 1 class. Notice that the load_mask() function is always returning an array of ones (as class IDs) along with the masks.

However, in your case, there are 5 different classes. You'd also need to return particular class indices when returning the masks. You can follow the solution suggested in this issue to fix your problem and retrain the network again.

Particularly, you would need to pass the list of your class_ids when loading image with add_image() here and update the return from load_mask() with this return mask, info['class_ids'].

Additionally, you can follow the notebook that illustrates how to train Mask R-CNN on the Shapes dataset which happens to be a multiclass dataset similar to yours. I hope this answers your question.

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