Load the model.pt file and initialize the MMRotate model object. Args: context (context): JSON Object containing information pertaining to the model artifacts parameters.
(self, context)
| 16 | threshold = 0.5 |
| 17 | |
| 18 | def initialize(self, context): |
| 19 | """Load the model.pt file and initialize the MMRotate model object. |
| 20 | |
| 21 | Args: |
| 22 | context (context): JSON Object containing information |
| 23 | pertaining to the model artifacts parameters. |
| 24 | """ |
| 25 | properties = context.system_properties |
| 26 | self.map_location = 'cuda' if torch.cuda.is_available() else 'cpu' |
| 27 | self.device = torch.device(self.map_location + ':' + |
| 28 | str(properties.get('gpu_id')) if torch.cuda. |
| 29 | is_available() else self.map_location) |
| 30 | self.manifest = context.manifest |
| 31 | |
| 32 | model_dir = properties.get('model_dir') |
| 33 | serialized_file = self.manifest['model']['serializedFile'] |
| 34 | checkpoint = os.path.join(model_dir, serialized_file) |
| 35 | self.config_file = os.path.join(model_dir, 'config.py') |
| 36 | |
| 37 | self.model = init_detector(self.config_file, checkpoint, self.device) |
| 38 | self.initialized = True |
| 39 | |
| 40 | def preprocess(self, data): |
| 41 | """Convert the request input to a ndarray. |
nothing calls this directly
no outgoing calls
no test coverage detected