Is there a way to make predictions and visualize the result image by loading a previously trained detectron2 model (without providing any metadata)? #3247
Unanswered
sushmasuresh28
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I am training a detectron2 model on a custom dataset and saving the "model_final.pth" locally. My question has 2 parts-
During testing, I would like to make predictions on any image provided by loading the saved "model_final.pth". Can anyone help me with it? Currently, when I try to load the file and make the predictions, I get no values and the output image with no predictions.
Is there a way to print custom class names while making the prediction on a single image (without providing any metadata)?
CASE 1: Currently, by using the below code-

from detectron2.utils.visualizer import ColorMode v = Visualizer(im[:, :, ::-1], MetadataCatalog.get(cfg.DATASETS.TRAIN[0]), scale=1.2) out = v.draw_instance_predictions(outputs["instances"].to("cpu")) cv2_imshow(out.get_image()[:, :, ::-1])
I get -
Although the classes are that of plants, I get them as 'person'
CASE 2: By removing the metadata parameter, I obtain the classes as 'tensor(0)'
from detectron2.utils.visualizer import ColorMode v = Visualizer(im[:, :, ::-1], scale=1.2) out = v.draw_instance_predictions(outputs["instances"].to("cpu")) cv2_imshow(out.get_image()[:, :, ::-1])
Result-

What I would like -

Or the percentages with no class names.
Since I am using a pre-trained model (which I am saving after detectron training in another file), I do not have the metadata registered while making the predictions
Beta Was this translation helpful? Give feedback.
All reactions