| 15 | |
| 16 | |
| 17 | class Predictor(BasePredictor): |
| 18 | def setup(self): |
| 19 | model_ckt = "epoch_60.pth" |
| 20 | cfg = Config.fromfile("configs/psgtr/psgtr_r50_psg_inference.py") |
| 21 | self.model = init_detector(cfg, model_ckt, device="cpu") |
| 22 | |
| 23 | def predict( |
| 24 | self, |
| 25 | image: Path = Input( |
| 26 | description="Input image.", |
| 27 | ), |
| 28 | num_rel: int = Input( |
| 29 | description="Number of Relations. Each relation will generate a scene graph", |
| 30 | default=5, |
| 31 | ge=1, |
| 32 | le=20, |
| 33 | ), |
| 34 | ) -> List[ModelOutput]: |
| 35 | input_image = mmcv.imread(str(image)) |
| 36 | result = inference_detector(self.model, input_image) |
| 37 | out_path = Path(tempfile.mkdtemp()) / "output.png" |
| 38 | out_dir = "temp" |
| 39 | show_result( |
| 40 | str(image), |
| 41 | result, |
| 42 | is_one_stage=True, |
| 43 | num_rel=num_rel, |
| 44 | out_dir=out_dir, |
| 45 | out_file=str(out_path), |
| 46 | ) |
| 47 | output = [] |
| 48 | output.append(ModelOutput(image=out_path)) |
| 49 | for i, img_path in enumerate(os.listdir(out_dir)): |
| 50 | img = mmcv.imread(os.path.join(out_dir, img_path)) |
| 51 | out_path = Path(tempfile.mkdtemp()) / f"output_{i}.png" |
| 52 | mmcv.imwrite(img, str(out_path)) |
| 53 | output.append(ModelOutput(image=out_path)) |
| 54 | shutil.rmtree(out_dir) |
| 55 | |
| 56 | return output |
nothing calls this directly
no outgoing calls
no test coverage detected