Loading model using detectron 2

I am trying to load a trained model using a code that my boss gave me to use. However, there is a slight issue. It keeps saying ‘Please load the model first.’ which is supposed to be printed as an except while trying to load the model. I set the directory of the pth file properly, but it still doesn’t work. Here’s the code for the loading part:

                def load_model(self):
                    try:
                        model_path= r"C:\GUI\output\model_final.pth" #model_final.pth
                        self.cfg.merge_from_file(model_zoo.get_config_file("COCO-InstanceSegmentation/mask_rcnn_R_50_FPN_3x.yaml"))
                        self.cfg.MODEL.ROI_HEADS.NUM_CLASSES = 3
                        self.cfg.MODEL.ROI_HEADS.SCORE_THRESH_TEST = 0.8
                        self.cfg.MODEL.WEIGHTS = os.path.join(self.cfg.OUTPUT_DIR, 'model_final.pth')
                        return DefaultPredictor(self.cfg)
                    except:
                        print('There is no model exist, please train the model first.')
                        return -1
                
                def predict(self, frame):
                    try:
                        outputs = self.predictor(frame)
                        # print position info
                        result = self.fish_position(outputs)
                        print(result)
                        # draw the 
                        v = self.draw_predict_position(frame,outputs)
                        return v.get_image()[:, :, ::-1]
                    # cv2.imshow('frame', v.get_image()[:, :, ::-1]) 
                    except:
                        print('Please load the model first.')

Here’s the main code:

                           model = FishRecogModel("use")
                                #model.register_coco()

                                cap = cv2.VideoCapture(3)
                                while(True):
                                    ret, frame = cap.read()
                                    model.predict(frame)
                                    if cv2.waitKey(1) & 0xFF == ord('q'):
                                        break
                                cap.release()
                                cv2.destroyAllWindows()

Can somebody help me out in figuring out why the ‘Please load the model first.’ keeps being printed out?

Remove the try/except part and allow Python to raise the actual error. Catching all exceptions without re-raising the error is usually not a good idea, since now you don’t know what is actually failing.
Based on the code snippet it also seems the exception is raised during the predict call and might be failing in any of these lines:

                    try:
                        outputs = self.predictor(frame)
                        # print position info
                        result = self.fish_position(outputs)
                        print(result)
                        # draw the 
                        v = self.draw_predict_position(frame,outputs)
                        return v.get_image()[:, :, ::-1]

I tried to find the error. It says failed to load plugin gstreamer-1.0\gstogg.dll’ module

Any idea why? The module is there in the correct folder though.

It seems your gstreamer installation might be broken. I don’t know how exactly you are using it, but it seems your application depends on this library so you might need to fix it.